diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 76b6e7a7..ce8d13b2 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -49,10 +49,28 @@ jobs: # place the ruled contract is executed rather than described. It is # `--noconftest` safe and needs no consumer, for the same reason and by # the same means as its two neighbours. + # + # § 3.4 slice S1 (`docs/front-end-package-boundary.md`, openDox-spec #8 + # → a44ac06d; RULED opensoft/openxFactory#656 comment 5642758731) adds + # `tests/test_web_boundary.py` on the same footing: it declares the + # `src/opendox/web/` census (`tests/fixtures/web_boundary_census.yaml`) + # and asserts the four things that hold the front-end package boundary + # — the census is complete, no file outside the gate loop names a + # route another column declares, every relative import resolves and + # stays in its class, and no stage-named file carries a governance + # literal. Three of the four are marked `xfail(strict=True)` for + # defects slices S2–S7 close (RULED, START S1–S3 NOW, same comment) — + # `strict=True` is what keeps this addition from putting the required + # check red for the length of that arc, and what turns it red the + # moment a later slice closes a defect without removing that slice's + # marker. `--noconftest` safe: it parses the tree and the declared + # YAML census, and imports no view module (they are JavaScript) and no + # `opendox` submodule. - name: pytest run: >- python -m pytest -q tests/test_leg_shape.py tests/test_consumer_reach.py tests/test_profile_registration.py + tests/test_web_boundary.py --noconftest diff --git a/tests/fixtures/web_boundary_census.yaml b/tests/fixtures/web_boundary_census.yaml new file mode 100644 index 00000000..7f8fc9ea --- /dev/null +++ b/tests/fixtures/web_boundary_census.yaml @@ -0,0 +1,314 @@ +# The declared census for `docs/front-end-package-boundary.md` +# (opensoft/openDox-spec #8 -> a44ac06d) § 3.2, read by +# `tests/test_web_boundary.py` -- slice S1, "declare the census and measure +# the defect" (opensoft/openxFactory#656 comment 5642758731, 2026-09-12, +# "RULED, same sitting -> START S1-S3 NOW, with the note amended to carry +# these rulings"). +# +# Every file under `src/opendox/web/` (measured at openDox-code `main` +# `a99eba03e31a0aee1cc15a061fdf718cc88a2c44`, the same head the note itself +# measured) appears here EXACTLY ONCE, `path` relative to that directory. +# `tests/test_web_boundary.py::test_every_web_file_is_classified_exactly_once` +# is the ratchet: a new file with no row here fails it immediately (the note +# § 4.5 point 1) -- that is the whole point of a DECLARED census over an +# inferred one. +# +# Classes, per the note's § 2.1: +# A openDox core. Names no governance status or stage word, and +# addresses no route another column declares. +# B the gate loop. Its SUBJECT is a gate act; its binding belongs to +# openXdox through the seam § 4 describes. Exempt, by construction, +# from the route-ownership assertion (#2 below) -- a gate-loop file +# naming a gate route is the boundary working, not breaking. +# C a stage-named region. Structurally neutral; its NAMES are one +# domain's mapping and must be parameterized from the registered +# domain profile (S7), never a literal. +# "?" transitional. A SPLIT file carrying more than one class's substance +# (class-A or class-C substance AND a class-B, or openxFactory-adapter, +# tail). Legitimate ONLY until slice S4 does the split -- after S4 a +# "?" row still standing fails the census assertion, because a +# permanent "undecided" is an escape hatch, not a boundary (note § 4.5 +# point 1). +# +# `tail` (optional): set on a class-A row whose file ALSO carries a rendered +# label or a corpus path (note § 2.2 rule 3) -- the identifier is named so S7 +# has a starting point. `note` (optional): free-text provenance, echoing the +# note's own `evidence` column. +# +# RULINGS APPLIED HERE, from opensoft/openxFactory#656 comment 5642758731 +# (Brett Heap, 2026-09-12T02:07:53Z, "RULED -- § 3.4 front-end package +# boundary, the five open questions ... every recommended answer adopted"), +# amending the note's own § 3.2 table: +# +# Q1 views/docs.js stays class A, its area map (`AREA_ORDER`) carried as +# a declared C tail, parameterized at S7. No census change from the +# note's own (recommendation-written) table. +# Q2 views/explorer.js is class C OUTRIGHT -- reclassified here from the +# note's "?" to "C": neither it nor the drill banner is class B, and +# explorer.js's only domain content is the artifact-folder vocabulary +# (a projection, not a split file). This is the one row this fixture +# changes from the note's own table. +# Q3 views/repo-selector.js SPLITS (picker + refresh -> A; the two +# `/actions/gate/*` project commissions -> a contributed binding at +# S4/S5; `/actions/apply-register-edits` leaves the bundle entirely) +# -- stays "?" here because the split itself is slice S4's act, not +# S1's; § 4.5 point 1 keeps "?" legitimate until then. The same rule +# (“a route constant travels with the binding that calls it, never +# with the model that declares it”) leaves `views/lens-model.js` and +# `views/staging-workbench-model.js` at "?" for the same reason. +# Q4 `/source/` is openDox's; discharged at slice S6 by moving the ROUTE +# (`openxdox/serve_projection.py`), not by reclassifying `views/viewer.js` +# here -- it stays class A, its one ownership breach carried as a +# `note`. +# Q5 views/intent-feed.js keeps RULED OQ-F (`not_moved`, openxFactory's); +# its two importers (`dispose.js`, `wheel.js`) are fixed at slice S2, +# not by any census reclassification here. +# +# Totals after Q2's reclassification (unchanged from the note otherwise): +# A 20 files (18 hand-authored + 2 vendored), 11,702 lines +# B 4 files, 1,597 lines +# C 14 files (13 + explorer.js), 11,854 lines (11,575 + 279) +# ? 4 files (5 - explorer.js), 5,432 lines (5,711 - 279) +# total 42 files, 30,585 lines -- unchanged (a reclassification, not a move) + +schema_version: 1 +kind: web-boundary-census +source_note: "opensoft/openDox-spec docs/front-end-package-boundary.md @ a44ac06d" +ruling_comment: "opensoft/openxFactory#656 comment 5642758731 (2026-09-12T02:07:53Z)" +measured_at: "opensoft/openDox-code main a99eba03e31a0aee1cc15a061fdf718cc88a2c44" + +files: + - path: app.js + class: A + loc: 1155 + note: "the shell; imports 20 view modules; its only class-B import is gate.js at :43 (discharged by S3's view registry)" + + - path: index.html + class: C + loc: 119 + note: "seven tab labels are stage names; mounts are id=view-" + + - path: styles.css + class: C + loc: 2574 + note: "four --st-brainstorm/--st-staged/--st-proposal/--st-realized status colour tokens (16 definitions); :1278-1295 styles intent-feed's chips" + + - path: vendor/markdown-it.min.js + class: A + loc: 2 + note: "vendored MIT Markdown renderer; viewer.js's only external dependency; html option disabled" + + - path: vendor/.gitkeep + class: A + loc: 0 + note: "directory keeper" + + - path: views/account-menu.js + class: A + loc: 181 + note: "header menu; only import is helpers.js" + + - path: views/board.js + class: C + loc: 247 + note: "four lifecycle columns; 25 governance literals" + + - path: views/bullseye.js + class: A + loc: 398 + note: "pure shared bullseye SVG; zero governance literals" + + - path: views/canvas-model.js + class: C + loc: 215 + note: "cluster canvas derivation; cluster/possible/supersede are governance nouns" + + - path: views/canvas.js + class: C + loc: 404 + note: "renders canvas-model.js's output; 7 governance literals" + + - path: views/composed-model.js + class: A + loc: 329 + exempt: COMPOSED_COLLECTIONS + note: "declared exempt (note § 2.2 rule 3) -- see declared_exemptions below" + + - path: views/dispose.js + class: B + loc: 427 + note: "GATE_DISPOSE_ROUTE :28 and GATE_PROPOSE_ROUTE :29 both under serve_gate.ACTIONS_GATE_PREFIX" + + - path: views/doc-wheel.js + class: C + loc: 491 + note: "docs-pane wheel; imports wheel-model.js" + + - path: views/docs.js + class: A + loc: 189 + tail: AREA_ORDER + note: "Q1: stays openDox/class A; AREA_ORDER :18 hardcodes ideation/brainstorm and ideation/staging, parameterized at S7" + + - path: views/doxbench-chat-model.js + class: A + loc: 1097 + note: "pure browser-session chat state; import-free" + + - path: views/doxbench-chat.js + class: A + loc: 1828 + note: "doxBench chat rail; imports only the pure chat model" + + - path: views/doxbench-editor.js + class: A + loc: 2966 + note: "doxBench authoring canvas; imports viewer.js and doxbench-state.js only" + + - path: views/doxbench-save.js + class: A + loc: 509 + note: "ordered Save orchestration; import-free" + + - path: views/doxbench-state.js + class: A + loc: 1049 + exempt: SCOPE_KINDS + note: "declared exempt (note § 2.2 rule 3) -- see declared_exemptions below" + + - path: views/edit.js + class: A + loc: 48 + note: "select-to-edit transport; ACTIONS_EDIT_ROUTE answered by openDox's own serve.py" + + - path: views/explorer.js + class: C + loc: 279 + note: "Q2 RULING: class C outright (was \"?\" in the note's own table) -- a projection whose only domain content is the artifact-folder vocabulary; classifyChangeFile; reads staged_topics[].files / changes[].files" + + - path: views/funnel.js + class: C + loc: 538 + note: "realization funnel; imports model.js's COLUMN_KEYS; 10 governance literals" + + - path: views/gate.js + class: B + loc: 184 + note: "GATE_ACTIONS = [demote,edit,ratify,kickoff]; GATE_RATIFY_ROUTE :120 under the gate prefix" + + - path: views/grouping.js + class: A + loc: 246 + tail: TALLY_FIELDS + note: "TALLY_FIELDS :34-41 pairs each schema key with a rendered label; :51-52 test c.status === active/archived; parameterized at S7" + + - path: views/helpers.js + class: A + loc: 58 + note: "el()/txt()/basename()/heat bands; no import, no literal, no route" + + - path: views/lens-model.js + class: "?" + loc: 1070 + note: "pure and import-free (class-A substance) but LENS_SAVE_ROUTE :1036 and LENS_CLUSTER_ROUTE :1037 are class-B tails; splits at S4 (Q3's rule extended)" + + - path: views/lens.js + class: "?" + loc: 1524 + note: "VOCABULARIES :57 is a class-C vocabulary table; DTN_SEED_ROUTE :41 and STAGING_SEED_ROUTE :45 answered only by openxFactory's adapter; splits at S4" + + - path: views/lineage.js + class: C + loc: 140 + note: "stats strip and lineage/readiness overlay; 10 governance literals" + + - path: views/model.js + class: C + loc: 126 + note: "COLUMN_KEYS = [docs,clusters,possibles,staged,proposals,realized]; densest file in the tree" + + - path: views/notebook.js + class: A + loc: 109 + note: "open in NotebookLM tile action; both routes are openDox's serve.py" + + - path: views/outline-model.js + class: C + loc: 404 + note: "staged-topic outline model; REQUIRED_SECTIONS/QUESTION_SUBFIELDS/TEMPLATE_ORDER" + + - path: views/repo-selector-model.js + class: A + loc: 537 + tail: STATIONS + note: "STATIONS :517-522 pairs each schema key with a rendered label; parameterized at S7" + + - path: views/repo-selector.js + class: "?" + loc: 889 + note: "Q3 RULING: SPLITS -- picker+refresh -> A, two gate commissions -> contributed binding (S4/S5), apply-register-edits leaves the bundle; stays \"?\" until S4 does the split" + + - path: views/settings.js + class: A + loc: 234 + note: "theme/localStorage preference store; pure frontend, no data path" + + - path: views/staging-workbench-model.js + class: "?" + loc: 1949 + note: "pure workbench scope derivation carrying SIX class-B route constants (:543,:817,:818,:821,:822,:826); splits at S4" + + - path: views/staging-workbench.js + class: C + loc: 3315 + note: "full-screen workbench scoped to one topic-bearing tile" + + - path: views/swb-create.js + class: B + loc: 372 + note: "CREATE_ROUTE = /actions/gate/create-document (from staging-workbench-model.js:543)" + + - path: views/swb-model-intake.js + class: A + loc: 364 + note: "model-intake dialog; all routes answered by openDox's serve_workbench.py" + + - path: views/swb-session.js + class: B + loc: 614 + note: "FIRST_EDIT_ROUTE/ABANDON_SESSION_ROUTE/SHARE_SESSION_ROUTE/OPEN_PR_ROUTE, all under the gate prefix" + + - path: views/viewer.js + class: A + loc: 403 + note: "Q4: stays class A; its content comes from /source/, openXdox's TODAY -- the one § 2.2 rule 1 breach the census carries, discharged by slice S6 (route moves, file does not)" + + - path: views/wheel-model.js + class: C + loc: 1300 + note: "WHEEL_KEYS :25 and WHEEL_LABELS :27-34 -- six stage names, spelled twice" + + - path: views/wheel.js + class: C + loc: 1702 + note: "THE WHEEL; imports dispose.js (class B) and intent-feed.js (absent, RULED openxFactory); SOURCE_ROUTE :97" + +# The two identifiers § 2.2 rule 3 declares EXEMPT from the governance-literal +# sweep (assertion 4) -- carried here WITH THE REASON, per the note's own +# instruction ("an exemption that is silence is how a literal survives a +# vocabulary sweep"). Both live in plain class-A files (no `tail`), so they +# are already outside assertion 4's scope by construction; this list is the +# DECLARED record of why, checked for real by +# `test_declared_governance_literal_exemptions_are_real_and_out_of_scope`. +declared_exemptions: + - path: views/composed-model.js + identifier: COMPOSED_COLLECTIONS + reason: >- + six SNAPSHOT FIELD NAMES (documents, clusters, possibles, staged_topics, + changes, keyword_index), never rendered -- a schema key, not a stage + name (note § 2.2 rule 3). + - path: views/doxbench-state.js + identifier: SCOPE_KINDS + reason: >- + the three tile kinds a workbench session may be scoped to -- a state + key, never a label (note § 2.2 rule 3). diff --git a/tests/test_web_boundary.py b/tests/test_web_boundary.py new file mode 100644 index 00000000..686e154d --- /dev/null +++ b/tests/test_web_boundary.py @@ -0,0 +1,511 @@ +"""The front-end package boundary, declared and measured -- slice S1. + +`docs/front-end-package-boundary.md` (opensoft/openDox-spec #8 -> `a44ac06d`) +invents the boundary `src/opendox/web/` never had (§ 1: "40 files, 30,410 +lines, and NO package boundary at all today"). § 4.5 states the test that +holds it, four assertions, and slice S1 (§ 5) is: "Land the census table of +§ 3.2 as data plus `tests/test_web_boundary.py` with all four assertions, add +the file to `validate`'s explicit list in the SAME commit, and mark +assertions 2, 3 and 4 `@pytest.mark.xfail(strict=True)` citing the defect +each measures ... Assertion 1 is unmarked." This module is that file; the +declared data is `tests/fixtures/web_boundary_census.yaml`. + +RULED -- opensoft/openxFactory#656 comment `5642758731` (Brett Heap, +2026-09-12T02:07:53Z, "RULED -- § 3.4 front-end package boundary, the five +open questions ... every recommended answer adopted" / "RULED, same sitting +-> START S1-S3 NOW, with the note amended to carry these rulings"). The +fixture's own header carries each ruling against the census row it changes; +only `views/explorer.js` actually moves (from "?" to C, Q2) -- the other four +rulings (Q1, Q3, Q4, Q5) are recorded against slices S2/S4/S6/S7, not this one. + +WHY `strict=True`, AND WHY THAT IS THE WHOLE POINT (note § 4.5, last +paragraph). openDox-code's `validate` runs an explicit file list with +`--noconftest` (§ 1.2(d) / `.github/workflows/validate.yml`), so a new test +file is not exercised until the workflow names it -- naming it while three of +its four assertions are known-red would put the required check red for the +duration of the whole S2-S7 arc. Marking those three `xfail(strict=True)` +instead keeps `validate` GREEN while the defect stands, and flips it RED the +moment a later slice closes the defect without also removing the marker -- +the measurement cannot rot into a permanently tolerated failure, and a slice +that claims to have closed a defect it has not gets caught by CI rather than +by review. Symmetrically: a marker left in place after its defect is truly +gone is an XPASS, and `strict=True` turns THAT red too. + +A NOTE ON FIDELITY OVER TIDINESS. Assertions 2 and 3 are each implemented to +the FULL WIDTH of what § 4.5 states, not narrowed to whatever count would +make the note's own closing-paragraph slice attribution come out even. Where +that surfaced a real disagreement inside the note itself, the `reason=` +string says so rather than picking a slice number quietly. This does not +weaken the ratchet: `strict=True` only ever fires on an UNEXPECTED PASS, so +if a slice the note names ships without actually closing every site this +assertion checks, the marker stays valid (still XFAIL) and the check stays +green -- CI, not this module, is what makes an author look again before +removing a marker their slice has not fully earned. + +`--noconftest` SAFE, deliberately, like its three neighbours already on the +explicit list (`test_leg_shape.py`, `test_consumer_reach.py`, +`test_profile_registration.py`): this module parses the TREE and the +declared YAML census; it imports no view module (they are JavaScript, not +Python) and no `opendox` submodule, so it needs no fixture, no path +insertion and no installed consumer. `PyYAML` is already a runtime +dependency (`pyproject.toml`'s `[project] dependencies`), not a test-only +addition made here. + +A CREATED file (this module and its fixture): no carve-manifest row (RULED +OQ-C) -- the front end's package boundary did not exist before this note, so +there is nothing for either file to have been carved FROM. +""" + +from __future__ import annotations + +import re +from pathlib import Path + +import pytest +import yaml + +ROOT = Path(__file__).resolve().parents[1] +WEB_ROOT = ROOT / "src" / "opendox" / "web" +CENSUS_PATH = Path(__file__).resolve().parent / "fixtures" / "web_boundary_census.yaml" + +VALID_CLASSES = {"A", "B", "C", "?"} + + +def _load_census() -> dict: + with CENSUS_PATH.open(encoding="utf-8") as fh: + return yaml.safe_load(fh) + + +_CENSUS = _load_census() +_ROWS: list[dict] = _CENSUS["files"] +_EXEMPTIONS: list[dict] = _CENSUS["declared_exemptions"] +# Duplicates collapse silently here (a dict can only hold one value per key); +# `test_every_web_file_is_classified_exactly_once` checks the RAW list +# instead, so a duplicate row is still caught rather than swallowed by this +# convenience lookup. +_ROWS_BY_PATH: dict[str, dict] = {row["path"]: row for row in _ROWS} + + +def _real_web_files() -> set[str]: + return {p.relative_to(WEB_ROOT).as_posix() for p in WEB_ROOT.rglob("*") if p.is_file()} + + +def _assertion_4_scope() -> list[dict]: + """The 14 class-C files (13 in the note's own § 3.1 total, +1 for + `views/explorer.js` under Q2's ruling) plus the three declared class-A + tails (note § 2.2 rule 3): `views/docs.js`, `views/grouping.js`, + `views/repo-selector-model.js`.""" + return [row for row in _ROWS if row["class"] == "C" or row.get("tail")] + + +# --------------------------------------------------------------------------- +# Assertion 1 -- the census is complete, and "?" is transitional (note § 4.5 +# point 1). UNMARKED: this is the ratchet, and it must hold from the moment +# the census is written, or a new file with no row could survive silently. +# --------------------------------------------------------------------------- + +def test_every_web_file_is_classified_exactly_once() -> None: + real = _real_web_files() + declared = set(_ROWS_BY_PATH) + + missing_rows = sorted(real - declared) + assert not missing_rows, ( + f"{len(missing_rows)} file(s) under src/opendox/web/ carry no census " + f"row in tests/fixtures/web_boundary_census.yaml: {missing_rows} -- " + f"a new or renamed file must be classified in the same commit that " + f"adds it (note § 4.5 point 1)." + ) + + stale_rows = sorted(declared - real) + assert not stale_rows, ( + f"{len(stale_rows)} census row(s) name a file that no longer exists " + f"under src/opendox/web/: {stale_rows} -- update or remove the row." + ) + + raw_paths = [row["path"] for row in _ROWS] + dup_paths = sorted({p for p in raw_paths if raw_paths.count(p) > 1}) + assert not dup_paths, f"duplicate census row(s) for: {dup_paths}" + + bad_class_rows = sorted(row["path"] for row in _ROWS if row["class"] not in VALID_CLASSES) + assert not bad_class_rows, ( + f"row(s) with a class outside {sorted(VALID_CLASSES)}: {bad_class_rows}" + ) + + # LOC is provenance the fixture carries voluntarily (mirroring the + # note's own § 3.1 totals); a census that drifts from the tree it + # describes is itself a data-quality defect, and it is cheap to catch + # here before anything downstream trusts it. `wc -l` (what the note and + # this fixture were measured with) counts NEWLINE CHARACTERS, which + # `.count("\n")` mirrors exactly regardless of a missing trailing + # newline -- both simply count the same bytes. + mismatched_loc = [] + for row in _ROWS: + text = (WEB_ROOT / row["path"]).read_text(encoding="utf-8", errors="replace") + real_loc = text.count("\n") + if real_loc != row["loc"]: + mismatched_loc.append((row["path"], row["loc"], real_loc)) + assert not mismatched_loc, ( + f"census `loc` drifted from the tree (path, declared, actual): {mismatched_loc}" + ) + + +# --------------------------------------------------------------------------- +# Assertion 2 -- no file OUTSIDE class B names a route another column +# declares (note § 2.2 rule 1, § 4.5 point 2). Class B is exempt BY +# CONSTRUCTION: a gate-loop file naming a gate route is the boundary +# working, not breaking. +# --------------------------------------------------------------------------- + +# The three owners, per the note's § 3.3 table -- the ownership the front +# end does not yet know about. Matched as a JS/HTML STRING LITERAL +# (immediately after a quote character, immediately before the closing one), +# so a bare mention in a `//` comment -- +# `views/staging-workbench-model.js`:899's trailing +# `"agent_invocation", // /actions/gate/* and /actions/edit"` -- is not +# flagged: only a literal that ADDRESSES the route is the § 1.2(c)/(d) +# defect this assertion measures. +_OWNED_ROUTE_PATTERNS = { + "the gate prefix (serve_gate.ACTIONS_GATE_PREFIX)": re.compile(r'["\']/actions/gate/'), + "openxFactory's adapter lanes (serve_openxfactory_lanes.py)": re.compile( + r'["\']/actions/(?:dtn-seed|staging-seed|apply-register-edits)["\']' + ), + "openXdox's projection routes (serve_projection.py)": re.compile( + r'["\']/(?:snapshot-index\.json|source/?|projections/(?:evidence|workbench|role-authority))["\']' + ), +} + + +def _line_of(text: str, offset: int) -> int: + return text.count("\n", 0, offset) + 1 + + +def _route_ownership_violations() -> list[str]: + violations = [] + for row in _ROWS: + if row["class"] == "B": + continue # exempt by construction + text = (WEB_ROOT / row["path"]).read_text(encoding="utf-8") + for owner, pattern in _OWNED_ROUTE_PATTERNS.items(): + for m in pattern.finditer(text): + site = f"{row['path']}:{_line_of(text, m.start())}" + violations.append(f"{site} names {m.group(0)} ({owner})") + return violations + + +@pytest.mark.xfail( + strict=True, + reason=( + "docs/front-end-package-boundary.md § 4.5 point 2 (opensoft/openDox-spec " + "#8 -> a44ac06d): 18 sites outside class B name a route another column " + "declares -- 10 the gate prefix (views/lens-model.js:1036/1037, " + "views/repo-selector.js:39/43, views/staging-workbench-model.js:543/" + "817/818/821/822/826), 3 openxFactory's adapter lanes " + "(views/lens.js:41/45, views/repo-selector.js:46), 5 openXdox's " + "projection routes (views/repo-selector.js:33, app.js:183/184, " + "views/viewer.js:314, views/wheel.js:97). The note's § 4.5 closing " + "paragraph assigns closure to slices S5 and S6; its own per-site " + "table (point 2) instead reads S4 for 14 of the 18 and S6 for the " + "remaining 4 -- the two do not fully agree, flagged here rather than " + "silently reconciled. Unmark only once verified green, whichever " + "slice(s) actually close it." + ), +) +def test_no_ownership_violation_outside_class_b() -> None: + violations = _route_ownership_violations() + assert not violations, f"{len(violations)} route-ownership violation(s):\n" + "\n".join(violations) + + +# --------------------------------------------------------------------------- +# Assertion 3 -- every relative import resolves, and no class-A/C file +# imports a class-B module (note § 4.5 point 3). Catches § 1.2(b) -- the +# carve's RULED `not_moved` row for `views/intent-feed.js` left two dangling +# imports at this leg -- as a test failure rather than a blank page. +# --------------------------------------------------------------------------- + +# Matches `import {...} from "./x.js"` (the `{...}` may span multiple source +# lines -- `views/wheel.js`:73-76 does exactly this twice -- but the +# `from "..."` clause itself is always on one line, which is all this +# pattern anchors on) and the bare side-effect form `import "./x.js";` +# (`views/viewer.js`:23's vendored markdown-it). Anchored on a RELATIVE +# specifier (`./` or `../`) immediately inside the quotes, which is what +# keeps a string built at runtime -- `"...Drafted from " + n + " document..."` +# in `views/lens.js`:802 is the one near-miss this tree actually has -- from +# being read as an import. +_IMPORT_FROM = re.compile(r'from\s*["\'](\.\.?/[^"\']+)["\']') +_IMPORT_BARE = re.compile(r'^\s*import\s*["\'](\.\.?/[^"\']+)["\']', re.MULTILINE) + + +def _relative_import_specifiers(text: str) -> list[str]: + return [m.group(1) for m in _IMPORT_FROM.finditer(text)] + [ + m.group(1) for m in _IMPORT_BARE.finditer(text) + ] + + +def _import_violations() -> list[str]: + violations = [] + for row in _ROWS: + path = row["path"] + if not path.endswith(".js"): + continue + text = (WEB_ROOT / path).read_text(encoding="utf-8") + importer_dir = (WEB_ROOT / path).parent + for specifier in _relative_import_specifiers(text): + target = (importer_dir / specifier).resolve() + try: + target_rel = target.relative_to(WEB_ROOT.resolve()).as_posix() + except ValueError: + violations.append(f"{path} -> {specifier}: resolves OUTSIDE src/opendox/web/ ({target})") + continue + if not target.is_file(): + violations.append(f"{path} -> {specifier}: UNRESOLVED (no file at {target_rel})") + continue + target_row = _ROWS_BY_PATH.get(target_rel) + if target_row is None: + violations.append( + f"{path} -> {specifier}: resolves to {target_rel}, which carries no census row" + ) + continue + if row["class"] in ("A", "C") and target_row["class"] == "B": + violations.append(f"{path} (class {row['class']}) imports {target_rel} (class B)") + return violations + + +@pytest.mark.xfail( + strict=True, + reason=( + "docs/front-end-package-boundary.md § 1.2(b) / § 4.5 point 3 " + "(opensoft/openDox-spec #8 -> a44ac06d): 7 sites today -- 2 " + "UNRESOLVED (views/dispose.js:26 and views/wheel.js:75-76 import " + "views/intent-feed.js, RULED not_moved and absent from this leg, " + "docs/opendox-carve-manifest.yaml:1807-1810 RULED OQ-F) and 5 " + "CLASS-BOUNDARY (app.js:43 -> views/gate.js, app.js:45 -> " + "views/swb-session.js, views/staging-workbench.js -> " + "views/swb-create.js and -> views/swb-session.js, " + "views/wheel.js:73-74 -> views/dispose.js -- all class A/C " + "importing class B). The note's closing paragraph assigns closure " + "to slice S2, which is the intent-feed edge only (the 2 unresolved " + "sites); the 5 class-boundary sites are the same shape S3's view " + "registry and S5's gate-loop contribution close, per § 4.1/§ 5, not " + "S2. This assertion therefore stays red after S2 alone -- flagged " + "here rather than narrowed to fit the note's own summary." + ), +) +def test_every_relative_import_resolves_and_stays_in_class() -> None: + violations = _import_violations() + assert not violations, f"{len(violations)} import violation(s):\n" + "\n".join(violations) + + +# --------------------------------------------------------------------------- +# Assertion 4 -- no class-C file, and no declared class-A tail, carries a +# governance literal (note § 2.2 rule 2, § 4.5 point 4). +# --------------------------------------------------------------------------- + +# A CLOSED word list: the eight controlled `Status:` words +# (openxFactory's `docs/document-lifecycle.md`) plus the stage vocabulary +# this tree's own funnel/wheel/board actually spell (`COLUMN_KEYS`, +# `WHEEL_KEYS`/`WHEEL_LABELS`, board.js's four columns, styles.css's +# `--st-*` tokens) -- evidenced, not guessed: every file this assertion +# scopes independently carries at least one of these words today, verified +# against openDox-code `main` `a99eba03` at S1 authoring time. +_STATUS_WORDS = ( + "brainstorm", "staged", "draft", "ratified", "standard", + "superseded", "retired", "record", +) +_STAGE_WORDS = ( + "docs", "documents", "clusters", "cluster", "possibles", "possible", + "proposals", "proposal", "realized", "changes", "active", "archived", +) +GOVERNANCE_WORDS = tuple(sorted(set(_STATUS_WORDS) | set(_STAGE_WORDS))) +_GOVERNANCE_WORD_PATTERN = re.compile( + r"\b(" + "|".join(re.escape(w) for w in GOVERNANCE_WORDS) + r")\b" +) + +# PR REVIEW FIX (opensoft/openDox-code#13, Copilot on tests/test_web_boundary.py +# :330): the sweep must not run over prose. `views/model.js`:8-9's own comment +# -- "Six-column docs-first funnel ... docs -> clusters -> possibles -> staged +# picks -> proposals -> realized" -- and `views/board.js`:1-5's "Four lifecycle +# columns -- brainstorm, staged, active proposals, realized/archived" carry six +# of the eight watched words as EXPLANATORY TEXT, not as runtime vocabulary; so +# does `styles.css`:1 ("grown verbatim from the staged mockup") among 197 `/* +# */` blocks. Left unstripped, S7 parameterizing every real literal would still +# not turn this assertion green -- the note's own words are "a governance word +# AS A LITERAL" (§ 2.2 rule 2), and a `//`/`/*`/`` +# (HTML) to spaces -- preserving every newline, so `_line_of` still lines up -- +# tracking quotes so a comment MARKER that turns up inside a real string (a +# URL, say) is left alone; none of the 17 in-scope files hit that case today +# (`grep -rn '://'` over them is empty), so no genuine literal is at risk of +# being swallowed by the tracking itself. Verified this does not silently empty +# the assertion: every one of the 17 in-scope files still carries at least one +# hit with comments excluded (1,377 raw hits across the set fall to 841 with +# comments stripped, and the per-file minimum is 3, not 0) -- so the assertion +# keeps failing today for a real, in-code reason and `strict=True` cannot XPASS +# out from under S1. +# +# NOT FIXED HERE, same footing as assertions 2/3's own "fidelity over +# tidiness" notes: a bare identifier or property access that only READS a +# snapshot schema key (`s.documents`, `s.clusters` and their kind, all over +# `model.js`/`board.js`) still trips this sweep, even though note § 2.2 rule 3 +# treats a schema key as distinct from a rendered word. Whether those sites +# need their own declared exemption (mirroring `declared_exemptions`) or a +# literal-vs-identifier-aware rewrite is left for S7 (or a further amendment) +# to decide against the real vocabulary sites it is parameterizing, rather +# than guessed at here. + + +def _strip_comments_for_scan(text: str, path: str) -> str: + """Blank out this file's COMMENT syntax -- `//`/`/* */` for `.js`, `/* */` + only for `.css` (no line-comment syntax exists), `` for `.html` -- + replacing every character except newlines with a space, so byte offsets + inside a comment never match and `_line_of` still reports the original + line for every match outside one. Quote-aware for the C-style languages + (single/double/backtick), so a `//` or `/*` that appears INSIDE a string + literal (a URL, say) is not mistaken for a comment opener; a file with no + comment syntax at all (nothing under `WEB_ROOT` today besides these three + extensions) is returned unchanged. + """ + if path.endswith(".js"): + return _strip_c_style_comments(text, allow_line_comments=True) + if path.endswith(".css"): + return _strip_c_style_comments(text, allow_line_comments=False) + if path.endswith(".html"): + return _strip_html_comments(text) + return text + + +def _strip_c_style_comments(text: str, *, allow_line_comments: bool) -> str: + out: list[str] = [] + i = 0 + n = len(text) + in_string: str | None = None # one of '"', "'", "`", or None + in_line_comment = False + in_block_comment = False + while i < n: + c = text[i] + nxt = text[i + 1] if i + 1 < n else "" + if in_line_comment: + if c == "\n": + in_line_comment = False + out.append(c) + else: + out.append(" ") + i += 1 + continue + if in_block_comment: + if c == "*" and nxt == "/": + in_block_comment = False + out.append(" ") + i += 2 + continue + out.append(c if c == "\n" else " ") + i += 1 + continue + if in_string: + out.append(c) + if c == "\\" and i + 1 < n: + out.append(nxt) # keep the escaped character verbatim too + i += 2 + continue + if c == in_string: + in_string = None + i += 1 + continue + if c in ("'", '"', "`"): + in_string = c + out.append(c) + i += 1 + continue + if allow_line_comments and c == "/" and nxt == "/": + in_line_comment = True + out.append(" ") + i += 2 + continue + if c == "/" and nxt == "*": + in_block_comment = True + out.append(" ") + i += 2 + continue + out.append(c) + i += 1 + return "".join(out) + + +def _strip_html_comments(text: str) -> str: + return re.sub( + r"", + lambda m: re.sub(r"[^\n]", " ", m.group(0)), + text, + flags=re.DOTALL, + ) + + +def _governance_literal_violations() -> list[str]: + violations = [] + for row in _assertion_4_scope(): + path = row["path"] + text = _strip_comments_for_scan( + (WEB_ROOT / path).read_text(encoding="utf-8"), path + ) + for m in _GOVERNANCE_WORD_PATTERN.finditer(text): + violations.append(f"{path}:{_line_of(text, m.start())} carries {m.group(1)!r}") + return violations + + +@pytest.mark.xfail( + strict=True, + reason=( + "docs/front-end-package-boundary.md § 2.2 rule 2 / § 4.5 point 4 " + "(opensoft/openDox-spec #8 -> a44ac06d): the 14 class-C files (13 in " + "the note's own § 3.1 count, +1 for views/explorer.js under Q2's " + "ruling) and the three declared class-A tails (views/docs.js, " + "views/grouping.js, views/repo-selector-model.js) carry the " + "registered profile's vocabulary as LITERALS -- COLUMN_KEYS, " + "WHEEL_KEYS/WHEEL_LABELS, board.js's four columns, styles.css's " + "four --st-* tokens, and more (every in-scope file trips at least " + "one hit today IN CODE, once `//`/`/* */`/`` prose comments " + "are excluded from the sweep by `_strip_comments_for_scan` -- added " + "on this PR's review, opensoft/openDox-code#13, after Copilot caught " + "the unstripped sweep counting explanatory comments too, e.g. " + "views/model.js's own \"docs -> clusters -> possibles -> staged " + "picks -> proposals -> realized\" pipeline sentence). The note " + "assigns closure to slice S7 (parameterize class C from the " + "registered domain profile). A bare identifier or property access " + "that only reads a snapshot schema key (`s.documents`, `s.clusters` " + "and their kind) still trips this sweep and is NOT excluded here -- " + "left for S7 (or a further amendment) to decide against the real " + "sites it parameterizes, the same fidelity-over-tidiness call " + "assertions 2 and 3 already make about their own scope." + ), +) +def test_no_class_c_file_carries_a_governance_literal() -> None: + violations = _governance_literal_violations() + assert not violations, ( + f"{len(violations)} governance-literal violation(s) (showing up to 20 of them):\n" + + "\n".join(violations[:20]) + ) + + +# --------------------------------------------------------------------------- +# Companion check -- the two declared exemptions are REAL and OUT OF SCOPE +# (note § 2.2 rule 3: "an exemption that is silence is how a literal +# survives a vocabulary sweep"). NOT one of the note's four numbered +# assertions; passes today and stays unmarked -- it is bookkeeping on the +# fixture, not a measurement of the boundary defect. +# --------------------------------------------------------------------------- + +def test_declared_governance_literal_exemptions_are_real_and_out_of_scope() -> None: + in_scope_paths = {row["path"] for row in _assertion_4_scope()} + for exemption in _EXEMPTIONS: + path = exemption["path"] + assert path in _ROWS_BY_PATH, f"declared exemption names an unclassified file: {path}" + assert path not in in_scope_paths, ( + f"{path} is declared exempt from the governance-literal sweep, but its " + f"census row also puts it in assertion 4's scope (class C or a declared " + f"tail) -- the exemption is CONTRADICTED, not silent, which is worse." + ) + assert exemption.get("reason"), f"declared exemption for {path} carries no reason" + text = (WEB_ROOT / path).read_text(encoding="utf-8") + assert exemption["identifier"] in text, ( + f"declared exemption names {exemption['identifier']!r}, which does not " + f"appear in {path} -- the exemption is stale" + )