summaryrefslogtreecommitdiff
path: root/test/web/prefix.py
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-12 17:15:03 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:16 -0300
commit7a07e24916cd5bc762996d81aa1faf550177cd6f (patch)
tree4530a8562fb3f068cc4340f1fab1f6c599721735 /test/web/prefix.py
parentf9ca3fb5ba767300bec3f1fbb13fc5e6552a90e3 (diff)
downloadcloud9-7a07e24916cd5bc762996d81aa1faf550177cd6f.tar.gz
cloud9-7a07e24916cd5bc762996d81aa1faf550177cd6f.zip
9web: serve prefixed sites through the composed 9P namespace
Post only the pure site/control/discovery tree, with a separate host-only adapter and no duplicate supervision. Serve websites, metadata and legacy controls through the ordinary 9P mux; retain whole-root filesystem browsing and compatibility paths. Pin public file descriptors across publication. Add opt-in build-time HTML/CSS prefix packaging with separate atomic preview generations and unchanged JavaScript/default output. Optional compatibility ports use ?u16. Deploy all five workstation sites on [::]:8090, with /mnt/9p/9web controls. Document Plan 9 references, companion build commits, shared-origin trust and live validation. Validated catalogue, host/FUSE, HTTP FS, mux, prefix and Chromium suites; original E2E 32 scenarios; all five live sites, blog navigation, IPv4/IPv6 and real cafe build through 9P.
Diffstat (limited to 'test/web/prefix.py')
-rw-r--r--test/web/prefix.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/test/web/prefix.py b/test/web/prefix.py
new file mode 100644
index 0000000..68fe974
--- /dev/null
+++ b/test/web/prefix.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+import hashlib
+import importlib.util
+from pathlib import Path
+import tempfile
+
+spec = importlib.util.spec_from_file_location('prefix', Path(__file__).resolve().parents[2] / 'web/prefix.py')
+p = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(p)
+prefix = '/sites/fixture'
+original = '''<!DOCTYPE html><html><head><style>
+/* url(/comment) */
+a[href="/blog/"]{background:url('/assets/a.png');content:"/ordinary"}
+@font-face{src:url(/fonts/a.woff2)}
+@import "/main.css";
+.svg{background:url("data:image/svg+xml,%3Csvg viewBox='0 0 10 10'%3E")}
+</style></head><body>
+<a href="/blog/post?q=1&amp;x=2#part">go</a><img src="/img.png" srcset="/one.png 1x, /two.png 2x">
+<a href="//elsewhere/foo">external</a><a href="https://other/x">external</a>
+<a href="#part">fragment</a><img src="data:image/png;base64,abcd">
+<a href="../page.html">relative</a><div style="background:url(/img.png)"></div>
+<code>href="/example"</code><!-- <a href="/comment"> -->
+<script>const s = '/assets/unmodified.js'; fetch('/api/pokes');</script>
+<script type="application/json">{"url":"/unmodified"}</script>
+</body></html>'''
+rewritten = p.html(original, prefix)
+assert 'srcset=" /sites/fixture/a.png 1x, /sites/fixture/b.png 2x"' in p.html('<img srcset=" /a.png 1x, /b.png 2x">', prefix)
+assert 'url(&quot;/sites/fixture/a.png&quot;)' in p.html('<div style="background:url(&quot;/a.png&quot;)"></div>', prefix)
+assert p.srcset('data:image/svg+xml,/untouched 1x, /a.png 2x', prefix) == 'data:image/svg+xml,/untouched 1x, /sites/fixture/a.png 2x'
+for piece in ['href="/sites/fixture/blog/post?q=1&amp;x=2#part"',
+ 'srcset="/sites/fixture/one.png 1x, /sites/fixture/two.png 2x"',
+ 'url(/sites/fixture/fonts/a.woff2)', 'a[href="/sites/fixture/blog/"]',
+ '@import "/sites/fixture/main.css"']:
+ assert piece in rewritten, piece
+for piece in ['/* url(/comment) */', 'content:"/ordinary"', '<code>href="/example"</code>',
+ "fetch('/api/pokes')", "const s = '/assets/unmodified.js'", '{"url":"/unmodified"}',
+ '<!-- <a href="/comment"> -->', 'href="../page.html"', 'href="#part"',
+ 'href="//elsewhere/foo"', 'href="https://other/x"', 'src="data:image/png;base64,abcd"',
+ 'url("data:image/svg+xml,%3Csvg viewBox=\'0 0 10 10\'%3E")']:
+ assert piece in rewritten, piece
+for invalid in ['', '/', '//host', '/a/../b', '/a?b', '/a#b', 'http://a']:
+ try:
+ p.check_prefix(invalid)
+ raise AssertionError(invalid)
+ except ValueError:
+ pass
+with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ source, out = root/'normal', root/'preview'
+ source.mkdir()
+ (source/'index.html').write_text(original)
+ (source/'app.js').write_text("fetch('/api/pokes')")
+ def hashes():
+ return {str(f.relative_to(source)): hashlib.sha256(f.read_bytes()).hexdigest() for f in source.rglob('*') if f.is_file()}
+ before = hashes()
+ p.publish(source, out, prefix)
+ assert hashes() == before
+ assert out.is_symlink() and (out/'index.html').read_text() == rewritten
+ assert (out/'app.js').read_bytes() == (source/'app.js').read_bytes()
+ previous = out.resolve()
+ (source/'app.js').unlink()
+ p.publish(source, out, prefix)
+ assert out.resolve() != previous and previous.exists()
+ assert not (out/'app.js').exists(), 'stale files must not leak into next generation'
+ (source/'escape').symlink_to('/etc/hostname')
+ current = out.resolve()
+ try:
+ p.publish(source, out, prefix)
+ raise AssertionError('symlink accepted')
+ except ValueError:
+ pass
+ assert out.resolve() == current, 'failed generation changed published output'
+print('prefix: scoped HTML/CSS, unchanged JS/text/source, atomic publication and failure preservation passed')