diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 8d4c16a..354c040 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -47,6 +47,68 @@ jobs: # The same disclosed narrowing openDox-code carries under RULED Q-L5 # (b′). # + # THAT PARAGRAPH IS THE 2026-09-10 STATE AND IS NO LONGER THE WHOLE SCOPE + # OF THIS CHECK. Copilot's review of `399e2a9` on openXdox-code#21 was + # right that a reader who stopped there would take the required job to be + # narrower than the list at the bottom of this file actually is; the + # correction was already in the file, twenty lines further down + # ("§ 3.4 SLICE S8 UN-NARROWS THIS LIST AS FAR AS THE MEASUREMENT + # ALLOWS"), and had never been pointed at from up here. MEASURED against + # that list rather than asserted — it names FOURTEEN files: + # * THREE never import anything under test (`test_leg_shape.py`, + # `test_dependency_direction.py`, `test_no_hardcoded_status_words.py` + # parse trees with `ast`). Those are the scaffold shape assertions the + # paragraph above is about, and they are all that "only the scaffold's + # shape assertions" ever described. + # * ELEVEN import a runtime module. `test_domain_profile.py` imports + # `openxdox.domain_profile` alone, on the § 4.4 grounds set out below; + # the other TEN RUN here — and calling all ten "carved" was wrong, as + # the review of `e92fb06` said: measured against openxFactory's own two + # registers, only TWO are ARRIVED carve rows + # (`test_doxbench_abstract_store.py`, `test_doxbench_telemetry.py`, each + # with a row in `docs/opendox-carve-manifest.yaml`) and EIGHT are CREATED + # files admitted by name in `docs/opendox-carve-admissions.yaml` — the two + # gate-loop suites of § 3.4 slice S5 and the three evidence/workbench/ + # authority pairs. The distinction is not cosmetic: an ARRIVED row's edits + # are declared at openxFactory (which is why + # `test_doxbench_mutation_boundary.py` is dropped rather than repaired, + # and why the 29 importer annotations are left alone), while a CREATED + # file is this leg's to edit. Re-derive with + # `grep -c '' /docs/opendox-carve-{manifest,admissions}.yaml`. + # FOUR of the ten reach the PINNED openDox — in TWO DIFFERENT WAYS, which + # this line ran together until the review of `24cd5f2` on #21 measured + # them apart: + # - ONE reads the pinned WEB BUNDLE: `test_gate_loop_probes.py`, whose + # `_opendox_bundle()` finds the marker under the installed `opendox` + # and whose `bundle` fixture composes it. `tests/opendox_bundle.py`'s + # own `find()` / `require()` call site is driven from that file too; + # `test_gate_loop_views.py` never calls `find()`, `require()` or that + # fixture, which this bullet claimed until the review of `a0eed16`; + # - THREE import pinned openDox PYTHON MODULES: + # `test_gate_loop_views.py` takes `opendox.view_extension` through its + # own guarded helper (`_view_extension_or_skip`, which is why it + # imports `opendox_bundle` at all — for `_absent()`, the CLASSIFIER, + # not for the bundle), while `test_doxbench_abstract_store.py:43,45` + # (`from opendox import doxbench_abstract_store`, `doxbench_turns`) + # and `test_doxbench_telemetry.py:21` (`from opendox import + # doxbench_telemetry`) import at module scope with NO guard in the + # path: a regression in the pin reaches those two as an ImportError + # or a failing assertion, loudly and unclassified. + # So `tests/opendox_bundle.py::_absent` decides for TWO of the four — + # the bundle for probes, the view contract for views — and for neither + # doxbench suite. Measured over the fourteen files named below: + # grep -ln 'import opendox_bundle' -> views, probes + # grep -ln 'from opendox import' -> views, telemetry, + # abstract_store + # grep -n 'opendox_bundle\.' tests/test_gate_loop_views.py + # -> three `_absent()` calls, + # no `find`/`require` + # What Q-L8 (b′) still keeps out is the REST of the carved corpus, which + # is BUILD-blocked on `doc_health` / `ideation_dashboard` — and + # `tests/test_doxbench_mutation_boundary.py` is the one file this act + # moves from the running group into that one, for the reason recorded in + # the drop block below. + # # `tests/test_dependency_direction.py` joins it under # `split-opendox-two-layer-product` § 4.1 (RULED 5626260214, # opensoft/openxFactory#656). It is a SHAPE assertion authored HERE, of @@ -92,9 +154,17 @@ jobs: # # `--noconftest` safe and needs no consumer: it imports this package's own # modules and reads this package's own files as text. Its three - # materialization assertions SKIP — never fail — where the pinned - # `opendox` predates the view contract, which is this leg's state until - # the pin bump that lands with the openDox half. + # materialization assertions used to SKIP — never fail — because the + # pinned `opendox` predated the view contract, "which is this leg's state + # until the pin bump that lands with the openDox half". THAT BUMP HAS + # LANDED: `pyproject.toml` names `0b4e8bbf` (openDox-code#23, § 3.4 slice + # S8 leg B) since 2026-09-16, and this file goes 32 passed / 3 skipped -> + # 35 passed / 0 skipped under the invocation below. THAT PAIR IS THE + # PIN-BUMP-ONLY MEASUREMENT, at `708591b`, and it is labelled because the + # review of `a9264b8` read it as the current one: the review rounds then + # added six guard tests to this file, so under the same invocation at the + # head it is 41 passed / 0 skipped + # (`python -m pytest -q tests/test_gate_loop_views.py --noconftest`). # # `tests/test_gate_loop_probes.py` joins it on the same footing and for # the reason the slice exists: slice S4 proved its two new modules by @@ -105,10 +175,19 @@ jobs: # assertion silently breaks a verb. Each probe assembles a COMPOSED bundle # — openDox's own `web/` with this column's six modules placed into it by # `web_assets.install_view_modules()`, RULED Q5's own hook — so what is - # measured is the shipped byte in the shipped position. Where the - # installed `opendox` carries no bundle (this leg's pinned state until the - # pin bump) every probe SKIPS with that reason named, and where `node` is - # absent they skip for that one. + # measured is the shipped byte in the shipped position. This block used to + # end "where the installed `opendox` carries no bundle (this leg's pinned + # state until the pin bump) every probe SKIPS". THE SAME BUMP CLEARED IT: + # at `0b4e8bbf` the bundle is in the wheel and this file goes 0 passed / + # 13 skipped -> 13 passed / 0 skipped — again the PIN-BUMP-ONLY pair, at + # `708591b`; the rounds added thirty-seven guard tests here, so at the head + # the same invocation reads 50 passed / 0 skipped + # (`python -m pytest -q tests/test_gate_loop_probes.py --noconftest`). + # The skip survives for an assembly + # that installs a DIFFERENT openDox from the one this leg declares — the + # guard compares two commit identities and never asks git which came first, + # so "different" is all it can say — and the `node` one for a runner + # without node. # § 3.4 SLICE S8 UN-NARROWS THIS LIST AS FAR AS THE MEASUREMENT ALLOWS, # which is the half of RULED Q-L8 (b′) this slice was scoped to lift. # The note's § 5 S8 row says the narrowings "lift FOR THE WEB SUITES", and @@ -128,12 +207,15 @@ jobs: # both a pre-carve `MODULE_PATH`; the module under test is # openDox's and is read through the PIN, as the bundle now is. # tests/test_doxbench_mutation_boundary.py 1 error -> 1 skipped - # A WEB SUITE, and the one of the 23 that can be named today: it - # reads only bundle files, so with the path repaired it COLLECTS - # and skips on the stated reason (this leg's `opendox` pin predates - # openDox's `web/**` package-data declaration) instead of erroring - # on a directory that does not exist. That it collects at all is - # § 1.2(d)'s defect closed; the pin bump is what makes it run. + # A WEB SUITE, and the one of the 23 S8 could name: it reads bundle + # files, so with the path repaired it COLLECTED and skipped on the + # stated reason (this leg's `opendox` pin predated openDox's + # `web/**` package-data declaration) instead of erroring on a + # directory that does not exist. That it collects at all is + # § 1.2(d)'s defect closed. S8 then predicted "the pin bump is what + # makes it run". THE PIN BUMP MEASURED IT AND THE PREDICTION WAS + # WRONG — the block below says what actually happens, and the file + # LEAVES this list in the same act that moved the pin. # tests/test_evidence_provenance_surface.py 19 passed # tests/test_evidence_provenance_surface_seam.py 8 passed 2 skipped # tests/test_model_scenario_workbench.py 23 passed @@ -163,6 +245,139 @@ jobs: # named: it is all-skip today, on the same footing openDox-code#23 left # its two all-skip suites off ITS list. # + # ONE FILE LEAVES THIS LIST WITH THE 2026-09-16 PIN BUMP + # (`a99eba03` -> `0b4e8bbf`), and the reason is the BUILD arc's, not the + # bump's. RULED openxFactory#656 comment 5700475319 (Brett Heap, + # 2026-09-16, by interactive multi-choice): the question "drop it, keep it + # and accept a red required check, or edit the arrived file" was put to + # Brett Heap and answered (a) DROP IT, "with the measurement and both + # grounds in the workflow comment; it returns with the BUILD arc beside + # test_doxbench_turns.py" — which is what follows. + # + # `tests/test_doxbench_mutation_boundary.py` was named by S8 on + # the measurement quoted above: it COLLECTS, then skips whole at + # `tests/opendox_bundle.py`'s module-level skip, which is what happened + # while the pinned `opendox` carried no `web/` bundle. At `0b4e8bbf` the + # bundle IS in the wheel, so the module-level skip on its line 46 no + # longer fires and the module runs on to its line 481 `from openxdox + # import gate_console` -> `src/openxdox/gate_console.py:63 from + # doc_health import corpus`, the openxFactory-only package named two + # paragraphs up. Measured under this exact invocation, in a fresh venv at + # the new pin: `ERROR tests/test_doxbench_mutation_boundary.py … + # ModuleNotFoundError: No module named 'doc_health'`, a COLLECTION error + # that interrupts the whole run. + # + # It is DROPPED rather than repaired, for the reason + # `tests/test_doxbench_turns.py` is not named at all: naming it would put + # the required check red for the BUILD arc's defect (split-opendox + # § 3.5/3.6, RULED Q-L8 (b′)), and the file is an ARRIVED carve row whose + # edits are declared at openxFactory — deferring its `gate_console` import + # would be an undeclared edit to a declared surface. It comes back to this + # list with the BUILD arc, in the act that makes `doc_health` reachable, + # alongside `test_doxbench_turns.py`. + # + # WITH IT GONE AND THE PIN MOVED, this invocation goes 301 passed / + # 23 skipped -> 360 passed / 6 skipped, and BOTH HALVES OF THAT DELTA HAVE + # TO BE SAID SEPARATELY, because Copilot's round-3 review of #21 caught this + # block conflating them: + # + # * SIXTEEN skips became PASSES — the 3 materialization assertions in + # `tests/test_gate_loop_views.py` and the 13 node probes in + # `tests/test_gate_loop_probes.py`. That is the pin bump's own effect, + # and it is the whole point of the act. + # * The seventeenth skip did NOT clear. It was + # `tests/test_doxbench_mutation_boundary.py`'s module-level skip, and at + # the new pin it becomes a COLLECTION ERROR (see the block above); the + # file leaves this list, so that skip is no longer RUN rather than + # cleared. Counting it as cleared would describe a transition that never + # happened. + # * The remaining rise to 360 is NOT the bump: it is the 43 direct tests + # of the provenance guard that Copilot's review rounds asked for, which + # live in `tests/test_gate_loop_probes.py` and + # `tests/test_gate_loop_views.py` and are therefore both on this list. + # The bump alone measured 317. Both counts are re-derived at every head + # rather than carried: + # git diff main -- tests/test_gate_loop_probes.py \ + # tests/test_gate_loop_views.py | grep -c '^+def test_' + # gives 43, and the passing figure has run 317 -> 323 -> 330 -> 332 -> + # 333 -> 334 -> 336 -> 343 -> 346 -> 348 -> 349 -> 351 -> 353 -> 355 -> + # 356 -> 357 -> 359 -> 360, once per round that added tests — the + # same discipline the block above applies to the skip counts. The review + # of `8b23f6f` asked for the CALL SITES: the tests before it proved what + # the guard decides and what it reads, and none of them proved that the + # three callers still route a missing subject into it, so swapping any + # one call for a bare `pytest.skip` would have left every required test + # green. The review of `24cd5f2` took the last three: the CI branch's + # message had to name WHICH side it could not read (two cases — an + # unreadable `pyproject.toml` beside a good `direct_url.json`, and + # neither side readable), and `_view_extension_or_skip()` had to survive + # a `view_extension` module that carries no `ViewBinding` class, which + # until then left this guard through an `AttributeError`. The review of + # `cb84001` took the two after that: BOTH new caller branches had only + # their declared-pin FAIL driven, so making either an unconditional + # failure would have passed every added test while breaking the consumer + # RULED 5700475319 protects — the assembly that pins an openDox behind + # the view contract. Each is now driven at a DIFFERENT commit too. The + # review of `a0eed16` took the last one, in the PARSER: both fakes for + # `importlib.metadata.distribution` answered to ANY name, so a regression + # to `distribution("openxdox")` would have read a stranger's PEP 610 + # record and compared ITS commit against this leg's declared pin with all + # ten parser tests green. Both fakes assert the name now, and one test + # asserts the lookup itself. The review of `de7d966` took the branch under + # THAT one: `declared_pin()`'s regex MISS — a readable `pyproject.toml` + # that declares no `opendox @ git+…@<40-hex>` — had no test at all, so a + # dependency line rewritten to a branch ref or a version range would have + # returned None with nothing proving the fail-closed policy still catches + # it. Two tests: the function returns None, and `_absent()` FAILS under CI + # naming the declared side while still printing the installed commit. The + # review of `8b9ece1` then found the PARSER bug with the widest blast + # radius on this PR: `_PIN_RE` had no delimiter after `{40}`, so a ref that + # merely BEGAN with forty hex characters (`…@<40-hex>dead`) yielded that + # prefix as the declared commit — and the guard would compare a commit this + # leg does NOT declare against what is installed, failing on the wrong + # culprit or skipping over a real regression. A trailing negative + # lookahead over alphanumerics made a continuing ref read as NO pin — + # THE EXPRESSION IS NOT REPRODUCED HERE, at the request of the review of + # `a9264b8`, because a rejected pattern written out in a workflow is a + # pattern somebody copies back; it was still a TEXT SEARCH, + # and the next two rounds walked the same class of hole out of it: a + # positive terminator set still admitted `,` and `'` INSIDE the quoted PEP + # 508 URL, and a search over raw text could read a sha out of a + # COMMENTED-OUT dependency line. `declared_pin()` PARSES the file with + # `tomllib` now and `fullmatch`es the dependency VALUE, so a pin is read + # only when the entire declared requirement is + # `opendox @ git+@<40-hex>` — and a comment is not in + # `project.dependencies` at all. Eleven continuations are refused in one + # test — eleven continuations against BOTH url shapes — and NINE + # legitimate declarations are still read in another (plain HTTPS · with + # extras · an SSH url whose AUTHORITY carries an `@` · a `;` path + # parameter · a `.git` suffix · a true environment marker · `OpenDox` + # spelled in mixed case, names being case-insensitive per PEP 503 · + # a `#subdirectory=src` fragment · an `#egg=…&subdirectory=…` one — + # the two the review of `e92fb06` added, which this inventory still + # counted as seven until the review of `9ab8521` measured it), + # because a guard too strict to read a correct file fails closed just as + # silently. A FALSE marker is the one conditional + # that must NOT read as a pin — pip installs nothing from that line — and + # it is driven beside a true one and an unevaluable one. The reviews of + # `52453af` and `18e8c12` found each of those in turn. The review of + # `0e3922d` ended the arc by taking the splitting away from this code + # altogether: `packaging.requirements` settles the name, the extras, the + # url and where the marker starts — a `;` is legal in a url path, and + # hand-splitting on it truncated a declaration pip installs — and the + # SOURCE is checked, because comparing shas alone let a dependency + # re-pointed at a different PROJECT read as the lawful "different commit" + # skip while this leg was no longer testing openDox-code at all. The + # review of `9ab8521` closed the OTHER HALF of that: the check sat on the + # DECLARED url only, so an `opendox` INSTALLED from an unrelated + # repository still reached that skip — `installed_commit()` reads + # `direct_url.json`'s `url` as well as its `commit_id` now, a fork or a + # mirror of openDox-code passing (RULED 5700475319) and a different + # project failing closed.) + # + # The 6 skips that remain are the three seam suites' `doc_health` pairs, + # which no pin bump touches. + # # `--noconftest` STAYS, and it is why this list is a list: `tests/ # conftest.py` imports the carved session fixtures, which reach both # absent packages. Every file named here stands on its own under it. @@ -176,7 +391,6 @@ jobs: tests/test_gate_loop_views.py tests/test_gate_loop_probes.py tests/test_doxbench_abstract_store.py - tests/test_doxbench_mutation_boundary.py tests/test_doxbench_telemetry.py tests/test_evidence_provenance_surface.py tests/test_evidence_provenance_surface_seam.py diff --git a/pyproject.toml b/pyproject.toml index 38331a7..8141dd7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,7 +103,7 @@ requires-python = ">=3.12" # PR) — and not an arbitrary choice: `Draft202012Validator`, the name # `gate_console.py:563` imports, was added in jsonschema 4.18.0. dependencies = [ - "opendox @ git+https://github.com/opensoft/openDox-code@a99eba03e31a0aee1cc15a061fdf718cc88a2c44", + "opendox @ git+https://github.com/opensoft/openDox-code@0b4e8bbf68fabfcd65d4f0d80e619c20a013e888", "PyYAML>=6.0", "jsonschema>=4.18", ] diff --git a/src/openxdox/view_extensions.py b/src/openxdox/view_extensions.py index 46f4d69..55d63ac 100644 --- a/src/openxdox/view_extensions.py +++ b/src/openxdox/view_extensions.py @@ -19,12 +19,33 @@ repository that PINS openDox conforms without inheriting from it. WHY THE BINDINGS ARE DECLARED AS DATA AND MATERIALIZED LATE. This leg pins -`opendox` by commit (`pyproject.toml`), and the pinned commit is older than the -view registry itself — `opendox.view_extension` does not exist there, and the -`exports` field RULED Q2 adds is newer still, landing in openDox-code's own S5 -leg. Importing either at module-import time would make this module unimportable -under its own declared dependency and would put this leg's `validate` red for a -reason that has nothing to do with this column. So `VIEW_BINDING_SPECS` below is +`opendox` by commit (`pyproject.toml`). Until 2026-09-16 that pin named +`a99eba03` and this paragraph said the pinned commit "is older than the view +registry itself — `opendox.view_extension` does not exist there, and the +`exports` field RULED Q2 adds is newer still". THAT IS NO LONGER TRUE, and the +old wording is quoted here as provenance rather than deleted: the pin now names +openDox-code#23 (`0b4e8bbf`, § 3.4 slice S8 leg B), where `view_extension` is +importable and `ViewBinding` takes `exports` — measured, and the three +materialization assertions in `tests/test_gate_loop_views.py` run and pass +against it instead of skipping. + +THE LATENESS STAYS, for the reason that outlives any one pin: an ASSEMBLY +chooses the `opendox` this module runs under, not this file, and a consumer +that pins an openDox behind the view contract must still be able to IMPORT this +module — an import-time reach would make it unimportable under THAT consumer's +pin and would put its `validate` red for a reason that has nothing to do with +this column. `ViewContractUnsupported` below is what names that condition where +`GateLoopViews.views()` CATCHES it, and that is two shapes, not three: the +`view_extension` module absent (ImportError) and a `ViewBinding` that does not +take this column's fields (TypeError). A module that carries no `ViewBinding` at +all still raises `AttributeError` at the constructor below — the class docstring +names that assembly as unsupported, and the runtime does not yet classify it. +The TEST-time guard does (`tests/test_gate_loop_views.py::_view_extension_or_skip`, +which reads the class with `getattr` and hands the shape to +`tests/opendox_bundle.py::_absent`); the runtime catch is registered in this pull +request's "What this does NOT do" rather than smuggled into a pin bump. Caught at +the review of `e6cd0e8` on openXdox-code#21, which was right that these lines +promised more than the code below does. So `VIEW_BINDING_SPECS` below is plain data — the same JSON shape the manifest crosses the process boundary as — and `GateLoopViews.views()` materializes it through whatever `opendox` the ASSEMBLY installed, at the one moment an assembly exists to have installed one. diff --git a/tests/opendox_bundle.py b/tests/opendox_bundle.py index 3d0b2f8..e170d42 100644 --- a/tests/opendox_bundle.py +++ b/tests/opendox_bundle.py @@ -10,9 +10,20 @@ openXdox-code [name a `views/.js` path], and every one of them resolves it under `REPO_ROOT / "src" / "openxdox" / "web"` — a directory openXdox-code does not have … the carve's `import rewrites` edit class rewrote the path constant and -pointed the tests at the wrong leg."* Eight further suites at this leg name the -same constant as a SERVE ROOT without naming a view module, so the real count is -31 files and 47 sites. +pointed the tests at the wrong leg."* Further suites at this leg name the same +constant as a SERVE ROOT without naming a view module, and the total is the one +**openXdox-code#19's LANDING re-derived** (`main 0a0265f`, "RE-DERIVED AT LANDING, +AND ONLY THE COUNT MOVED"): under a named, re-runnable instrument — a ROOT SPELLING +is a line spelling `REPO_ROOT / "src" / "openxdox" / "web"` in any Path or slash +form, counted over the REVISIONS with `git grep` and never a worktree — **46 root +spellings over 31 files**, as 22 resolving a concrete `views/.js` module plus +9 using the root as a serve root (the ninth being the tool at +`tests/tools/playwright-smoke.py`, outside `validate`'s list). `validate.yml`'s S8 +block carries that same 46. The review rounds on #19 said "31 files, 47 sites"; +that figure is left ATTRIBUTED and not restated, for #19's own reason — a root +spelled once carries several derived sites, so neither total corrects the other — +and this line asserted it as "the real count" until the review of `de7d966` on #21 +found the two numbers disagreeing across this repository. The note's § 5 S8 row then infers that those files *"go to the leg the census says owns each bundle file"*. **That inference does not hold, and the reason is @@ -35,19 +46,75 @@ web = Path(opendox.__file__).resolve().parent / "web" and S5 leg B (`openDox-code#20`) landed the packaging declaration that puts -`opendox/web/**` into a wheel at all. Until this leg's pin advances past that -commit, an installed `opendox` carries no bundle — so a module that imports this -one SKIPS, exactly as S5's probes do, rather than failing on a stand-in. A -skipped suite says "the pin is behind"; a failing one would say "the code is -wrong", and only one of those is true. +`opendox/web/**` into a wheel at all. THIS LEG'S PIN HAS NOW ADVANCED PAST IT — +2026-09-16, `a99eba03` -> `0b4e8bbf` (openDox-code#23, § 3.4 slice S8 leg B) — +and the bundle is there: `find()` returns a real directory under the installed +`opendox`, so the OLD missing-bundle skip no longer fires for the suites that +import `OPENDOX_WEB`. It does not follow that all of them now RUN, and the review +of `52453af` was right to catch the blanket claim: `test_doxbench_mutation_ +boundary.py` imports `OPENDOX_WEB` too, and with that skip gone it runs on to +`from openxdox import gate_console` -> `doc_health`, a COLLECTION ERROR. That is +the BUILD arc's defect, not this bump's, and it is precisely why RULED +openxFactory#656 comment 5700475319 drops that file from `validate.yml`'s list. +This paragraph used to end "Until this leg's pin advances past that commit, an +installed `opendox` carries no bundle", which was true of `a99eba03` and is +quoted here as provenance, not as a claim. + +A SKIP STAYS FOR TWO CASES AND TWO ONLY — and THAT IT STAYS AT ALL is ruled, not +chosen here. RULED openxFactory#656 comment 5700475319 (Brett Heap, 2026-09-16, +by interactive multi-choice): asked whether to keep these guards with corrected +reasons or delete them on pin lockstep #2's precedent, Brett Heap answered +(a) KEEP THEM and correct the reasons, "they test the ASSEMBLED openDox; a +consumer may pin behind the view contract". + +This paragraph overstated the skip until the review of `7c0a3b6` on +openXdox-code#21. A missing bundle is honest to skip +where the installed distribution records a commit that is NOT the one this leg +declares — note the claim is "different", never "older": nothing here proves an +ordering, only a disagreement — and where the installation records no provenance +at all AND the run is off CI. Everywhere else `_absent()` fails closed, the +declared pin included, and under CI unrecorded provenance included. + +FOUR OUTCOMES, NOT THREE. Two review rounds on #21 caught this paragraph running +them together: at `27a89fd` it had one sentence for both SKIPS, and at `f6f1b991` +the sentence below still said every FAILURE means "the openDox we declare is +wrong", which is true of one of the two failures and a misdiagnosis of the other. +`_absent()`'s docstring holds the canonical table; these are the four things it +says, and they are four different claims: + + * DIFFERENT commits -> SKIP, saying "this is not the openDox we declare" and + naming both commits to prove it; + * an unreadable side, OFF CI -> SKIP, saying only "the comparison could not be + made". It claims nothing about what is installed, and it exists because off + the required path an unreadable side is lawful; + * EQUAL commits -> FAIL, saying "the openDox we declare is wrong". This is the + only outcome that is an assertion about the package; + * an unreadable side, UNDER CI -> FAIL, naming WHICH side could not be read + and saying the two commits could not be COMPARED. It does NOT say "this run + cannot say which openDox is installed": where `pyproject.toml` is the + unreadable side the installed commit is in hand and gets printed, so that + claim was false for one of the two shapes this row covers — caught at the + review of `24cd5f2` on #21. It is a COMPARISON anomaly, not proof of a bad + package: `validate.yml` installs `-e ".[test]"` against a PEP 508 direct VCS + reference and pip records `direct_url.json` for that every time, so a + required run that cannot read one side has lost the ability to check, which + is itself worth stopping for. + +The guard's whole job is to keep those four apart instead of answering "skip" to +all of them. """ from __future__ import annotations import atexit +import json +import os +import re import shutil import tempfile +import tomllib from pathlib import Path +from typing import NoReturn import pytest @@ -56,18 +123,29 @@ #: one of the six modules openXdox itself contributes back under RULED Q5. _MARKER = ("views", "helpers.js") -_REASON = ( - "the installed `opendox` carries no `web/` bundle: this leg pins a commit " - "older than openDox's own packaging declaration (`[tool.setuptools." - "package-data] opendox = [\"web/**\"]`, openDox-code#20, § 3.4 slice S5), " - "so there is nothing here to read. The pin bump makes this suite run — the " - "same bump `tests/test_gate_loop_probes.py` and `tests/test_gate_loop_" - "views.py` already wait on. SKIPPED, never failed: the code under test is " - "not what is missing.") +# `_REASON`, the module-level skip string, is GONE — `_absent()` below composes the +# reason from what it measured instead of stating it in advance. It read "this leg +# pins a commit older than openDox's own packaging declaration … The pin bump makes +# this suite run", which was true of `a99eba03` and became false at `0b4e8bbf`; the +# replacement's whole point is that it cannot go stale, because every reason is +# composed from what the run just read. In the DIFFERENT-COMMIT outcome that is the +# two commits, named; where a side is unreadable there is no comparison to name, and +# the reason says WHICH side could not be read instead. (The review of `e6cd0e8` +# caught this comment claiming the two commits for all four rows.) def find() -> Path | None: - """The installed openDox's `web/` bundle, or None where the pin carries none.""" + """The installed openDox's `web/` bundle, or None where no bundle was found. + + DISCOVERY ONLY: this function tests for the marker and says nothing about + WHY it is absent. `None` used to be documented as "the pin carries none", + which was the single expected cause before the bump and is now one of four + (a regression at the declared pin, a consumer at a different commit, or + either side unreadable). Classifying it is `_absent()`'s job and its table + is not restated here — a caller that read the old line could have concluded + "stale pin, skip" and walked straight past the identity check. Caught at the + review of `399e2a9` on openXdox-code#21. + """ try: import opendox except ModuleNotFoundError: # pragma: no cover - no consumer pinned @@ -76,17 +154,423 @@ def find() -> Path | None: return web if web.joinpath(*_MARKER).is_file() else None + +# --------------------------------------------------------------------------- +# PROVENANCE — WHICH openDox IS ACTUALLY INSTALLED, and why the skip must ask. +# +# Copilot's round-1 review of openXdox-code#21 (suppressed comment on this file, +# and the same finding twice more on `tests/test_gate_loop_probes.py` and +# `tests/test_gate_loop_views.py`) was ACCURATE and is answered here rather than +# argued: `find()` tests for a MARKER, never for an identity, so a skip reason +# that says "the installed `opendox` came from somewhere older than the declared +# pin" was asserting something it had not measured. Before the pin bump that cost +# nothing — a missing bundle WAS the declared state. After it the same skip would +# hide the opposite fact: if the declared pin itself ever stopped shipping +# `web/**`, thirteen node probes, three materialization assertions and every +# bundle suite would go quietly green in a REQUIRED check, and the coverage this +# bump exists to gain would be lost in silence. +# +# So the two facts are now READ, and the skip is conditional on them: +# * `declared_pin()` — the 40-hex this leg's own `pyproject.toml` declares. +# * `installed_commit()` — the commit pip actually built, out of the +# distribution's `direct_url.json` (PEP 610), which a VCS install always +# records. +# Bundle missing AND the two agree -> FAIL: a regression at the declared pin. +# Bundle missing AND they differ -> SKIP: a consumer assembling at a +# DIFFERENT commit, both named in the +# reason. DIFFERENT, never "older": this +# guard compares two identities and never +# asks git which came first. +# Provenance unreadable, UNDER CI -> FAIL. Round 2 of the same review was right +# that skipping here left the required job +# able to go green with the bundle missing; +# on the required path an unreadable +# provenance is itself the anomaly, because +# `validate.yml` installs a PEP 508 direct +# VCS reference and pip records one every +# time. +# Provenance unreadable, OFF CI -> SKIP, saying so: an editable checkout or a +# hand-placed wheel lawfully has none, and +# nothing measured means nothing claimed. +# --------------------------------------------------------------------------- + +#: A git object name, matched CASE-INSENSITIVELY and normalized to lowercase +#: below. Copilot asked for the normalization on openXdox-code#21, and it can +#: only ever turn an "unknown" into a real comparison: a lawful record that +#: happens to spell its commit in upper case would otherwise read as +#: unreadable provenance and FAIL under CI for a formatting difference. +_SHA_RE = re.compile(r"[0-9a-fA-F]{40}") + +#: THE PIN IS READ OUT OF THE PARSED DEPENDENCY LIST, NOT OUT OF THE FILE TEXT, +#: and that is where four review rounds drove it. The text-search version had a +#: new hole every round, each one the same class — a 40-hex PREFIX read as a pin: +#: `8b9ece1` no terminator at all (`…@dead`); +#: `2dfd669` `(?![0-9a-zA-Z])`, which still let `-feature`, `/branch`, +#: `_suffix` and `.1` through, all legal git refs; +#: `a9264b8` a positive terminator set, which still let `,` and `'` through +#: INSIDE the quoted PEP 508 URL, where both are ref continuations; +#: and, independently of any terminator, a search over the raw text could read +#: the sha out of a COMMENTED-OUT old dependency line and compare against a pin +#: this file no longer declares. +#: Refusing ref characters one class at a time is a losing game — git allows +#: nearly everything a URL does. `tomllib` ends it: the dependency VALUE is a +#: string the parser hands over whole, so `fullmatch` against it admits a pin only +#: when the ENTIRE declared requirement is `opendox @ git+@<40-hex>`, and a +#: comment is not in `project.dependencies` at all. Copilot's finding at `a9264b8`. +#: The optional-dependency tables are NOT searched: a test extra is not what this +#: leg is built against, and `validate.yml` installs `.[test]` against this list. +#: THE URL PART IS `\S+`, NOT `[^@\s]+`, and that is the review of `52453af`: +#: a PEP 508 SSH declaration carries an `@` in the AUTHORITY — +#: `opendox @ git+ssh://git@github.com/opensoft/openDox-code@<40-hex>` — so +#: stopping at the first `@` read no pin out of a declaration pip installs +#: happily, and the guard would have failed closed under CI on a correct file. +#: Greedy `\S+` under `fullmatch` backtracks to the LAST `@` that leaves forty hex +#: and nothing after them, which is the pin by construction. +#: The pin inside a direct-reference URL. The NAME, the extras and the marker are +#: the PEP 508 parser's business now (review of `0e3922d`); what is left here is +#: "this URL ends in `@<40-hex>` and nothing else", which is what refuses a ref +#: that merely BEGINS with forty hex characters. `\S+` rather than `[^@\s]+` +#: because an SSH url carries an `@` in its authority (review of `18e8c12`), and +#: greedy backtracking under `fullmatch` lands on the LAST such `@`. +_URL_PIN_RE = re.compile(r"git\+\S+@([0-9a-fA-F]{40})") + +#: pip's direct-reference FRAGMENT: `#subdirectory=src`, `#egg=opendox`, joined by +#: `&`. It is legal after the pin and says nothing about which commit is declared, +#: so it is stripped before matching — the review of `e92fb06` caught +#: `…@#subdirectory=src` reading as NO pin and failing the guard closed on a +#: declaration pip installs. Only a `key=value` fragment is stripped: a bare +#: `#feature` is a ref continuation, not a fragment, and must still refuse. +_FRAGMENT_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_.-]*=[^&]*(?:&[A-Za-z_][A-Za-z0-9_.-]*=[^&]*)*") + + +def _without_fragment(url: str) -> str: + """`url` with a pip direct-reference fragment removed, if it has one.""" + head, sep, fragment = url.partition("#") + if sep and _FRAGMENT_RE.fullmatch(fragment): + return head + return url + +#: The repository this leg is entitled to reason about. `installed_commit()` +#: compares SHAS ONLY, so a declaration re-pointed at another repository at some +#: other 40-hex commit would have made a missing bundle look like the lawful +#: "different commit" case and SKIP under CI — while this leg was no longer +#: testing openDox-code at all. Copilot's thread on `0e3922d`. A pin at another +#: repository is not a declaration this guard can interpret, so it reads as NO +#: pin, which is the fail-closed path under CI rather than a silent skip. +#: The `;…` tail is RFC 3986 path parameters, legal in a VCS url and the very +#: shape the review of `0e3922d` named (`…/repo;component@`); it belongs to +#: the path, not to the repository's name, so it is allowed and ignored here. +_OPENDOX_CODE_RE = re.compile(r".*/opendox-code(?:\.git)?(?:;[^/]*)?$") + + +def _names_opendox_code(url: str) -> bool: + """Whether a direct-reference URL names `opensoft/openDox-code`. + + Compared on the repository PATH and case-insensitively (the estate spells it + `openDox-code`, `opendox-code` and `OpenDox-code` in different places), with + the `git+` scheme prefix, any `@` suffix and a trailing `.git` stripped + first. A fork or mirror under another account still passes — what this refuses + is a DIFFERENT PROJECT, which is the case the thread on `0e3922d` names. + + IT READS BOTH SIDES' URLS, and that is why the `@` suffix is stripped + POSITIONALLY rather than at the last `@`: a DECLARED url carries the ref + (`…/openDox-code@<40-hex>`) and an INSTALLED one never does — PEP 610 keeps it + in `vcs_info.requested_revision` — so `rsplit("@", 1)` cut a perfectly ordinary + `ssh://git@github.com/opensoft/openDox-code` down to `ssh://git` and read a + correct install as a different project. A ref can only follow the final `/`; + an authority's `@` cannot. Copilot's thread on `9ab8521`. + """ + without_scheme = url[len("git+"):] if url.startswith("git+") else url + last_segment = without_scheme.rsplit("/", 1)[-1] + repository = (without_scheme.rsplit("@", 1)[0] + if "@" in last_segment else without_scheme) + return bool(_OPENDOX_CODE_RE.fullmatch(repository.rstrip("/").lower())) + + +def _marker_holds(text: str) -> bool: + """Whether a PEP 508 environment marker is TRUE for this interpreter. + + A conditional requirement is only a declaration where its marker holds: with + `; python_version < "3.0"` pip installs nothing, so treating the sha as "the + commit this leg declares" would compare an unrelated installed `opendox` + against a pin that is not active and take the different-commit SKIP — over a + real regression. Copilot's review of `18e8c12`. + + UNEVALUABLE IS FALSE, deliberately: a marker this environment cannot judge is + not a declaration this run can rely on, and everything that returns None here + lands on `_absent()`'s fail-closed path under CI rather than on a skip. + """ + try: + from packaging.markers import Marker + except ModuleNotFoundError: # pragma: no cover - ships with pytest + return False + try: + return bool(Marker(text).evaluate()) + except Exception: + return False + + +def declared_pin() -> str | None: + """The openDox-code commit this leg's `project.dependencies` pins `opendox` to. + + None where there is NO SUCH PIN TO READ, which is SIX states and not one — the + docstring said "if unreadable" until the review of `a9264b8` pointed out that + the caller cannot tell them apart from that word: the file is unreadable, it is + not valid TOML, it declares no `opendox` requirement, the requirement it + declares is not a 40-hex direct VCS pin (a branch ref, a version range, a path + install), its environment marker does not hold on this interpreter (review of + `18e8c12`), or it points at a DIFFERENT PROJECT than openDox-code (the thread + on `0e3922d`). `_absent()` treats all six the same — fail-closed under CI — and + that is the point: NONE of them tells this run which openDox it declares. + + THE REQUIREMENT IS PARSED, never split by hand: `packaging.requirements` + settles the name (case-insensitively, PEP 503), the extras, the url and where + the marker starts, because every hand-rolled version of that split lost a legal + declaration shape — an `@` in an SSH authority, a `;` in a url path — or + admitted an illegal one, once per review round. + """ + toml = Path(__file__).resolve().parents[1] / "pyproject.toml" + try: + parsed = tomllib.loads(toml.read_text(encoding="utf-8")) + except (OSError, UnicodeDecodeError, tomllib.TOMLDecodeError): + # UnicodeDecodeError is a ValueError, NOT an OSError, so a non-UTF-8 + # `pyproject.toml` would have escaped this function and bypassed + # `_absent()`'s explicit unknown-provenance policy altogether. Caught at + # the review of `27a89fd` on openXdox-code#21. The `# pragma: no cover` + # that sat on this line is GONE rather than kept: the review of + # `f6f1b991` asked for a test that makes the read fail, and BOTH raising + # types are now driven by + # `tests/test_gate_loop_probes.py::test_declared_pin_is_none_when_*`, so + # the pragma had become a false claim about the branch it labelled. + # `TOMLDecodeError` joined them at `a9264b8`'s review, when the read became + # a PARSE: a `pyproject.toml` that does not parse declares nothing, and the + # guard must fail closed on it exactly as it does on an unreadable one. + return None + project = parsed.get("project") + dependencies = project.get("dependencies") if isinstance(project, dict) else None + if not isinstance(dependencies, list): + return None + try: + from packaging.requirements import InvalidRequirement, Requirement + except ModuleNotFoundError: # pragma: no cover - ships with pytest + return None + for entry in dependencies: + if not isinstance(entry, str): + continue + # THE PEP 508 PARSER SPLITS THIS, not `partition(";")`. A semicolon is a + # legal URI character, so `git+https://host/repo;component@` was + # truncated at it and read as NO pin — the guard failing closed on a + # declaration pip installs. Copilot's review of `0e3922d`; the parser knows + # where the marker starts and this function no longer guesses. + try: + requirement = Requirement(entry) + except InvalidRequirement: + continue + if requirement.name.lower() != "opendox" or not requirement.url: + continue + # A marker that does not hold means pip installs nothing from this line, so + # the sha on it is not "the commit this leg declares" (review of `18e8c12`). + if requirement.marker is not None and not _marker_holds(str(requirement.marker)): + continue + url = _without_fragment(requirement.url) + match = _URL_PIN_RE.fullmatch(url) + if match and _names_opendox_code(url): + return match.group(1).lower() + return None + + +def installed_commit() -> str | None: + """The commit the INSTALLED `opendox` was built from (PEP 610), or None. + + None means NO USABLE PROVENANCE WAS READ — which is broader than "none was + recorded", and saying only the narrow thing made this contract inaccurate + (caught at the review of `27a89fd` on #21). It covers: no `direct_url.json`, + malformed JSON, an `archive_info` (non-VCS) install, a record whose `vcs` is + not git, a `commit_id` that is not 40 hex, a record whose `url` names a + PROJECT other than openDox-code (Copilot's thread on `9ab8521`), the + distribution lookup raising, and the read raising. Every one of those has its + own test below. + + WHAT THE CALLER DOES WITH None IS NOT "always skip", and this docstring said + so until Copilot's round-3 review of #21 caught it: `_absent()` FAILS on None + under CI and SKIPS off it. The rule is the required path, not the value — + see `_absent()`'s own table. A future caller that reads only this line would + otherwise bypass the safety rule the required check depends on. + """ + try: + from importlib.metadata import distribution + raw = distribution("opendox").read_text("direct_url.json") + except Exception: + # Driven by `test_installed_commit_is_none_when_the_package_is_not_installed` + # (the LOOKUP raises) and `…_when_reading_the_record_raises` (the read does). + return None + if not raw: + return None + try: + record = json.loads(raw) + vcs_info = record.get("vcs_info") or {} + source = record.get("url") + vcs, commit = vcs_info.get("vcs"), vcs_info.get("commit_id") + except (ValueError, AttributeError): + # Driven by `test_installed_commit_is_none_on_malformed_json`. + return None + # BOTH CHECKS ARE LOAD-BEARING, and the second is Copilot's finding at the + # head before this one: `len(commit) == 40` admitted any forty CHARACTERS, so + # a malformed record carrying a forty-character non-hex id read as "a + # different pin" and `_absent()` SKIPPED under CI — the silent green this + # whole guard exists to prevent, reached through the parser instead of + # through the decision. A commit id is 40 lowercase hex and the record must + # say it is git, or this function does not know what is installed. + if vcs != "git" or not isinstance(commit, str): + return None + # THE SOURCE IS THE OTHER HALF OF THE PROVENANCE, and this function read only + # the commit until Copilot's thread on `9ab8521`: a distribution NAMED + # `opendox` but built from an unrelated repository at its own 40-hex commit + # was handed to `_absent()` as the lawful DIFFERENT-COMMIT case and SKIPPED + # the required suite — while nothing installed here came from openDox-code at + # all. `declared_pin()` got exactly this check at `9ff630d`, on the side that + # is DECLARED; this is the same check on the side that is IMPORTED, and + # half a provenance check is the silent green the other half exists to stop. + # A FORK or a MIRROR still reads (RULED openxFactory#656 comment 5700475319 — + # a consumer may pin an openDox of its own choosing); what is refused is a + # different PROJECT, and it lands on the fail-closed path under CI. + if not isinstance(source, str) or not _names_opendox_code(_without_fragment(source)): + return None + return commit.lower() if _SHA_RE.fullmatch(commit) else None + + +def under_ci() -> bool: + """True on the REQUIRED path — GitHub Actions sets `CI=true` on every runner.""" + return os.environ.get("CI", "").strip().lower() in {"1", "true", "yes"} + + +def _unreadable_side(declared: str | None, installed: str | None) -> str: + """WHICH side of the comparison could not be read — never "which openDox is + installed", because two of these three shapes have a commit in hand. + + Copilot's review of `24cd5f2` on #21 caught the CI branch saying "this run + cannot say which `opendox` is installed" while the very next field printed the + installed hash: when `pyproject.toml` is the unreadable side, the provenance is + known and it is the COMPARISON that cannot be made. Both branches compose their + phrase here now, so the two can no longer drift apart — which is how the off-CI + branch came to name the side (review of `27a89fd`) while the CI branch did not. + """ + if declared is None and installed is None: + return ("NEITHER side is usable: this leg's declared pin could not be read " + "from `pyproject.toml` (see `declared_pin()` for the six states " + "that reach this) and the installed distribution records no PEP 610 " + "provenance this guard can use") + if declared is None: + # NOT "the file could not be read": `declared_pin()` returns None for six + # states and only two of them are a failed READ (the review of `9ff630d` + # caught this phrase blaming the file for the other four — an inactive + # marker, no `opendox` requirement, a requirement that is not a 40-hex VCS + # pin, or a pin at another project, every one of them a perfectly readable + # `pyproject.toml`). The sentence says what IS true of all six. + return ("this leg's declared pin could not be read from `pyproject.toml` " + "— the file is unreadable or unparseable, declares no `opendox` " + "requirement, declares one that is not a 40-hex direct VCS pin at " + "openDox-code, or carries an environment marker that does not hold " + "here (`declared_pin()` lists the six)") + return ("no usable PEP 610 provenance could be read from the installed " + "distribution — it records none, it records one this guard cannot " + "read, or it records one built from a PROJECT other than openDox-code " + "(`installed_commit()` lists the states)") + + +def _absent(subject: str, *, module_level: bool) -> NoReturn: + """Raise the RIGHT outcome for a missing `subject`. + + | installed vs declared | outcome | + | --- | --- | + | equal | FAIL — a regression at the pin this leg declares | + | different | SKIP — a consumer assembling at a DIFFERENT commit (identity, never ancestry) | + | UNKNOWN, under CI | FAIL — see below | + | UNKNOWN, off CI | SKIP — a developer box may install however it likes | + + THE "UNKNOWN, UNDER CI" ROW IS COPILOT ROUND 2's FINDING, and it was right: + skipping on unknown provenance left the required `validate` job able to go + green with the bundle missing, which is the exact silence this guard exists to + break. On the required path unknown provenance is not a neutral state — + `validate.yml` installs with `pip install -e ".[test]"` against a PEP 508 + direct VCS reference, and pip records `direct_url.json` for that every time — + so failing to read one there is itself the anomaly. Off CI the permissive + branch stays, because an editable checkout or a hand-placed wheel is a lawful + way to work and has no provenance to record. + """ + declared, installed = declared_pin(), installed_commit() + if declared is not None and installed is not None and declared == installed: + pytest.fail( + f"{subject} is missing from the `opendox` this leg DECLARES " + f"(`pyproject.toml` pins {declared[:8]}, and the installed " + f"distribution records that same commit in its `direct_url.json`). " + f"That is a REGRESSION at the declared pin, not a stale consumer, so " + f"it fails here instead of skipping: a skip would take every suite " + f"that depends on {subject} quietly green in a required check.") + if declared is None or installed is None: + unreadable = _unreadable_side(declared, installed) + if under_ci(): + pytest.fail( + f"{subject} is missing and the two commits could not be COMPARED: " + f"{unreadable} (declared={declared or 'unreadable'}, " + f"installed={installed or 'unrecorded'}). Where the field above " + f"prints a commit, THAT side was read fine; nothing here claims the " + f"installed openDox is unknown. On CI the unreadable side is itself " + f"the anomaly: `validate.yml` installs `-e \".[test]\"` against a " + f"PEP 508 direct VCS reference, and pip records `direct_url.json` " + f"for that every time. Failing rather than skipping, because a skip " + f"here is exactly the silent green this guard exists to prevent.") + pytest.skip( + f"{subject} is missing and the comparison could not be made: {unreadable} " + f"(declared={declared or 'unreadable'}, " + f"installed={installed or 'unreadable'}). NOTHING is claimed here about " + f"whether the installed openDox IS the declared one — the comparison " + f"never happened. This is not the different-commit skip, which reads " + f"both sides and names them. Off the CI path an unreadable side is " + f"lawful (an " + f"editable checkout or a hand-placed wheel records none). Under CI this " + f"same condition FAILS.", + allow_module_level=module_level) + pytest.skip( + f"{subject} is missing, and this is NOT the declared pin's doing: the " + f"installed distribution was built from {installed[:8]}, while " + f"`pyproject.toml` declares {declared[:8]}. Under the declared pin these " + f"suites RUN — reaching this reason means the `opendox` actually installed " + f"came from somewhere else (an assembly at its own pin, or a stale editable " + f"checkout).", + allow_module_level=module_level) + + _STAGED: Path | None = None def require(*, module_level: bool = True) -> Path: - """The pinned bundle, STAGED once per process as an ESM-marked tree — or - SKIP where the pin carries no bundle. + """The pinned bundle, STAGED once per process as an ESM-marked tree — or, + where there is none, whatever `_absent()` decides. + + THE OUTCOME IS `_absent()`'s FOUR-ROW TABLE AND THIS DOCSTRING DOES NOT + RESTATE IT. Two reviews on #21 caught a paraphrase here losing a row (first + "SKIP where the pin carries no bundle", then a summary that dropped the + off-CI unreadable case), which is what a second copy of a table is for. Read + `_absent()`. - `module_level=True` skips the IMPORTING MODULE, which is what the thirty - suites whose whole subject is the bundle want. `web()` below passes False, - which skips only the calling TEST — see its own docstring for when that is - the honest reading and when it is not. + `module_level` SCOPES THE SKIP OUTCOME AND NOTHING ELSE. With True a skip + takes the IMPORTING MODULE, which is what the TWENTY-NINE suites whose whole + subject is the bundle want (26 importing `OPENDOX_WEB`, 3 calling `composed()` + at module scope; `test_doxbench_turns.py` is NOT among them — it calls `web()` + per test, which is that docstring's own subject. The count read "thirty" until + the review of `2dfd669`); `web()` below passes False, so a skip takes only + the calling TEST (see its docstring for when that is the honest reading). The + FAIL outcomes — the declared pin, and an unreadable side under CI — are not + scoped by it at all, and no flag softens one. WHERE a failure lands is decided + by where the guard was REACHED, never by `module_level`: reached from a test, + `pytest.fail` fails that test; reached while a module is being imported — the + `OPENDOX_WEB` line, through PEP 562's `__getattr__`, or a module-scope + `composed()` — it raises during COLLECTION, and pytest reports that module as a + collection ERROR rather than a failed test. Red either way, which is the point. + The review of `e6cd0e8` caught this paragraph reading as though the flag + governed every outcome; the review of `ca327c2` caught the sentence that + replaced it promising a failed TEST in the one case that cannot produce one. WHY A STAGED COPY AND NOT THE INSTALLED DIRECTORY ITSELF (Copilot review of openXdox-code#19, the `test_round_trip.py` finding — accurate). Several of @@ -113,7 +597,36 @@ def require(*, module_level: bool = True) -> Path: if _STAGED is None: web = find() if web is None: - pytest.skip(_REASON, allow_module_level=module_level) + # THE 29 IMPORTER ANNOTATIONS THAT REACH THIS LINE ARE STALE, AND + # THEY ARE NOT REPAIRED HERE. Copilot's review of `399e2a9` on + # openXdox-code#21 is right about the fact: 29 files carry the + # annotation `# noqa: E402 (skips where the pin carries no bundle)`, + # and after the bump this path also FAILS — at the declared pin, and + # for an unreadable side under CI. The annotation sits on TWO import + # forms, which the review of `2dfd669` caught this sentence collapsing + # into one: 26 files import `OPENDOX_WEB` from here, and 3 — + # `test_doxbench_transport.py`, `test_session_confinement.py`, + # `test_staging_workbench.py` — `import opendox_bundle` and call + # `composed()` at module scope. Measured, not estimated: + # grep -rn 'skips where the pin carries no bundle' tests/ \ + # --include='test_*.py' -> 29 + # sites in 29 files. The --include is load-bearing: this comment + # quotes the annotation, so the unfiltered command answers 30 and + # counts the helper that reports the count. Caught at the review + # of `de7d966` on #21. + # git diff --name-only main -- -> 0 + # all 29 appear in openxFactory `docs/opendox-carve-manifest.yaml` + # Every one of them is an ARRIVED carve row whose edits are declared + # at openxFactory, and none is otherwise touched by this act, so + # editing them here would be an undeclared edit to a declared + # surface — the same ground on which + # `tests/test_doxbench_mutation_boundary.py` is DROPPED from + # `validate.yml` rather than repaired. Registered as residue in #21's + # description for a later declared act. Nothing is hidden by the + # wait: the annotation is a `# noqa` justification, while the + # outcome those files actually get is composed below, from what it + # measured, and names itself in full. + _absent("openDox's `web/` bundle", module_level=module_level) staging = Path(tempfile.mkdtemp(prefix="opendox-bundle-")) atexit.register(shutil.rmtree, staging, True) target = staging / "web" @@ -143,8 +656,10 @@ def require(*, module_level: bool = True) -> Path: def web() -> Path: - """The pinned bundle, skipping ONLY THE CALLING TEST where the pin carries - none. + """The pinned bundle; where there is none, `_absent()`'s outcome scoped to + the CALLING TEST rather than the module. Which outcome is `_absent()`'s + table's to say, and this docstring does not restate it — for the reason + `require()` above gives. FOR THE SUITE WHOSE SUBJECT IS NOT THE BUNDLE (Copilot review of `openXdox-code#19` is the class of finding this anticipates, and the @@ -156,8 +671,13 @@ def web() -> Path: suite it no longer runs. So the rule is the subject, not the convenience: a module whose every test - reads the bundle imports `OPENDOX_WEB` and skips whole; a module where the - bundle is an aside calls this and skips the three tests that need it. + reads the bundle imports `OPENDOX_WEB` and takes the outcome module-wide; a + module where the bundle is an aside calls this and takes it per test. WHERE + THE OUTCOME IS A SKIP, that reads "skips whole" and "skips the three tests + that need it"; where `_absent()` FAILS — the declared pin, or an unreadable + side under CI — the failure lands on whatever test reached the guard, and no + scoping flag softens it. Caught at the review of `e6cd0e8`, which was right + that promising a skip here contradicts the table this docstring defers to. """ return require(module_level=False) diff --git a/tests/test_dependency_direction.py b/tests/test_dependency_direction.py index 6b1f58f..9d52bf3 100644 --- a/tests/test_dependency_direction.py +++ b/tests/test_dependency_direction.py @@ -240,10 +240,15 @@ def test_every_deferred_cross_package_reach_out_of_src_is_known() -> None: # as `serve_gate.py` contributes its routes to the `route_extension` one, so # it belongs on this list for the same reason: a contribution surface that # stops consuming openDox has forked it. Its reach is DEFERRED (inside - # `GateLoopViews.views()`) and deliberately so — this leg pins an `opendox` - # older than the view registry itself, and an import-time reach would make - # the module unimportable under its own declared dependency. The census - # below counts a deferred reach, which is what makes that lawful here. + # `GateLoopViews.views()`) and deliberately so. This comment used to give + # the reason as "this leg pins an `opendox` older than the view registry + # itself" — true of `a99eba03`, no longer true since the 2026-09-16 bump to + # `0b4e8bbf` (openDox-code#23), where `opendox.view_extension` is + # importable. The deferral stays on the reason that outlives any one pin: an + # ASSEMBLY chooses the openDox this module runs under, and an import-time + # reach would make the module unimportable under a consumer pinned behind + # the view contract. The census below counts a deferred reach, which is what + # makes that lawful here. "src/openxdox/view_extensions.py", ) @@ -317,10 +322,27 @@ def test_the_doc_health_implementation_surface_is_exactly_declared() -> None: #: The openDox -> openXdox back-imports, MEASURED at the commit this leg pins. #: #: LOWERED TO ZERO AT IMPORT TIME BY BUILD SLICE 2b — `opensoft/openDox-code` -#: #10, which this file's pin now names (`pyproject.toml`). **0 import-time / -#: 19 deferred over five modules**, from 9 / 19 at the head of that slice and -#: from the 13 / 19 over six modules that the census RULED 5626260214 called -#: "the 13-line openDox->openXdox inversion" stood at. +#: #10. **0 import-time / 19 deferred over five modules**, from 9 / 19 at the +#: head of that slice and from the 13 / 19 over six modules that the census +#: RULED 5626260214 called "the 13-line openDox->openXdox inversion" stood at. +#: +#: THE PIN HAS MOVED TWICE SINCE — two bumps of THIS file's own declaration, +#: `0f1f2e59` -> `a99eba03` (openXdox-code#15) and `a99eba03` -> `0b4e8bbf` +#: (this act) — AND THE TABLE HAS NOT. Measured, not assumed. (Two pin bumps, +#: three upstream landings: they are different counts of different things, and +#: both are stated here so neither can be read as the other.) +#: This note used to say slice 2b's merge was the commit "this file's pin now +#: names"; that stopped being true at openXdox-code#15 (`0f1f2e59` -> +#: `a99eba03`) and the sentence was not followed, which is the stale-claim class +#: this repository has since had to sweep for. The pin names `0b4e8bbf` +#: (openDox-code#23, § 3.4 slice S8 leg B) as of 2026-09-16, and +#: `_back_import_census()` recomputed against THAT tree returns exactly the five +#: rows below. THE RANGE THAT COVERS IS THREE openDox-code LANDINGS, not two, and +#: naming them is the correction Copilot's round-1 review of openXdox-code#21 +#: asked for: from `a99eba03` (#11, § 4.3) this pin crosses `8efb3cf5` (#20, +#: § 3.4 slice S5 leg B), `1e469713` (#21, § 3.4 slice S7) and `0b4e8bbf` (#23, +#: § 3.4 slice S8 leg B). The ratchet neither fell nor rose across any of them, +#: and the numbers here are that measurement, not a carried-forward memory. #: #: THE WHOLE OF THE INVERSION IS GONE, which is worth stating plainly because #: this table has never been able to say it before: no module of the pinned diff --git a/tests/test_gate_loop_probes.py b/tests/test_gate_loop_probes.py index bbe1095..0a9c9f5 100644 --- a/tests/test_gate_loop_probes.py +++ b/tests/test_gate_loop_probes.py @@ -21,13 +21,38 @@ asserted once. THE ASSEMBLY IS THE PRECONDITION, AND IT IS THE PIN. This leg pins `opendox` by -commit (`pyproject.toml`), and the pinned commit predates BOTH the view registry -and the packaging fix that puts `opendox/web/` into a wheel at all -(openDox-code#20's own first commit). Where the installed `opendox` carries no -bundle there is nothing to assemble INTO, and every probe SKIPS with that reason -named — never fails, and never silently passes against a stand-in. They run in -full the moment the pin bump lands, which is the same bump the three -materialization assertions in `test_gate_loop_views.py` wait for. +commit (`pyproject.toml`). When these probes landed with slice S5 that pin was +`a99eba03`, which predated BOTH the view registry and the packaging fix that +puts `opendox/web/` into a wheel at all (openDox-code#20's own first commit), so +this paragraph said the probes "run in full the moment the pin bump lands". +THE BUMP LANDED — 2026-09-16, `a99eba03` -> `0b4e8bbf` (openDox-code#23, § 3.4 +slice S8 leg B) — and all thirteen of them now RUN: 13 skipped became 13 passed +under `validate.yml`'s own invocation, in the same act that moved the pin, and +the three materialization assertions in `test_gate_loop_views.py` that waited on +the same bump went 3 skipped -> 3 passed beside them. + +WHAT A MISSING BUNDLE MEANS NOW, stated precisely — the review rounds on #21 +rewrote this paragraph twice, and both times because it promised an outcome the +guard does not give. Where the installed `opendox` carries no bundle there is +nothing to assemble INTO, and `tests/opendox_bundle.py::_absent` chooses by +READING which openDox is installed: + + * a DIFFERENT commit from the one this leg declares -> SKIP, naming BOTH; + * NO recorded provenance, off CI -> SKIP, naming the declared one and saying + plainly that the installed one is unrecorded (it cannot name what it could + not read, which is why this is a different sentence from the one above); + * the DECLARED commit -> FAIL, because THAT is a regression here, and a skip + would take these thirteen probes quietly green in a required check; + * no recorded provenance UNDER CI -> FAIL TOO, and the review of `f6f1b991` on + #21 was right that this line used to file it under the word "regression". It + is not one. It is a PROVENANCE ANOMALY: the required run cannot establish + which openDox it is testing at all. `validate.yml` installs `-e ".[test]"` + against a PEP 508 direct VCS reference and pip records `direct_url.json` for + that every time, so failing to read one on the required path is a metadata or + install failure — worth stopping for, but never evidence that the bundle + regressed. + +No outcome ever passes silently against a stand-in. A CREATED file: no row in openxFactory's `docs/opendox-carve-manifest.yaml` (RULED OQ-C), admitted by path in the S5 annotation. @@ -118,7 +143,15 @@ def _run_node(body: str, bundle: Path) -> dict: def _opendox_bundle() -> Path | None: - """The INSTALLED openDox's web bundle, or None where the pin carries none.""" + """The INSTALLED openDox's web bundle, or None where no bundle was found. + + DISCOVERY ONLY, same contract as `tests/opendox_bundle.py::find` and stale + in the same way until the review of `399e2a9` on #21: "where the pin carries + none" was the one expected cause before the bump, and the `bundle` fixture + below now routes `None` into `_absent()` precisely BECAUSE it is no longer + the only one. What the absence means is `_absent()`'s four-row table; this + function only reports that the marker is not there. + """ try: import opendox except ModuleNotFoundError: # pragma: no cover - no consumer @@ -132,19 +165,41 @@ def bundle(tmp_path) -> Path: """A COMPOSED bundle: openDox's own `web/`, with this column's six modules placed into it by the assembly hook RULED Q5 names. - Skipped — never failed — where the assembled `opendox` carries no bundle: - that is this leg's pinned state until the pin bump, and a probe that quietly - ran against a stand-in `helpers.js` would measure the stand-in rather than - the shipped file. + Where the assembled `opendox` carries no bundle, the outcome is + `tests/opendox_bundle.py::_absent`'s FOUR-ROW TABLE and this docstring does + not restate it — two reviews on #21 caught a two-row paraphrase here, which is + what a second copy of a table is for. That this guard survives the pin bump at + all is RULED + openxFactory#656 comment 5700475319 (Brett Heap, 2026-09-16, by interactive + multi-choice), answer (a): keep the guards, correct their reasons. + + That was a plain skip until the 2026-09-16 pin bump, when a missing bundle + stopped being the expected state AT THE COMMIT THIS LEG DECLARES and started + being a regression THERE — see `tests/opendox_bundle.py::_absent`, which reads + both commits before it decides. Only the equal-commit row is a regression: a + DIFFERENT installed commit still skips, an unreadable side still skips off CI, + and the CI failure for an unreadable side is a comparison anomaly rather than + a verdict on the package. The review of `24cd5f2` caught this sentence + generalizing the one row to all four, two paragraphs below the table. + A probe that quietly ran against a stand-in `helpers.js` would measure the + stand-in rather than the shipped file, so a skip is still the right outcome + wherever `_absent()` gives one. """ source = _opendox_bundle() if source is None: - pytest.skip( - "the installed `opendox` carries no `web/` bundle: this leg pins a " - "commit older than openDox's own packaging fix, so there is nothing " - "to assemble into. The pin bump owed at landing makes these probes " - "run (the same bump `test_gate_loop_views.py`'s three " - "materialization assertions wait for)") + # The shared rule in `tests/opendox_bundle.py::_absent`, which READS the + # installed distribution's PEP 610 provenance instead of asserting it. + # Its four-row table is there, not restated here. Round 1 of the review on + # #21 found this file claiming the install "came from somewhere older than + # the declared pin" on a check that only tested for a marker. UNDER THAT + # CHECK, had `0b4e8bbf` itself ever stopped shipping `web/**`, all thirteen + # probes below would have skipped and this required check would have stayed + # green over the regression. UNDER THE TABLE THEY OBEY NOW THEY FAIL: the + # installed commit equals the declared pin, which is the table's first row + # — said here because the review of `9ab8521` read the sentence above as a + # claim about the guard that replaced it. + import opendox_bundle + opendox_bundle._absent("openDox's `web/` bundle", module_level=False) target = tmp_path / "web" shutil.copytree(source, target) web_assets.install_view_modules(target) @@ -628,3 +683,768 @@ def test_js_a_built_transport_keeps_the_model_it_validated(bundle) -> None: assert result["b"]["tag"] == "second", result["b"] # and the BODIES were shaped by the right model too, not only the verdicts assert result["sent"] == ["first", "second"] + + +# --------------------------------------------------------------------------- +# THE GUARD ITSELF, TESTED DIRECTLY — Copilot round-2 thread on #21 +# (`PRRT_kwDOUPv7_s6i_iiz`, "the new provenance decision is only exercised +# indirectly on the normal bundle-present path; there are no tests"). Accurate: +# the four branches had been proven by hand, by renaming the installed bundle and +# re-running. That proof is now permanent and runs in `validate`. +# +# These live HERE rather than in a new file on purpose: a created file at this leg +# needs an admission row in openxFactory's `docs/opendox-carve-admissions.yaml` +# (RULED OQ-C), and adding one is not a pin bump's act. This module is already +# admitted, already on `validate.yml`'s list, and already owns the fixture whose +# thirteen probes the decision gates. +# --------------------------------------------------------------------------- + +import opendox_bundle as _ob # noqa: E402 (a helper import, never OPENDOX_WEB) + +_PIN_A = "a" * 40 +_PIN_B = "b" * 40 + + +def _decide(monkeypatch, declared, installed, *, ci): + monkeypatch.setattr(_ob, "declared_pin", lambda: declared) + monkeypatch.setattr(_ob, "installed_commit", lambda: installed) + monkeypatch.setenv("CI", "true" if ci else "") + return lambda: _ob._absent("the subject under test", module_level=False) + + +def test_the_declared_pin_missing_its_bundle_FAILS(monkeypatch) -> None: + """The regression case: what is installed IS what this leg declares.""" + call = _decide(monkeypatch, _PIN_A, _PIN_A, ci=False) + with pytest.raises(pytest.fail.Exception) as raised: + call() + assert "REGRESSION at the declared pin" in str(raised.value) + assert _PIN_A[:8] in str(raised.value) + + +def test_a_different_installed_commit_SKIPS_and_names_both(monkeypatch) -> None: + """The lawful case: a consumer assembling at a DIFFERENT commit. + + Not "older": the values are synthetic and `_absent()` compares identities, so + nothing here establishes an ordering. Caught at the review of `27a89fd`. + """ + call = _decide(monkeypatch, _PIN_A, _PIN_B, ci=True) + with pytest.raises(pytest.skip.Exception) as raised: + call() + message = str(raised.value) + assert _PIN_A[:8] in message + assert _PIN_B[:8] in message + assert "NOT the declared pin's doing" in message + + +def test_unknown_provenance_FAILS_under_ci(monkeypatch) -> None: + """The round-2 finding: on the REQUIRED path, unknown is not neutral. + + The message says the two commits could not be COMPARED and names the side that + could not be read — it no longer says "this run cannot say which `opendox` is + installed", which was false whenever the unreadable side was `pyproject.toml` + (the review of `24cd5f2`, and the assertion below moved with it). + """ + call = _decide(monkeypatch, _PIN_A, None, ci=True) + with pytest.raises(pytest.fail.Exception) as raised: + call() + message = str(raised.value) + assert "could not be COMPARED" in message + assert "no usable PEP 610 provenance could be read" in message + + +def test_an_unreadable_declared_pin_under_ci_does_not_blame_the_install( + monkeypatch) -> None: + """THE CI TWIN of the off-CI test below, and the review of `24cd5f2`'s finding. + + `declared_pin()` unreadable with a perfectly good `direct_url.json` used to FAIL + saying "this run cannot say which `opendox` is installed" while the very next + field printed the installed hash. What is unknown is the COMPARISON, and the + message has to say which side went missing — under CI exactly as off it. + """ + call = _decide(monkeypatch, None, _PIN_B, ci=True) + with pytest.raises(pytest.fail.Exception) as raised: + call() + message = str(raised.value) + assert "declared pin could not be read" in message + assert "no usable PEP 610 provenance" not in message + assert _PIN_B in message + + +def test_both_sides_unreadable_says_NEITHER_rather_than_picking_one( + monkeypatch) -> None: + """The third shape, which the either/or phrasing could only half-report.""" + call = _decide(monkeypatch, None, None, ci=True) + with pytest.raises(pytest.fail.Exception) as raised: + call() + assert "NEITHER side is usable" in str(raised.value) + + +def test_unknown_provenance_SKIPS_off_ci(monkeypatch) -> None: + """...and off it, an editable checkout has no provenance to record.""" + call = _decide(monkeypatch, _PIN_A, None, ci=False) + with pytest.raises(pytest.skip.Exception) as raised: + call() + message = str(raised.value) + assert "no usable PEP 610 provenance could be read" in message + assert "NOTHING is claimed here about" in message + + +def test_an_unreadable_declared_pin_says_so_rather_than_blaming_the_install( + monkeypatch) -> None: + """The INSTALLED side can be perfectly good and the comparison still fail. + + Caught at the review of `27a89fd` on #21: this branch used to report "this + installation records no PEP 610 provenance" even when the installation had + recorded a valid one and it was `pyproject.toml` that could not be read. The + message now names whichever side is actually missing. + """ + call = _decide(monkeypatch, None, _PIN_B, ci=False) + with pytest.raises(pytest.skip.Exception) as raised: + call() + message = str(raised.value) + assert "declared pin could not be read" in message + assert "no usable PEP 610 provenance" not in message + + +def test_under_ci_reads_the_environment_the_runner_sets(monkeypatch) -> None: + """`CI` is read, not guessed: `1`, `true` and `yes` (any case, trimmed) are + CI; every other value, and an unset variable, are not. GitHub Actions sets + `CI=true`. The docstring used to say "nothing else is treated as CI" while the + body below accepted three spellings — caught at the review of `27a89fd`. + """ + for value, expected in (("true", True), ("TRUE", True), ("1", True), + ("yes", True), ("false", False), ("", False)): + monkeypatch.setenv("CI", value) + assert _ob.under_ci() is expected, value + monkeypatch.delenv("CI", raising=False) + assert _ob.under_ci() is False + + +def test_the_declared_pin_is_read_from_this_legs_own_pyproject(monkeypatch) -> None: + """Not a constant: the guard re-reads the file the bump edits. + + The first half checks the LIVE file, and on its own it proved nothing — a + hard-coded return of today's sha would satisfy a substring assertion against + the file that contains it (Copilot, review of `0e3922d`). The second half is + the proof: with `pyproject.toml` replaced by a synthetic one declaring a + DIFFERENT commit, the function must return THAT commit, which only a real read + can do. + """ + declared = _ob.declared_pin() + assert declared is not None + assert len(declared) == 40 + toml = (Path(__file__).resolve().parents[1] / "pyproject.toml").read_text( + encoding="utf-8") + assert f"openDox-code@{declared}" in toml + assert _PIN_A != declared + _with_pyproject_text(monkeypatch, _pyproject( + f"opendox @ git+https://github.com/opensoft/openDox-code@{_PIN_A}")) + assert _ob.declared_pin() == _PIN_A + + +def _with_unreadable_pyproject(monkeypatch, exc) -> None: + """Make `Path.read_text` raise for `pyproject.toml`, and for nothing else. + + Narrow on purpose: `declared_pin()` is the only reader under test, and a + blanket patch would hide which file the branch actually reacted to. + """ + real_read_text = Path.read_text + + def _read_text(self, *args, **kwargs): + if self.name == "pyproject.toml": + raise exc + return real_read_text(self, *args, **kwargs) + + monkeypatch.setattr(_ob.Path, "read_text", _read_text) + + +def _with_pyproject_text(monkeypatch, text) -> None: + """Make `pyproject.toml` READ CLEANLY as `text`, and nothing else change. + + `_with_unreadable_pyproject` above drives the two RAISING branches; this drives + the branch where the file is perfectly readable and simply does not declare the + pin — the `if match else None` the review of `de7d966` found untested. + """ + real_read_text = Path.read_text + + def _read_text(self, *args, **kwargs): + if self.name == "pyproject.toml": + return text + return real_read_text(self, *args, **kwargs) + + monkeypatch.setattr(_ob.Path, "read_text", _read_text) + + +def test_declared_pin_is_none_when_pyproject_declares_no_opendox_pin( + monkeypatch) -> None: + """A READABLE `pyproject.toml` with no `opendox @ git+…@<40-hex>` in it. + + The two tests above make the READ raise; nothing made the REGEX miss. A + dependency line that lost its pin — rewritten to a version range, to a branch + ref, to a path install, or simply deleted — returns None from the same function + and must reach the SAME fail-closed policy, or the required check could go green + over a leg that no longer declares which openDox it is built against. Caught at + the review of `de7d966` on #21. + """ + _with_pyproject_text(monkeypatch, ( + "[project]\nname = \"openxdox-code\"\n" + "dependencies = [\n" + " \"opendox @ git+https://github.com/opensoft/openDox-code@main\",\n" + " \"pyyaml>=6\",\n" + "]\n")) + assert _ob.declared_pin() is None + + +def _pyproject(*requirements, extra="") -> str: + """A minimal, VALID `pyproject.toml` declaring exactly these requirements. + + The quote is chosen per requirement — a TOML literal string for the usual + case, a basic string where the value itself carries a `'` — because two cases + below put a quote character INSIDE the requirement on purpose, and a helper + that emitted invalid TOML would make `declared_pin()` return None for the + wrong reason, passing the test while proving nothing. + """ + body = "" + for requirement in requirements: + quote = '"' if "'" in requirement else "'" + assert quote not in requirement, requirement + body += f" {quote}{requirement}{quote},\n" + return ('[project]\nname = "openxdox-code"\n' + f"{extra}dependencies = [\n{body}]\n") + + +def test_declared_pin_refuses_anything_but_a_whole_40_hex_direct_pin( + monkeypatch) -> None: + """A ref that CONTINUES past the sha is not a pin, and every escape is closed. + + Four review rounds walked this one class of bug out of a text search — no + terminator at all (`8b9ece1`), a negative lookahead that let `-feature`, + `/branch`, `_suffix` and `.1` through (`2dfd669`), a positive terminator set + that still let `,` and `'` through INSIDE the quoted URL (`a9264b8`) — and the + answer was to stop searching text: `tomllib` hands over the dependency VALUE, + and `fullmatch` admits it only if the WHOLE requirement is the pin. Every + continuation those rounds named is driven here, on one `assert`. + """ + # `#feature` stays a REFUSAL: a bare `#…` is a ref continuation, not pip's + # `key=value` direct-reference fragment, and only the latter is stripped + # (review of `e92fb06`). + for tail in ("dead", "x", "0", "-feature", "/branch", "_suffix", ".1", + ",feature", "'feature", " feature", "#feature"): + for url in (f"git+https://github.com/opensoft/openDox-code@{_PIN_A}", + f"git+ssh://git@github.com/opensoft/openDox-code@{_PIN_A}"): + _with_pyproject_text(monkeypatch, _pyproject(f"opendox @ {url}{tail}")) + assert _ob.declared_pin() is None, (url, tail) + + +def test_declared_pin_refuses_a_pin_at_a_DIFFERENT_REPOSITORY(monkeypatch) -> None: + """A 40-hex pin at another project is not a declaration this guard can read. + + `installed_commit()` compares SHAS ONLY, so a dependency re-pointed at another + repository at some other 40-hex commit would have made a missing bundle look + like the lawful "different commit" case and SKIP under CI — while this leg was + no longer testing openDox-code at all. Copilot's thread on `0e3922d`. Such a + pin reads as NO pin, which is the fail-closed path, and a fork or mirror of + openDox-code under another account still reads (what is refused is a different + PROJECT, not a different host). + """ + for url, expected in ( + (f"git+https://github.com/opensoft/openDox-code@{_PIN_A}", _PIN_A), + (f"git+https://github.com/someone/openDox-code@{_PIN_A}", _PIN_A), + (f"git+https://example.invalid/mirrors/opendox-code.git@{_PIN_A}", _PIN_A), + (f"git+https://github.com/opensoft/openXdox-code@{_PIN_A}", None), + (f"git+https://github.com/opensoft/some-other-project@{_PIN_A}", None), + ): + _with_pyproject_text(monkeypatch, _pyproject(f"opendox @ {url}")) + assert _ob.declared_pin() == expected, url + + +def test_declared_pin_ignores_a_commented_out_dependency(monkeypatch) -> None: + """The stale sha in a COMMENT is not what this leg declares. + + Copilot's finding at `a9264b8`: a search over the raw file text reads a sha out + of a commented-out old line, so a leg whose real dependency had been changed or + removed would still report the commented commit — and `_absent()` would compare + against a pin this file no longer declares. `tomllib` never sees comments. + """ + _with_pyproject_text(monkeypatch, _pyproject( + "PyYAML>=6.0", + extra=(f'# opendox @ git+https://github.com/opensoft/openDox-code@{_PIN_A}\n' + "# (kept as provenance, and not a declaration)\n"))) + assert _ob.declared_pin() is None + + +def test_declared_pin_reads_the_pin_through_extras_markers_and_position( + monkeypatch) -> None: + """...and the parse does not cost the pin it protects. + + PEP 508 lets the requirement carry extras and an environment marker, and the + list has no required order. A guard too strict to read a legitimate declaration + fails closed on a CORRECT file, which is the opposite defect and just as silent. + """ + for requirement in ( + f"opendox @ git+https://github.com/opensoft/openDox-code@{_PIN_A}", + f"opendox[test] @ git+https://github.com/opensoft/openDox-code@{_PIN_A}", + # An SSH declaration carries an `@` in the AUTHORITY, and a pattern that + # stopped at the first one read NO pin out of a requirement pip installs + # happily — the guard would then fail closed under CI on a correct file. + # Copilot's review of `52453af`. + f"opendox @ git+ssh://git@github.com/opensoft/openDox-code@{_PIN_A}", + f'opendox @ git+https://github.com/opensoft/openDox-code@{_PIN_A} ; python_version >= "3.11"', + # Distribution names are case-insensitive (PEP 503), and this one is + # spelled `openDox` half the time in this estate. Copilot, `18e8c12`. + f"OpenDox @ git+https://github.com/opensoft/openDox-code@{_PIN_A}", + # A SEMICOLON is a legal URI character, and `partition(";")` truncated + # the url at it — the guard failing closed on a declaration pip + # installs. The PEP 508 parser knows where a marker starts. + # Copilot, review of `0e3922d`. + f"opendox @ git+https://github.com/opensoft/openDox-code;branch@{_PIN_A}", + # ...and a `.git` suffix, which the source check must not refuse. + f"opendox @ git+ssh://git@github.com/opensoft/openDox-code.git@{_PIN_A}", + # pip's direct-reference FRAGMENT is legal after the pin and says + # nothing about which commit is declared. `#subdirectory=…` read as NO + # pin until the review of `e92fb06`, failing the guard closed on a + # declaration pip installs. + f"opendox @ git+https://github.com/opensoft/openDox-code@{_PIN_A}#subdirectory=src", + f"opendox @ git+https://github.com/opensoft/openDox-code@{_PIN_A}#egg=opendox&subdirectory=src", + ): + _with_pyproject_text(monkeypatch, _pyproject( + "PyYAML>=6.0", requirement, "jsonschema>=4.18")) + assert _ob.declared_pin() == _PIN_A, requirement + + +def test_declared_pin_is_none_for_a_pin_whose_marker_is_FALSE(monkeypatch) -> None: + """A conditional requirement is a declaration only where its marker holds. + + With `; python_version < "3.0"` pip installs nothing from that line, so reading + the sha as "the commit this leg declares" would compare whatever `opendox` + happens to be installed against a pin that is NOT ACTIVE — and the mismatch + takes the different-commit SKIP, over a real regression. Copilot's review of + `18e8c12`; the marker is evaluated now, and an unevaluable one reads as false. + """ + for marker, expected in (('python_version >= "3.0"', _PIN_A), + ('python_version < "3.0"', None), + # A SYNTACTICALLY VALID marker naming a variable this + # environment has no value for. The case here used to + # be `this is not a marker`, which `Requirement()` + # rejects outright — so it proved the InvalidRequirement + # branch and never reached `_marker_holds()` at all. + # Copilot's review of `9ff630d`. + ('extra == "nothing-declares-this"', None)): + _with_pyproject_text(monkeypatch, _pyproject( + f"opendox @ git+https://github.com/opensoft/openDox-code@{_PIN_A}" + f" ; {marker}")) + assert _ob.declared_pin() == expected, marker + # ...and the unevaluable path is driven at the function, where a marker that + # PARSES but cannot be evaluated here must read as false rather than raise. + assert _ob._marker_holds('extra == "x"') is False + assert _ob._marker_holds("this is not a marker") is False + assert _ob._marker_holds('python_version >= "3.0"') is True + + +def test_declared_pin_is_none_when_pyproject_does_not_parse(monkeypatch) -> None: + """A `pyproject.toml` that is not TOML declares nothing, and fails closed. + + The read became a PARSE at `a9264b8`'s review, so `TOMLDecodeError` joined + `OSError` and `UnicodeDecodeError` in the same refusal. Without it the guard + would raise out of `declared_pin()` and bypass `_absent()`'s policy entirely — + the defect the review of `27a89fd` found for `UnicodeDecodeError`, one parser + later. + """ + _with_pyproject_text(monkeypatch, "[project\nname = broken") + assert _ob.declared_pin() is None + + +def test_an_undeclared_pin_FAILS_under_ci_like_any_other_unreadable_side( + monkeypatch) -> None: + """...and the outcome is the fail-closed one, driven end to end. + + The test above proves the function returns None; this proves what `_absent()` + then does with it — FAIL under CI, naming the declared side as the one it could + not read, with the installed commit still printed because that side was fine. + """ + _with_pyproject_text(monkeypatch, "[project]\nname = \"openxdox-code\"\n") + monkeypatch.setattr(_ob, "installed_commit", lambda: _PIN_B) + monkeypatch.setenv("CI", "true") + with pytest.raises(pytest.fail.Exception) as raised: + _ob._absent("the subject under test", module_level=False) + message = str(raised.value) + assert "declared pin could not be read" in message + assert _PIN_B in message + + +def test_declared_pin_is_none_when_the_read_raises(monkeypatch) -> None: + """The unreadable DECLARED side, produced rather than assumed. + + Copilot's review of `f6f1b991` on #21: the CI fail-closed policy depends on + `declared_pin()` returning None when the read raises, and every test of the + decision monkeypatches `declared_pin()` itself — so `declared=None` had only + ever been supplied as an input, never once produced by the function. + """ + _with_unreadable_pyproject(monkeypatch, OSError("pyproject.toml unreadable")) + assert _ob.declared_pin() is None + + +def test_declared_pin_is_none_when_pyproject_is_not_utf_8(monkeypatch) -> None: + """The half of that branch that was a REAL BUG until the review of `27a89fd`. + + `UnicodeDecodeError` is a `ValueError`, NOT an `OSError`, so a non-UTF-8 + `pyproject.toml` raised straight out of `declared_pin()` and past + `_absent()`'s unknown-provenance policy — the required check's fail-closed + rule bypassed entirely. This case exists so the `except` clause cannot + silently narrow back to `OSError` alone. + """ + _with_unreadable_pyproject( + monkeypatch, + UnicodeDecodeError("utf-8", b"\xff", 0, 1, "invalid start byte")) + assert _ob.declared_pin() is None + + +# --- THE PEP 610 PARSER ITSELF, not a monkeypatched stand-in ----------------- +# Copilot round 3 on #21: "all six direct guard tests monkeypatch +# `installed_commit()` and therefore bypass this code … a parser regression can +# change the CI decision while the required tests remain green." Accurate — the +# tests above pin the DECISION, these pin the READING it decides on. A fake +# distribution is installed over `importlib.metadata.distribution`, which is the +# exact name `installed_commit()` resolves at call time. + +class _FakeDist: + """Just enough of `importlib.metadata.Distribution` for `read_text`.""" + + def __init__(self, payload): + self._payload = payload + + def read_text(self, name): + if name != "direct_url.json": # pragma: no cover - never asked + return None + if isinstance(self._payload, Exception): + raise self._payload + return self._payload + + +#: The ONE distribution `installed_commit()` may ask about. Both fakes below assert +#: it, because neither did until the review of `a0eed16`: they answered to ANY name, +#: so a regression to `distribution("openxdox")` — or to any other installed package +#: — would have read a STRANGER's `direct_url.json`, compared that commit against +#: this leg's declared pin, and left every parser test then standing green while +#: doing it — all TEN of them then; the eleventh is the one below, which exists +#: because of this finding. (`grep -c '^def test_installed_commit' ` +#: -> 13 at this head: the review of `9ab8521` added the two SOURCE cases.) +_ASKED = "opendox" + + +def _with_dist(monkeypatch, payload): + """Install a fake distribution whose `read_text` returns (or raises) `payload`. + + The fake ASSERTS the name it is asked for (see `_ASKED`): the provenance this + guard reads is worthless if it is read off the wrong package. + """ + import importlib.metadata as md + + def _lookup(name): + assert name == _ASKED, f"installed_commit() asked for {name!r}, not {_ASKED!r}" + return _FakeDist(payload) + monkeypatch.setattr(md, "distribution", _lookup) + + +def _with_no_dist(monkeypatch, exc): + """Make the LOOKUP itself raise — the path `_with_dist` cannot reach. + + Caught at `7c0a3b6`: `_with_dist(PackageNotFoundError(...))` made `read_text` + raise, so the test named for an uninstalled package never exercised + `distribution("opendox")` failing, which is the call `installed_commit()` + actually guards. It asserts the requested name too, for `_with_dist`'s reason. + """ + import importlib.metadata as md + + def _raise(name): + assert name == _ASKED, f"installed_commit() asked for {name!r}, not {_ASKED!r}" + raise exc + monkeypatch.setattr(md, "distribution", _raise) + + +def test_installed_commit_asks_for_the_opendox_distribution_and_no_other( + monkeypatch) -> None: + """The lookup NAME is the assertion, and nothing else asserted it. + + `_with_dist` answered to any name, so `distribution("openxdox")` would have read + a stranger's PEP 610 record and compared ITS commit against this leg's declared + pin — a provenance check on the wrong package, with every parser test green. + Caught at the review of `a0eed16` on #21. + """ + import importlib.metadata as md + asked = [] + + def _lookup(name): + asked.append(name) + return _FakeDist(json.dumps( + {"url": "https://github.com/opensoft/openDox-code", + "vcs_info": {"vcs": "git", "commit_id": _PIN_B}})) + monkeypatch.setattr(md, "distribution", _lookup) + assert _ob.installed_commit() == _PIN_B + assert asked == ["opendox"] + + +def test_installed_commit_reads_a_real_vcs_record(monkeypatch) -> None: + _with_dist(monkeypatch, json.dumps( + {"url": "https://github.com/opensoft/openDox-code", + "vcs_info": {"vcs": "git", "commit_id": _PIN_B}})) + assert _ob.installed_commit() == _PIN_B + + +def test_installed_commit_is_none_when_the_file_is_absent(monkeypatch) -> None: + _with_dist(monkeypatch, None) + assert _ob.installed_commit() is None + + +def test_installed_commit_is_none_on_malformed_json(monkeypatch) -> None: + _with_dist(monkeypatch, "{not json at all") + assert _ob.installed_commit() is None + + +def test_installed_commit_is_none_for_a_non_vcs_install(monkeypatch) -> None: + """A wheel installed from an archive records `archive_info`, not `vcs_info`.""" + _with_dist(monkeypatch, json.dumps( + {"url": "file:///tmp/opendox-0.0.0-py3-none-any.whl", + "archive_info": {"hash": "sha256=abc"}})) + assert _ob.installed_commit() is None + + +def test_installed_commit_refuses_a_commit_id_that_is_not_40_hex(monkeypatch) -> None: + """A short id is not a commit this guard may compare — round 3's parser case.""" + _with_dist(monkeypatch, json.dumps( + {"vcs_info": {"vcs": "git", "commit_id": "0b4e8bbf"}})) + assert _ob.installed_commit() is None + + +def test_installed_commit_refuses_forty_characters_that_are_not_hex(monkeypatch) -> None: + """THE SILENT-GREEN PATH THROUGH THE PARSER, caught at `42741fd`. + + `len(commit) == 40` admitted any forty characters, so a malformed record + carrying a forty-character non-hex id read as "a different pin" and `_absent()` + SKIPPED under CI — the exact outcome this guard exists to prevent, reached + through the reading rather than through the decision. + """ + _with_dist(monkeypatch, json.dumps( + {"vcs_info": {"vcs": "git", "commit_id": "z" * 40}})) + assert _ob.installed_commit() is None + + +def test_installed_commit_normalizes_an_upper_case_commit_id(monkeypatch) -> None: + """A lawful record spelled in upper case is compared, not discarded. + + Asked for on #21. It can only ever turn an "unknown" into a real comparison: + without it an upper-case id would read as unreadable provenance and FAIL under + CI over a formatting difference rather than a regression. + """ + _with_dist(monkeypatch, json.dumps( + {"url": "https://github.com/opensoft/openDox-code", + "vcs_info": {"vcs": "git", "commit_id": _PIN_B.upper()}})) + assert _ob.installed_commit() == _PIN_B + + +def test_installed_commit_refuses_a_record_that_is_not_git(monkeypatch) -> None: + """A 40-hex id under a non-git VCS is not an openDox-code commit.""" + _with_dist(monkeypatch, json.dumps( + {"vcs_info": {"vcs": "hg", "commit_id": _PIN_B}})) + assert _ob.installed_commit() is None + + +def test_installed_commit_refuses_a_record_from_a_DIFFERENT_PROJECT(monkeypatch) -> None: + """A 40-hex git commit OF SOMETHING ELSE is not provenance this leg may compare. + + `installed_commit()` returned `vcs_info.commit_id` and dropped the record's + `url`, so an `opendox` built from an unrelated repository at its own commit + reached `_absent()` as the lawful DIFFERENT-COMMIT case and SKIPPED the required + suite — with nothing installed here coming from openDox-code at all. The + DECLARED side got this check at `9ff630d` + (`test_declared_pin_refuses_a_pin_at_a_DIFFERENT_REPOSITORY`); Copilot's thread + on `9ab8521` asked for it on the side that is actually imported. + """ + for url in ("https://github.com/opensoft/openXdox-code", + "https://github.com/opensoft/openDox-spec", + "https://github.com/opensoft/openDox-code-mirror", + "file:///srv/wheels/opendox"): + _with_dist(monkeypatch, json.dumps( + {"url": url, "vcs_info": {"vcs": "git", "commit_id": _PIN_B}})) + assert _ob.installed_commit() is None, url + + +def test_installed_commit_reads_a_fork_a_mirror_and_an_ssh_record(monkeypatch) -> None: + """...and the source check must not fail CLOSED on a lawful install. + + An installed record carries no `@` — PEP 610 keeps the ref in + `requested_revision` — so stripping at the LAST `@` cut + `ssh://git@github.com/opensoft/openDox-code` down to `ssh://git` and read a + correct install as a different project: the "too strict" half of this defect, + which every round of this arc has found paired with the too-loose half. A fork + or a mirror under another account reads too, RULED openxFactory#656 comment + 5700475319: a consumer may pin an openDox of its own choosing; what is refused + is a different PROJECT. + """ + for url in ("https://github.com/opensoft/openDox-code", + "git+https://github.com/opensoft/openDox-code.git", + "ssh://git@github.com/opensoft/openDox-code", + "https://github.com/a-fork/openDox-code", + "https://git.example.test/mirrors/opendox-code.git", + "https://github.com/opensoft/openDox-code#subdirectory=src"): + _with_dist(monkeypatch, json.dumps( + {"url": url, "vcs_info": {"vcs": "git", "commit_id": _PIN_B}})) + assert _ob.installed_commit() == _PIN_B, url + + +def test_installed_commit_is_none_when_the_package_is_not_installed(monkeypatch) -> None: + """The LOOKUP fails, not the read — see `_with_no_dist`.""" + from importlib.metadata import PackageNotFoundError + _with_no_dist(monkeypatch, PackageNotFoundError("opendox")) + assert _ob.installed_commit() is None + + +def test_installed_commit_is_none_when_reading_the_record_raises(monkeypatch) -> None: + """...and the read failing is its own case, which is what `_with_dist` drives.""" + _with_dist(monkeypatch, OSError("metadata unreadable")) + assert _ob.installed_commit() is None + +# WHY THE CASES ABOVE ARE THE CASES: `_absent()` branches on `installed_commit()`'s +# RETURN VALUE, so every test of the DECISION that monkeypatches that function +# proves nothing about the READING. TWELVE cases cover the reading of the INSTALLED +# side — a real VCS record, an absent `direct_url.json`, malformed JSON, a non-VCS +# (`archive_info`) install, a commit id that is not 40 characters, forty +# characters that are not hex, an UPPER-CASE 40-hex id (normalized rather than +# discarded), a 40-hex id under a non-git VCS, a record whose `url` names a +# DIFFERENT PROJECT, the fork / mirror / SSH / fragment shapes that must still +# read (the same defect's too-strict half), the distribution LOOKUP raising, +# and the read raising. The DECLARED side's own reading is covered separately, +# above, by the `test_declared_pin_is_none_when_…` cases — and THAT count is not +# written here at all, because it was written as "two" and was five by the time +# the review of `5285cf2` read it (the readable miss, a false marker, a file that +# does not parse, the read raising, a non-UTF-8 file). The command is the count: +# +# grep -c '^def test_declared_pin_is_none' tests/test_gate_loop_probes.py +# +# THE COUNT IS MEASURED, NOT CARRIED, and this line read "nine" until the review +# of `f6f1b991` on #21 caught that the upper-case case added at `b177eef` had +# never reached the inventory: +# +# grep -c '^def test_installed_commit' tests/test_gate_loop_probes.py -> 13 +# +# It read 10 until the review of `fd3af6a` caught the lookup-name test the review +# of `a0eed16` had just asked for — the same staleness, one round later, which is +# why the command is printed beside the number every time. +# A DELETED case is not one of the cases above, and this paragraph used to number +# it as though it were ("a tenth test"). One further test stood here until `7c0a3b6` +# and is gone rather than repaired: it asserted strings against +# `inspect.getsource(installed_commit)`, and once the implementation stopped +# containing `len(commit) == 40` it passed only because an explanatory COMMENT +# still held that text. A test coupled to source text fails on a harmless rename +# and catches no behaviour — the cases above already assert the results it was +# gesturing at. + + +# --- THE CALL SITES, not the decision and not the parser --------------------- +# Copilot's review of `8b23f6f` on #21, and it is the round-3 finding one level +# out: the tests above prove what `_absent()` DECIDES and what +# `installed_commit()` READS, and every one of them either calls `_absent()` +# directly or monkeypatches the function under it. None of them proves that the +# three CALLERS still route a missing subject INTO `_absent()`. That review's own +# sentence: "replacing this call with `pytest.skip` would leave the guard +# tests green while the `OPENDOX_WEB` importers silently skip under CI" — it said +# 19, the count at ITS head, and the point does not live in the number, so the +# number is not carried here. What is true at any head is the command: +# git diff main -- tests/test_gate_loop_probes.py | grep -c '^+def test_' +# git diff main -- tests/test_gate_loop_views.py | grep -c '^+def test_' +# (37 in this file and 6 in the views file at THIS head — 19 decision/read cases, +# 13 `installed_commit` parser tests and 5 call-site tests here; `validate.yml`'s +# record block carries the total, 43. The review of `fd3af6a` caught this pair +# reading 25 and 6, and the review of `de7d966` moved it again by asking for the +# two undeclared-pin tests: a count written in prose is stale one round later, +# which is why the commands are printed above it every time.) +# It is exactly the silent green this whole guard exists to break, reached one +# level further out each round — and the review of `b22a6fd` caught the quoted +# count going stale three rounds after the quotation. +# Two call sites are covered here; the third +# (`test_gate_loop_views.py::_view_extension_or_skip`) is covered in that file, +# beside the assertions it gates. + + +def _pin(monkeypatch, declared, installed, *, ci=True): + """Fix what the guard will READ, so a call site's OUTCOME is the assertion.""" + monkeypatch.setattr(_ob, "declared_pin", lambda: declared) + monkeypatch.setattr(_ob, "installed_commit", lambda: installed) + monkeypatch.setenv("CI", "true" if ci else "") + + +def test_require_FAILS_at_the_declared_pin_when_the_bundle_is_missing( + monkeypatch) -> None: + """`opendox_bundle.require()`'s own call site, driven with no bundle. + + `_STAGED` is reset because `require()` stages once per process and every + other suite in this run has already filled it — without the reset this test + would never reach `find()` at all, and would prove nothing. + """ + _pin(monkeypatch, _PIN_A, _PIN_A) + monkeypatch.setattr(_ob, "_STAGED", None) + monkeypatch.setattr(_ob, "find", lambda: None) + with pytest.raises(pytest.fail.Exception) as raised: + _ob.require(module_level=False) + assert "REGRESSION at the declared pin" in str(raised.value) + + +def test_require_SKIPS_for_a_different_installed_commit(monkeypatch) -> None: + """...and the lawful consumer still gets a skip through the same call.""" + _pin(monkeypatch, _PIN_A, _PIN_B) + monkeypatch.setattr(_ob, "_STAGED", None) + monkeypatch.setattr(_ob, "find", lambda: None) + with pytest.raises(pytest.skip.Exception) as raised: + _ob.require(module_level=False) + assert "NOT the declared pin's doing" in str(raised.value) + + +def test_require_forwards_its_DEFAULT_module_level_to_the_skip(monkeypatch) -> None: + """THE DEFAULT IS THE PATH THE MODULE-SCOPE CALLERS TAKE, and no test drove it. + + Both call-site tests above pass `module_level=False`, because that is what a + test function needs. The TWENTY-NINE annotated module-scope sites take the + default instead — 26 importing `OPENDOX_WEB`, which PEP 562's `__getattr__` + resolves with a bare `require()`, and 3 calling `composed()`, which calls a + bare `require()` of its own (the two forms `opendox_bundle.py`'s own annotation + note keeps apart, and which the review of `2dfd669` caught being collapsed into + one). At module scope a skip must carry `allow_module_level=True` or pytest + raises instead of skipping, so a regression that stopped forwarding the default + would have left every test above green and broken exactly those callers. + Copilot's review of `5285cf2`. + """ + _pin(monkeypatch, _PIN_A, _PIN_B) + monkeypatch.setattr(_ob, "_STAGED", None) + monkeypatch.setattr(_ob, "find", lambda: None) + with pytest.raises(pytest.skip.Exception) as raised: + _ob.require() + assert raised.value.allow_module_level is True + assert "NOT the declared pin's doing" in str(raised.value) + + +def test_the_bundle_fixture_FAILS_at_the_declared_pin(request, monkeypatch) -> None: + """The `bundle` fixture's call site, driven through the real fixture. + + `request.getfixturevalue` runs the fixture that the thirteen probes below + receive, so what is proven is the branch they actually take — not a copy of + it written into the test. + """ + import sys + _pin(monkeypatch, _PIN_A, _PIN_A) + monkeypatch.setattr(sys.modules[__name__], "_opendox_bundle", lambda: None) + with pytest.raises(pytest.fail.Exception) as raised: + request.getfixturevalue("bundle") + assert "REGRESSION at the declared pin" in str(raised.value) + + +def test_the_bundle_fixture_SKIPS_for_a_different_installed_commit( + request, monkeypatch) -> None: + """...and skips, naming both commits, for an assembly at another pin.""" + import sys + _pin(monkeypatch, _PIN_A, _PIN_B) + monkeypatch.setattr(sys.modules[__name__], "_opendox_bundle", lambda: None) + with pytest.raises(pytest.skip.Exception) as raised: + request.getfixturevalue("bundle") + message = str(raised.value) + assert _PIN_A[:8] in message + assert _PIN_B[:8] in message diff --git a/tests/test_gate_loop_views.py b/tests/test_gate_loop_views.py index 2864efa..6e44b49 100644 --- a/tests/test_gate_loop_views.py +++ b/tests/test_gate_loop_views.py @@ -615,17 +615,89 @@ def test_the_style_residue_is_recorded_rather_than_skipped() -> None: # --------------------------------------------------------------------------- def _view_extension_or_skip(): - view_extension = pytest.importorskip( - "opendox.view_extension", - reason="this leg pins an `opendox` older than the § 3.4 slice S3 view " - "registry; the specs above are asserted as data, and the " - "materialization is asserted wherever a contract-bearing " - "opendox is installed") - if "exports" not in getattr(view_extension.ViewBinding, "__annotations__", {}): - pytest.skip( - "the pinned `opendox.view_extension.ViewBinding` predates RULED Q2's " - "`exports` field (openxFactory#656 comment 5648049748); the pin bump " - "to the openDox carrying § 3.4 slice S5 is owed at landing") + """The assembled openDox's view registry, or — where it has none — whichever + of FAIL and SKIP `tests/opendox_bundle.py::_absent` measures: FAIL for the + commit this leg DECLARES and for an UNREADABLE SIDE (either commit) under CI; + SKIP for a DIFFERENT commit and for an unreadable side OFF CI. + + This summary took two goes. It read "or SKIP where it has none", which + contradicted the table four paragraphs down; the review of `42741fd` on #21 + caught that, and the review of `7c0a3b6` caught the replacement too — it said + a skip was "only for a demonstrably different consumer" and dropped the + off-CI unrecorded branch. All four rows are on the line now, because the + summary is the line a reader trusts and a half-table is how it went wrong + twice. + + ALL THREE REFUSAL BRANCHES ARE SATISFIED BY THIS LEG'S OWN PIN, since + 2026-09-16 (the module, the `ViewBinding` class, and RULED Q2's `exports` + field — the enumeration is below; this line said "BOTH GUARDS" until the + review of `8b9ece1`, having been written when there were two). + They were not when slice S5 wrote them: the pin was `a99eba03`, the first + reason read "this leg pins an `opendox` older than the § 3.4 slice S3 view + registry" and the second said the bump "is owed at landing". The bump landed + (`a99eba03` -> `0b4e8bbf`, openDox-code#23, § 3.4 slice S8 leg B) and the + three assertions below went 3 skipped -> 3 passed under `validate.yml`'s own + invocation. The old wording is quoted here as provenance, not asserted. + + THE GUARDS STAY, and that is RULED rather than preferred: + RULED openxFactory#656 comment 5700475319 (Brett Heap, 2026-09-16, by + interactive multi-choice) answered the question "keep the guards and correct + their reasons, or delete them on pin lockstep #2's precedent" with + (a) KEEP — because what they + test is the ASSEMBLED openDox, not this leg's declared pin (the section header + above says so), and an assembly is free to install an openDox behind the view + contract. That is the same + condition `view_extensions.ViewContractUnsupported` names at runtime, and + the three refusal branches below are its test-time counterpart (the paragraph + said "these two guards" until the review of `52453af`, having been written when + there were two). + + BUT THEY NO LONGER SKIP BLINDLY. Copilot's round-1 review of openXdox-code#21 + was right that `pytest.importorskip` cannot tell a DIFFERENT assembly from "a + regression in the openDox this leg DECLARES", and after the bump only the + first of those may skip. (That review said "an older assembly"; the guard that + replaced `importorskip` cannot measure ordering, only identity, so this summary + stopped borrowing the word — the review of `cb84001` caught it here, the last + copy left in the file.) If `0b4e8bbf` lost `view_extension` or the `exports` + field, all three assertions below would have gone quietly green in a required + check. `tests/opendox_bundle.py::_absent` decides by READING the declared pin + out of `pyproject.toml` and the installed commit out of the distribution's + PEP 610 `direct_url.json`. This docstring said "different (or unrecorded) -> + SKIP", and Copilot's round-3 review of #21 was right that the parenthesis is + false: an UNREADABLE SIDE fails under CI and skips only off it, because a + skip on the required path is the silent green the guard exists to prevent. + The table `_absent()` actually carries: equal -> FAIL; different -> SKIP with + both commits named; either side unreadable -> FAIL under CI naming WHICH side + it was, SKIP off it. + """ + import opendox_bundle + try: + from opendox import view_extension + except ImportError: + # FAIL at the declared pin, SKIP only for a different one. `importorskip` + # could not tell those apart, and after the pin bump that difference is + # the whole point: a packaging or API regression at `0b4e8bbf` would have + # taken all three assertions below quietly green in a required check. + opendox_bundle._absent( + "`opendox.view_extension` (§ 3.4 slice S3's view registry)", + module_level=False) + binding = getattr(view_extension, "ViewBinding", None) + if binding is None: + # THE MODULE WITHOUT ITS CLASS — a third unsupported shape, and until the + # review of `24cd5f2` on #21 the only one that escaped this guard: the + # class was dereferenced here directly, so an assembly shipping + # `view_extension` without `ViewBinding` raised AttributeError instead of + # taking the declared FAIL/SKIP. `view_extensions.ViewContractUnsupported` + # names exactly that assembly as unsupported (its docstring: "an assembly + # that pins an openDox without `view_extension.ViewBinding`"), so it is + # `_absent()`'s to classify, like the other two. + opendox_bundle._absent( + "`opendox.view_extension.ViewBinding` (§ 3.4 slice S3's view " + "registry class)", module_level=False) + if "exports" not in getattr(binding, "__annotations__", {}): + opendox_bundle._absent( + "RULED Q2's `exports` field on `opendox.view_extension.ViewBinding` " + "(openxFactory#656 comment 5648049748)", module_level=False) return view_extension @@ -710,3 +782,162 @@ def test_the_draft_views_one_action_is_the_create_forms_own_submit() -> None: assert create.count('method: "POST"') == 1, "still exactly one write" # the TILE path is untouched: there a new document really is being started assert 'o.submitLabel || "create document"' in create + + +# --------------------------------------------------------------------------- +# `_view_extension_or_skip`'s OWN CALL SITES — Copilot's review of `8b23f6f` on +# openXdox-code#21, and it was right: the three materialization assertions above +# exercise only the SUCCESSFUL import-and-`exports` path. The guard's refusal +# branches were reached by nothing, so replacing any one `_absent()` call with a +# bare `pytest.skip` would have left every required test green while restoring the +# silent green this act exists to remove. There are THREE of them, and the third +# arrived with the review of `cb84001` (the review of `b22a6fd` caught this header +# still saying two): +# 1. `opendox.view_extension` absent — the module is not there at all; +# 2. `view_extension.ViewBinding` absent — the module without its class, +# which was an AttributeError out of this guard until `cb84001`; +# 3. `ViewBinding` without RULED Q2's `exports` — the partial packaging +# regression: the registry present, the contract behind it. +# Each is driven BOTH ways below — FAIL at the commit this leg declares, SKIP for a +# different one — because a branch proved only at the declared pin can be replaced +# by an unconditional failure with every added test still green, and that breaks the +# consumer RULED 5700475319 protects. The direct `_absent()` tests in +# `tests/test_gate_loop_probes.py` prove what the guard DECIDES; these prove that +# this caller still asks it. +# --------------------------------------------------------------------------- + +_PIN_DECLARED = "a" * 40 +_PIN_OTHER = "b" * 40 + + +def _guard_reads(monkeypatch, declared, installed, *, ci=True): + import opendox_bundle + monkeypatch.setattr(opendox_bundle, "declared_pin", lambda: declared) + monkeypatch.setattr(opendox_bundle, "installed_commit", lambda: installed) + monkeypatch.setenv("CI", "true" if ci else "") + + +def _without_view_extension(monkeypatch): + """Make `from opendox import view_extension` raise ImportError. + + BOTH steps are needed and neither is enough: the attribute is deleted + because the package object already carries it once anything has imported it, + and the `sys.modules` entry is set to `None` because otherwise the submodule + is simply re-imported from disk. A `None` entry is the documented way to + make an import fail without touching the filesystem. + """ + import sys + import opendox + monkeypatch.delattr(opendox, "view_extension", raising=False) + monkeypatch.setitem(sys.modules, "opendox.view_extension", None) + + +def test_a_missing_view_extension_FAILS_at_the_declared_pin(monkeypatch) -> None: + """The ImportError branch, at the pin this leg declares, under CI.""" + _guard_reads(monkeypatch, _PIN_DECLARED, _PIN_DECLARED) + _without_view_extension(monkeypatch) + with pytest.raises(pytest.fail.Exception) as raised: + _view_extension_or_skip() + message = str(raised.value) + assert "REGRESSION at the declared pin" in message + assert "view_extension" in message + + +def test_a_missing_view_extension_SKIPS_for_a_different_installed_commit( + monkeypatch) -> None: + """...and the DIFFERENT-COMMIT reading that RULED 5700475319 rests on still holds. + + Not "older", and the thread on `24cd5f2` was right to say so twice: `_absent()` + compares two identities and never asks git which came first, so `b`*40 against + `a`*40 is a different assembly and nothing more. The ruling's own ground — an + assembly is free to install an openDox behind the view contract — is what this + skip serves, and it needs no ordering to hold. + """ + _guard_reads(monkeypatch, _PIN_DECLARED, _PIN_OTHER) + _without_view_extension(monkeypatch) + with pytest.raises(pytest.skip.Exception) as raised: + _view_extension_or_skip() + message = str(raised.value) + assert _PIN_DECLARED[:8] in message + assert _PIN_OTHER[:8] in message + + +def test_a_ViewBinding_without_exports_FAILS_at_the_declared_pin( + monkeypatch) -> None: + """The SECOND branch: the module imports, and RULED Q2's field is gone. + + This is the branch a partial packaging regression would take — the registry + present, the contract behind it — and it was the less obvious of the two to + leave unproven. + + THE MODULE COMES THROUGH THE HELPER, not `from opendox import view_extension`: + the review of `24cd5f2` caught that a bare import here raises ImportError for + exactly the consumer this helper exists to SKIP (a different openDox without + the module), turning a supported assembly into a hard failure inside the test + that proves the guard. This call is made BEFORE `_guard_reads()` patches + anything, so it is the real installed module or the real skip. + """ + view_extension = _view_extension_or_skip() + _guard_reads(monkeypatch, _PIN_DECLARED, _PIN_DECLARED) + monkeypatch.setattr(view_extension.ViewBinding, "__annotations__", {}) + with pytest.raises(pytest.fail.Exception) as raised: + _view_extension_or_skip() + assert "`exports` field" in str(raised.value) + + +def test_a_ViewBinding_without_exports_SKIPS_for_a_different_installed_commit( + monkeypatch) -> None: + """The SKIP half of the `exports` branch, at the CALL SITE. + + The declared-pin FAIL above and the generic `_absent()` tests would both stay + green if this call became an unconditional failure, and the consumer RULED + 5700475319 protects — an assembly pinning an openDox behind the view contract — + would break with them green. Caught at the review of `cb84001`. + """ + view_extension = _view_extension_or_skip() + _guard_reads(monkeypatch, _PIN_DECLARED, _PIN_OTHER) + monkeypatch.setattr(view_extension.ViewBinding, "__annotations__", {}) + with pytest.raises(pytest.skip.Exception) as raised: + _view_extension_or_skip() + message = str(raised.value) + assert _PIN_DECLARED[:8] in message + assert _PIN_OTHER[:8] in message + + +def test_a_view_extension_without_ViewBinding_FAILS_at_the_declared_pin( + monkeypatch) -> None: + """THE THIRD unsupported shape: the module imports, the CLASS is not there. + + It raised `AttributeError` before the review of `24cd5f2` — the one path out + of this guard that never reached `_absent()` — and an AttributeError three + frames from a dataclass is precisely what + `view_extensions.ViewContractUnsupported` exists to replace with a sentence. + """ + view_extension = _view_extension_or_skip() + _guard_reads(monkeypatch, _PIN_DECLARED, _PIN_DECLARED) + monkeypatch.delattr(view_extension, "ViewBinding") + with pytest.raises(pytest.fail.Exception) as raised: + _view_extension_or_skip() + message = str(raised.value) + assert "ViewBinding" in message + assert "REGRESSION at the declared pin" in message + + +def test_a_view_extension_without_ViewBinding_SKIPS_for_a_different_commit( + monkeypatch) -> None: + """...and the same branch at a DIFFERENT commit takes the ruled skip. + + The third unsupported shape has to be COMPATIBLE for a consumer behind the + view contract, exactly as the other two are; with only the FAIL case driven, + an unconditional failure here would pass every added test and break that + consumer. Caught at the review of `cb84001`. + """ + view_extension = _view_extension_or_skip() + _guard_reads(monkeypatch, _PIN_DECLARED, _PIN_OTHER) + monkeypatch.delattr(view_extension, "ViewBinding") + with pytest.raises(pytest.skip.Exception) as raised: + _view_extension_or_skip() + message = str(raised.value) + assert "ViewBinding" in message + assert _PIN_DECLARED[:8] in message + assert _PIN_OTHER[:8] in message