From f9ca3fb5ba767300bec3f1fbb13fc5e6552a90e3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 12 Oct 2026 16:48:56 -0300 Subject: 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. --- test/web/host_fs.py | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 test/web/host_fs.py (limited to 'test/web/host_fs.py') 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(' 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('