diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-07 10:35:09 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-07 10:35:09 +0200 |
| commit | 2c0903c648e24b4e2adf20492398e8b67d033b49 (patch) | |
| tree | 0435f298010f0f946362f28baebbe88337ca8768 /packages/meshbay-hub/tests/test_spa_syntax.py | |
| parent | 0ed078c92cabab1dab0f70f321562032ea549ce6 (diff) | |
| parent | eeda274d751c537f4ecef3087994a16a9517478f (diff) | |
| download | meshbay-2c0903c648e24b4e2adf20492398e8b67d033b49.tar.gz | |
Merge branch 'refactor/groups-phase1'
Groups refactor, phases 1-3.
The root model replaces the old `upload` flag and group-wide `member_upload`
with per-root `writable`/`removable`/`ejected`, carried by a `RootSet` that
both front doors — the loopback API and signed MNP — reach through the same
`ops` functions. MNP goes to 1.1, additively: the roots table now rides on
`index_delta`, so a root added, removed, ejected or plugged reaches every
connected client instead of only whoever reloaded.
The group UI becomes a plugin architecture: an application is a registry
entry in `apps.js` plus its own files, with directories stored generically
by `ops.set_app_directories` under whatever the app is called. A reference
application, hidden behind `?dev=1`, is what makes that claim testable —
adding it is what found the two places still naming apps by hand.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011pvMdvLBG92jyhvD5pD6us
Diffstat (limited to 'packages/meshbay-hub/tests/test_spa_syntax.py')
| -rw-r--r-- | packages/meshbay-hub/tests/test_spa_syntax.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/packages/meshbay-hub/tests/test_spa_syntax.py b/packages/meshbay-hub/tests/test_spa_syntax.py new file mode 100644 index 0000000..352f84b --- /dev/null +++ b/packages/meshbay-hub/tests/test_spa_syntax.py @@ -0,0 +1,85 @@ +""" +Every SPA module parses. + +This is the cheapest possible test and the suite did not have it, which is how +a `${/* ... */''}` — htm template syntax, pasted into a plain object literal — +reached a committed file. Nothing else here would catch it: the source-reading +guards (`test_hook_ordering`, `test_transport_contracts`, `test_spa_ordering`) +match patterns in text that parses or does not, and the browser harnesses only +load the few modules they need. + +**`node --check foo.js` is not the check.** It reports success on exactly the +file above: given a `.js` extension it makes its own decision about how to +parse, and a module-syntax error inside one can come back clean. Copying to +`.mjs` first is what forces the module parser, and it is the difference +between a green run and a real one — the same shape as the "a test that models +a fix agrees with it by construction" note in CLAUDE.md, one level lower. + +It says nothing about names, imports resolving, or hooks being in order. Those +have their own tests. This one only says the file is JavaScript. +""" + +import shutil +import subprocess +from pathlib import Path + +import pytest + +STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static" + +pytestmark = pytest.mark.skipif( + shutil.which("node") is None or not STATIC.exists(), + reason="node or the SPA sources are not available") + + +def _modules() -> list[Path]: + # vendor/ is third-party and shipped as-is; sw.js is a service worker, a + # classic script by definition, and transport.js is loaded with a plain + # <script> tag for the same historical reason (see its own header). + files = sorted(STATIC.glob("*.js")) + sorted((STATIC / "locales").glob("*.js")) + return [f for f in files if f.name not in ("sw.js",)] + + +def test_every_module_parses(tmp_path): + broken: list[str] = [] + for path in _modules(): + # The .mjs copy is the whole point — see this module's docstring. + copy = tmp_path / (path.stem + ".mjs") + copy.write_text(path.read_text(encoding="utf-8"), encoding="utf-8") + proc = subprocess.run(["node", "--check", str(copy)], + capture_output=True, text=True) + if proc.returncode != 0: + first = (proc.stderr or "").strip().splitlines() + detail = next((ln for ln in first if "Error" in ln), first[:1] and first[0] or "") + broken.append(f"{path.name}: {detail}") + + assert not broken, "SPA modules that do not parse:\n" + "\n".join(broken) + + +def test_the_check_would_notice_a_broken_file(tmp_path): + """ + The test above passing means nothing unless it can fail, and the way it + fails is the interesting part: this same content in a file called `.js` + is reported as fine. + """ + bad = "export const a = {\n ${/* not object syntax */''}\n b: 1,\n};\n" + + as_js = tmp_path / "sample.js" + as_js.write_text(bad, encoding="utf-8") + lenient = subprocess.run(["node", "--check", str(as_js)], + capture_output=True, text=True) + + as_mjs = tmp_path / "sample.mjs" + as_mjs.write_text(bad, encoding="utf-8") + strict = subprocess.run(["node", "--check", str(as_mjs)], + capture_output=True, text=True) + + assert strict.returncode != 0, ( + "the .mjs check no longer reports a module syntax error — this whole " + "test is then measuring nothing") + if lenient.returncode == 0: + # Recorded rather than asserted: this is a Node behaviour, and it + # improving would be good news, not a failure. The .mjs copy stays + # either way, because relying on the loose path is what let this + # through once already. + pass |