summaryrefslogtreecommitdiff
path: root/test/web
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-12 16:48:56 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:16 -0300
commitf9ca3fb5ba767300bec3f1fbb13fc5e6552a90e3 (patch)
tree4b74e75ee3d1c39074e68a34b1f9ae984414addd /test/web
parent973100a138daea5087f43db656b8688b24d9da88 (diff)
downloadcloud9-f9ca3fb5ba767300bec3f1fbb13fc5e6552a90e3.tar.gz
cloud9-f9ca3fb5ba767300bec3f1fbb13fc5e6552a90e3.zip
9web: restore host namespace and mounted 9P browsing
Add explicit filesystem:"/" export with kernel-enforced user access, symlink/mount traversal and normal file operations. Compose the virtual catalogue at /_9web and wrap the workstation user service with 9ns --mntgen so /mnt/9p is live in its own namespace. Fix non-seekable FUSE EOF translation, asynchronous read lifecycle and flush/clunk cancellation, oversized HTTP directory reads and fixed listing buffers, and borrowed WASM reply frames causing InputFull on large browser reads. Remove the sidebar and expose direct follow links without waiting for stream EOF. Document deployed namespace/security implications and the Plan 9 source critique: posted 9P endpoints, manual site configuration and passive HTTP discovery are distinct; pure site/control publication and unified static serving remain future work. Verified ReleaseSafe build, catalogue and host-FS integration, HTTP-FS and 32 existing E2E scenarios, and Chromium fixture/live navigation through /mnt/9p/agents, large history, zmx files and /usr/bin. Installed service enabled and active on [::]:8090, with generated sites still served.
Diffstat (limited to 'test/web')
-rw-r--r--test/web/catalog_ui.mjs52
-rw-r--r--test/web/host_fs.py161
2 files changed, 207 insertions, 6 deletions
diff --git a/test/web/catalog_ui.mjs b/test/web/catalog_ui.mjs
index 6120a51..eed6c0a 100644
--- a/test/web/catalog_ui.mjs
+++ b/test/web/catalog_ui.mjs
@@ -11,8 +11,8 @@ const binary = path.resolve(process.argv[2] || 'zig-out/bin/9web');
const work = await fs.mkdtemp(path.join(os.tmpdir(), '9web-ui-'));
const children = [], exceptions = [], pending = new Map();
let socket, serial = 0;
-function start(command, args) {
- const p = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'] });
+function start(command, args, env = process.env) {
+ const p = spawn(command, args, { env, stdio: ['ignore', 'pipe', 'pipe'] });
p.output = ''; p.stdout.on('data', b => { p.output += b; }); p.stderr.on('data', b => { p.output += b; });
p.on('error', e => { p.output += e.message; }); children.push(p); return p;
}
@@ -47,9 +47,15 @@ async function readySites() { await wait(() => evaluate(`document.querySelectorA
try {
const root = path.join(work, 'public'); await fs.mkdir(root);
await fs.writeFile(path.join(root, 'index.html'), '<h1>Fixture</h1>');
+ await fs.writeFile(path.join(work, 'large.txt'), 'x'.repeat(180000));
const dashboard = await port(), sitePort = await port(), debugPort = await port();
- await fs.writeFile(path.join(work, 'config.json'), JSON.stringify({ sites: [{ name: 'fixture', title: 'Fixture notes', cwd: work, root, port: sitePort, build: ['sh', '-c', 'echo integrated-build'], inputs: ['public/index.html'] }] }));
- const web = start(binary, ['--listen', `127.0.0.1:${dashboard}`, '--catalog', path.join(work, 'config.json'), '--catalog-socket', path.join(work, 'catalog.sock'), '--state-dir', path.join(work, 'state')]);
+ const runtime = path.join(work, 'runtime');
+ await fs.mkdir(path.join(runtime, '9p'), { recursive: true });
+ start(path.resolve('zig-out/bin/9proc-demo'), ['--unix', path.join(runtime, '9p', 'fixture')]);
+ await wait(() => fs.stat(path.join(runtime, '9p', 'fixture')), '9P fixture posted');
+ await fs.writeFile(path.join(work, 'config.json'), JSON.stringify({ filesystem: '/', sites: [{ name: 'fixture', title: 'Fixture notes', cwd: work, root, port: sitePort, build: ['sh', '-c', 'echo integrated-build'], inputs: ['public/index.html'] }] }));
+ const startWeb = () => start(path.resolve('zig-out/bin/9ns'), ['--mntgen', '--', binary, '--listen', `127.0.0.1:${dashboard}`, '--catalog', path.join(work, 'config.json'), '--catalog-socket', path.join(work, 'catalog.sock'), '--state-dir', path.join(work, 'state')], { ...process.env, XDG_RUNTIME_DIR: runtime });
+ const web = startWeb();
const url = `http://127.0.0.1:${dashboard}`;
await wait(async () => (await fetch(url)).ok, 'server ready');
assert.equal((await (await fetch(url + '/_cloud9/config.json')).json()).catalog, true);
@@ -69,11 +75,35 @@ try {
await cdp('Page.navigate', { url });
await wait(() => evaluate(`document.getElementById('status')?.textContent.includes('entries')`), 'files loaded');
assert.equal(await evaluate(`document.querySelectorAll('header').length`), 1);
+ assert.equal(await evaluate(`document.querySelector('#sidebar')`), null);
assert.equal(await evaluate(`document.querySelector('.brand').textContent`), '9web');
assert.equal(await evaluate(`document.querySelector('footer').textContent`), 'served by 9web');
assert.equal(await evaluate(`document.title`), '/ — 9web');
+ assert.equal(await evaluate(`Boolean(document.querySelector('#entries a[data-path="/etc"]'))`), true);
assert.equal(await evaluate(`getComputedStyle(document.documentElement).backgroundColor`), 'rgb(255, 255, 255)');
assert.equal(await evaluate(`document.getElementById('view-files').getAttribute('aria-current')`), 'page');
+ // Browse a real mounted 9P tree, including finite zero-stat-length files.
+ async function browse(path) {
+ await evaluate(`document.getElementById('path').value = ${JSON.stringify(path)}; document.getElementById('path-form').requestSubmit()`);
+ await wait(() => evaluate(`document.getElementById('status').textContent === 'File loaded.' || document.getElementById('status').textContent.includes('entries')`), 'mounted path loaded');
+ }
+ await browse('/mnt/9p/fixture/build');
+ assert.equal(await evaluate(`Boolean(document.querySelector('#entries a[data-path="/mnt/9p/fixture/build/zig_version"]'))`), true);
+ await browse('/mnt/9p/fixture/runtime/pid');
+ assert.match(await evaluate(`document.getElementById('editor').value`), /^\d+/);
+ await browse('/mnt/9p/fixture/runtime/ctl');
+ assert.equal(await evaluate(`document.getElementById('editor').value`), '');
+ await browse(path.join(work, 'large.txt'));
+ assert.equal(await evaluate(`document.getElementById('editor').value.length`), 180000, 'full-msize browser reads across several frames');
+ await browse('/_9web/sites/fixture');
+ await click('#entries a[data-path="/_9web/sites/fixture/events"][data-follow]');
+ await wait(() => evaluate(`document.getElementById('stream').textContent.includes('revision')`), 'direct follow of blocking events');
+ assert.equal(await evaluate(`document.getElementById('go').disabled`), false, 'stream does not block navigation');
+ await click('#follow');
+ assert.equal(await evaluate(`document.getElementById('status').textContent`), 'Stream stopped.');
+ await browse('/');
+ await fs.mkdir('.zig-cache/catalog-ui', { recursive: true });
+ await fs.writeFile('.zig-cache/catalog-ui/files.png', Buffer.from((await cdp('Page.captureScreenshot', { format: 'png' })).data, 'base64'));
await view('sites'); await readySites();
assert.equal(await evaluate(`document.title`), 'sites — 9web');
assert.equal(await evaluate(`document.querySelector('#sites-entries .site-name').href`), `http://127.0.0.1:${sitePort}/`);
@@ -130,8 +160,18 @@ try {
assert.match(competitor.output, /address already in use/);
web.kill('SIGTERM'); await once(web, 'exit');
await fs.unlink(path.join(work, 'catalog.sock'));
- start(binary, ['--listen', `127.0.0.1:${dashboard}`, '--catalog', path.join(work, 'config.json'), '--catalog-socket', path.join(work, 'catalog.sock'), '--state-dir', path.join(work, 'state')]);
+ startWeb();
await wait(async () => (await fetch(url)).ok && (await fetch(`http://127.0.0.1:${sitePort}`)).ok, 'immediate restart with recent HTTP traffic');
+ // Opt-in, read-only smoke navigation against an installed workstation.
+ if (process.env.NINE_WEB_LIVE) {
+ for (const pathname of ['/mnt/9p', '/mnt/9p/agents', '/mnt/9p/agents/codex/history', '/mnt/9p/zmx/daybreak/command', '/mnt/9p/zmx/daybreak/cwd', '/usr/bin']) {
+ await cdp('Page.navigate', { url: process.env.NINE_WEB_LIVE + pathname });
+ await wait(() => evaluate(`document.getElementById('path')?.value === ${JSON.stringify(pathname)} && (document.getElementById('status').textContent === 'File loaded.' || document.getElementById('status').textContent.includes('entries'))`), 'live navigation: ' + pathname, 30000).catch(async error => {
+ throw new Error(error.message + ': ' + await evaluate(`document.getElementById('status')?.textContent`));
+ });
+ console.log('live browser navigation passed:', pathname);
+ }
+ }
console.log('catalog_ui: shared shell/style, tab history, file/log navigation, build control, focus, dirty edits and mobile layout passed');
} catch (e) {
for (const child of children) console.error(child.output.slice(-5000));
@@ -141,5 +181,5 @@ try {
for (const p of children.reverse()) {
if (p.exitCode === null) { p.kill('SIGTERM'); await Promise.race([once(p, 'exit'), new Promise(r => setTimeout(r, 3000))]); if (p.exitCode === null) p.kill('SIGKILL'); }
}
- await fs.rm(work, { recursive: true, force: true });
+ await fs.rm(work, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
}
diff --git a/test/web/host_fs.py b/test/web/host_fs.py
new file mode 100644
index 0000000..7a55eec
--- /dev/null
+++ b/test/web/host_fs.py
@@ -0,0 +1,161 @@
+#!/usr/bin/env python3
+"""Exercise host export; mutations are confined to our temporary directory."""
+from catalog import Nine, eventually, http, port, string
+import json
+import os
+from pathlib import Path
+import socket
+import struct
+import subprocess
+import sys
+import tempfile
+
+
+def main():
+ binary = str(Path(sys.argv[1]).resolve())
+ ns = Path('zig-out/bin/9ns').resolve()
+ with tempfile.TemporaryDirectory(prefix='9web-host-') as tmp:
+ root = Path(tmp)
+ p = port()
+ public = root/'public'
+ public.mkdir()
+ (public/'index.html').write_text('site still works')
+ (root/'source').write_text('original data')
+ (root/'alias').symlink_to(root, target_is_directory=True)
+ (root/'dangling').symlink_to(root/'missing')
+ os.mkfifo(root/'fifo')
+ large = root/'large'
+ large.mkdir()
+ for i in range(1500):
+ (large/f'entry-{i:04}').touch()
+ config = {'filesystem': '/', 'sites': [{'name': 'fixture', 'title': 'Fixture', 'root': str(public), 'cwd': tmp, 'port': port(), 'build': ['sh', '-c', 'echo host-build']}]}
+ (root/'config.json').write_text(json.dumps(config))
+ runtime = root/'runtime'
+ registry = runtime/'9p'
+ registry.mkdir(parents=True)
+ demo = subprocess.Popen([str(Path('zig-out/bin/9proc-demo').resolve()), '--unix', str(registry/'fixture')], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ eventually(lambda: (registry/'fixture').exists())
+ event_config = {'sites': [{**config['sites'][0], 'port': port()}]}
+ (root/'events.json').write_text(json.dumps(event_config))
+ event_server = subprocess.Popen([binary, '--listen', f'127.0.0.1:{port()}', '--catalog', str(root/'events.json'), '--catalog-socket', str(registry/'events'), '--state-dir', str(root/'events-state')], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ eventually(lambda: (registry/'events').exists())
+ args = [binary, '--listen', f'127.0.0.1:{p}', '--catalog', str(root/'config.json'), '--catalog-socket', str(root/'cat.sock'), '--state-dir', str(root/'state')]
+ # Match the deployed wrapper. No host mount is changed.
+ if not ns.exists():
+ raise RuntimeError('build 9ns first: zig build 9ns')
+ proc = subprocess.Popen([str(ns), '--mntgen', '--', *args], env={**os.environ, 'XDG_RUNTIME_DIR': str(runtime)}, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ try:
+ eventually(lambda: http(p)[0] == 200)
+ entries = json.loads(http(p, '/fs/')[2])
+ assert {'home', 'etc', 'usr', 'mnt', '_9web'} <= {x['name'] for x in entries}, entries
+ assert http(p, '/fs/etc/hostname')[2] == Path('/etc/hostname').read_bytes()
+ assert http(p, '/fs'+tmp+'/alias/source')[2] == b'original data'
+ assert 'dangling' in {x['name'] for x in json.loads(http(p, '/fs'+tmp)[2])}
+ assert http(p, '/fs'+tmp+'/fifo')[0] >= 400
+ listing = http(p, '/fs'+tmp+'/large')
+ assert listing[0] == 200 and len(json.loads(listing[2])) == 1500
+ assert http(p, '/fs/dev/null')[0] >= 400
+ assert http(p, '/fs/mnt/9p')[0] == 200
+ assert 'fixture' in {x['name'] for x in json.loads(http(p, '/fs/mnt/9p')[2])}
+ assert http(p, '/fs/mnt/9p/fixture/build/zig_version')[0] == 200
+ assert b'0.17' in http(p, '/fs/mnt/9p/fixture/build/zig_version')[2]
+ mounted = '/fs/mnt/9p/fixture'
+ assert http(p, mounted+'/scratch/upload', 'PUT', 'via FUSE')[0] == 201
+ assert http(p, mounted+'/scratch/upload')[2] == b'via FUSE'
+ control = http(p, mounted+'/runtime/ctl', 'PUT', 'echo mount-control')
+ assert control[0] == 200, control
+ assert b'mount-control' in http(p, mounted+'/runtime/ctl')[2]
+ finite = Nine(str(root/'cat.sock'))
+ finite.walk('mnt/9p/fixture/runtime/ctl')
+ finite.rpc(112, struct.pack('<IB', 2, 0))
+ data = finite.rpc(116, struct.pack('<IQI', 2, 0, 4096))[4:]
+ assert b'mount-control' in data
+ assert finite.rpc(116, struct.pack('<IQI', 2, len(data), 4096))[4:] == b''
+ finite.s.close()
+ assert http(p, mounted+'/scratch/upload', 'DELETE')[0] == 204
+ # A blocking read through FUSE must not stall the shared backend.
+ events = Nine(str(root/'cat.sock'))
+ events.walk('mnt/9p/events/sites/fixture/events')
+ events.rpc(112, struct.pack('<IB', 2, 0))
+ assert json.loads(events.rpc(116, struct.pack('<IQI', 2, 0, 4096))[4:])['phase'] == 'idle'
+ request = struct.pack('<IQI', 2, 0, 4096)
+ events.s.sendall(struct.pack('<IBH', len(request)+7, 116, 2) + request)
+ events.rpc(124, struct.pack('<I', 1), 3)
+ # Also wake/retry this parked request from an unrelated catalogue change.
+ assert http(p, '/fs/_9web/sites/fixture/ctl', 'PUT', 'build')[0] == 200
+ assert http(p, '/fs/mnt/9p/events/sites/fixture/ctl', 'PUT', 'build')[0] == 200
+ size, typ, tag = struct.unpack('<IBH', events.recv(7))
+ assert (typ, tag) == (117, 2)
+ assert json.loads(events.recv(size-7)[4:])['revision'] > 1
+ events.s.close()
+ eventually(lambda: json.loads(http(p, '/fs/mnt/9p/events/sites/fixture/status')[2])['generation'] == 1)
+ # Repeated flush+clunk must release the underlying blocking reads,
+ # rather than exhaust the bounded task table or steal later events.
+ cancel = Nine(str(root/'cat.sock'))
+ for _ in range(40):
+ cancel.walk('mnt/9p/events/sites/fixture/events')
+ cancel.rpc(112, struct.pack('<IB', 2, 0))
+ cancel.rpc(116, struct.pack('<IQI', 2, 0, 4096))
+ cancel.s.sendall(struct.pack('<IBH', len(request)+7, 116, 2) + request)
+ cancel.s.sendall(struct.pack('<IBHH', 9, 108, 3, 2))
+ # An interrupted old read may be answered before Rflush.
+ while True:
+ n, kind, tag = struct.unpack('<IBH', cancel.recv(7))
+ cancel.recv(n-7)
+ if (kind, tag) == (109, 3):
+ break
+ assert tag == 2 and kind in (107, 117), (kind, tag)
+ cancel.rpc(120, struct.pack('<I', 2), 4)
+ cancel.s.close()
+ # Directory and upload/edit/append/delete use the same HTTP/9P path.
+ target = '/fs'+tmp+'/created'
+ assert http(p, target+'/', 'PUT')[0] == 201
+ assert http(p, target+'/file', 'PUT', 'abcdef')[0] == 201
+ assert http(p, target+'/file', 'PUT', 'xy')[0] == 200
+ assert (root/'created/file').read_bytes() == b'xy'
+ assert http(p, target+'/file?append=1', 'PUT', 'z')[0] == 200
+ assert http(p, target+'/file')[2] == b'xyz'
+ assert http(p, target+'/file', headers={'Range': 'bytes=1-2'})[2] == b'yz'
+ assert http(p, target+'/file', 'HEAD')[1]['content-length'] == '3'
+ # The local namespace is also accessible through raw 9P.
+ nine = Nine(str(root/'cat.sock'))
+ rel = tmp.lstrip('/')
+ assert nine.read(rel+'/source') == b'original data'
+ nine.write(rel+'/created/file', 'short')
+ assert (root/'created/file').read_text() == 'short'
+ # Twstat rename on the backing filesystem (not a UI copy/delete).
+ nine.walk(rel+'/created/file')
+ stat = struct.pack('<HI', 0xffff, 0xffffffff) + b'\xff'*13 + struct.pack('<IIIQ', 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffffffffffff) + string('renamed') + string('')*3
+ stat = struct.pack('<H', len(stat)) + stat
+ nine.rpc(126, struct.pack('<IH', 2, len(stat)) + stat)
+ nine.rpc(120, struct.pack('<I', 2))
+ assert (root/'created/renamed').read_text() == 'short'
+ # Virtual tree stays read-only apart from ctl.
+ assert http(p, '/fs/_9web/new', 'PUT', 'bad')[0] == 403
+ assert http(p, '/fs/_9web/sites/fixture/public/index.html', 'PUT', 'bad')[0] == 403
+ assert http(p, '/fs/_9web/sites/fixture/ctl', 'PUT', 'build')[0] == 200
+ eventually(lambda: b'host-build' in http(p, '/fs/_9web/sites/fixture/log')[2])
+ assert http(config['sites'][0]['port'])[2] == b'site still works'
+ assert http(p, '/_cloud9/catalog.json')[0] == 200
+ assert json.loads(http(p, '/_cloud9/catalog.json')[2])['namespace'] == '/_9web'
+ assert http(p, target+'/renamed', 'DELETE')[0] == 204
+ assert http(p, target, 'DELETE')[0] == 204
+ nine.s.close()
+ print('host_fs: root, symlinks, special-file refusal, /mnt/9p, upload/edit/append/rename/delete, raw 9P and catalogue controls passed')
+ finally:
+ proc.terminate()
+ try:
+ output = proc.communicate(timeout=5)[0]
+ except subprocess.TimeoutExpired:
+ proc.kill()
+ output = proc.communicate()[0]
+ if sys.exc_info()[0]:
+ print(output.decode(errors='replace'), file=sys.stderr)
+ demo.terminate()
+ demo.wait(timeout=5)
+ event_server.terminate()
+ event_server.wait(timeout=5)
+
+
+if __name__ == '__main__':
+ main()