From a7c013a69560de336bcc6ce0af875c914602b36a Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 29 Sep 2026 18:34:37 -0400 Subject: [PATCH 1/4] Put every file that decides a gate verdict on the gate surface Since the receipt shim refactor (4a23e31, #116), the trust pins live in scripts/receipt_pins.py, but the gate surface still listed only the files that held them before. receipt's append gate calls a proposal gate-changing only when it touches gate_surface, so a resolver-shaped append that also edited the pins, or bumped receipt in pyproject.toml and uv.lock, was judged as plain data: accepted, and never named. Reproduced with the base gate invoked as the trusted CI job invokes it: 3dd95a0's gate accepted the release-20 append plus a receipt_pins.py edit as "+5 appended vs base, release 20", and #299's gate accepted #297's seven rows plus a pins edit as "+7 appended vs base, release 21". The surface now covers: - scripts/**: the judge runs a script there, so scripts/ is sys.path[0], and both pull request jobs also put it on PYTHONPATH. A new module there shadows imports (the standard library's included), and a sitecustomize.py runs at startup. Both were observed. - pyproject.toml and uv.lock, which pick the receipt version the judge runs, and uv.toml, .python-version and .venv/**, which uv also reads from the project it provisions the judge from. Each was observed to change what `uv sync --locked --no-dev --project ` and `uv run` do. The same candidates are now refused as mixed, naming the decider, while both pure appends still pass and a pins-only change is reported as gate-only. The resolver's proposals change only ledger/** and releases/manifests/**, so they stay data proposals. Tests: every decider is refused as mixed beside a witnessed append and named when changed alone; a pure append beside unchanged deciders passes; an audit-hook run shows every file the gate opens or imports from its own checkout is on the surface; and the shim's surface is pinned as a deliberate superset of the originals'. Co-Authored-By: Claude Opus 5.5 --- README.md | 7 +- scripts/receipt_pins.py | 22 +- tests/test_receipt_shim_transparency.py | 48 +++++ tests/test_thesis_append_shim_isolation.py | 237 +++++++++++++++++++++ 4 files changed, 309 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d65fb107..a428d531 100644 --- a/README.md +++ b/README.md @@ -571,4 +571,9 @@ environment. Verification machinery is consumed from the `receipt` package with this repository's trust pins committed in `scripts/receipt_pins.py`; see `releases/README.md` (immutable post-genesis, like everything under `releases/`) for the schema, offline -verification procedure, and security limits. +verification procedure, and security limits. The gate surface in that file +lists every base-checkout file that can decide a verdict: all of `scripts/`, +the append workflow, the anchors, and the uv inputs that build the gate's +environment (`pyproject.toml`, `uv.lock`, `uv.toml`, `.python-version`, +`.venv/`). The gate refuses a pull request that changes any of them together +with the ledger, and names them when a pull request changes only them. diff --git a/scripts/receipt_pins.py b/scripts/receipt_pins.py index 2136c758..ed1328ee 100644 --- a/scripts/receipt_pins.py +++ b/scripts/receipt_pins.py @@ -86,13 +86,27 @@ (f"releases/anchors/{LEDGER_SPEC.producer_public_key_filename}"), } ), + # Every file in the judging (base) checkout that can decide a verdict. A + # proposal that changes one of them together with the ledger is refused as + # mixed, and a proposal that changes only these is reported by name. gate_surface=frozenset( { - "scripts/check_thesis_facts_append.py", - "scripts/verify_release_chain.py", - "scripts/canonical_json.py", - "scripts/cut_release_manifest.py", + # The judge runs scripts/check_thesis_facts_append.py, so scripts/ + # is sys.path[0], and both pull request jobs also put it on + # PYTHONPATH. Any file there can decide the verdict: these pins, + # a module that shadows an import (the standard library's + # included), or a sitecustomize.py, which runs at startup. + "scripts/**", ".github/workflows/thesis-facts-append.yml", + # `uv sync --locked --no-dev --project ` builds the judge's + # environment from these, including the receipt version that + # implements the gate. uv also reads the project's uv.toml and + # .python-version, and reuses a .venv it finds there. + "pyproject.toml", + "uv.lock", + "uv.toml", + ".python-version", + ".venv/**", "releases/anchors/**", } ), diff --git a/tests/test_receipt_shim_transparency.py b/tests/test_receipt_shim_transparency.py index 99fccc19..095e5f19 100644 --- a/tests/test_receipt_shim_transparency.py +++ b/tests/test_receipt_shim_transparency.py @@ -113,6 +113,54 @@ def test_original_oracle_fixtures_are_authenticated(name: str) -> None: assert _sha256(ORIGINAL_FIXTURES / name) == ORIGINAL_HASHES[name] +def _original_surface(name: str) -> frozenset[str]: + """Read one surface literal from the authenticated original gate.""" + + import ast + + module = ast.parse( + (ORIGINAL_FIXTURES / "check_thesis_facts_append.py").read_text(encoding="utf-8") + ) + for node in module.body: + if ( + isinstance(node, ast.Assign) + and [getattr(target, "id", None) for target in node.targets] == [name] + and isinstance(node.value, ast.Call) + ): + return frozenset(ast.literal_eval(node.value.args[0])) + raise AssertionError(f"{name} not found in the original gate") + + +def test_the_shim_gate_surface_deliberately_widens_the_originals() -> None: + """The one place the pair is meant to disagree about classification. + + The originals' GATE_SURFACE predates scripts/receipt_pins.py, where the + shim's trust pins now live, and never listed the uv inputs that provision + the judge. The shim's surface covers every original entry and adds those, + so a proposal that changes one of them is refused as mixed (with rows) or + named as gate-only (alone), where the original judged it as plain data. + No case in this file changes such a file, so the byte-identity asserted + here is unaffected; tests/test_thesis_append_shim_isolation.py holds the + shim to the wider surface. + """ + + from receipt.append_gate import _matches_surface + + from scripts.receipt_pins import APPEND_GATE_SPEC + + original_gate = _original_surface("GATE_SURFACE") + shim_gate = APPEND_GATE_SPEC.gate_surface + for entry in original_gate: + if entry.endswith("/**"): + assert entry in shim_gate, entry + else: + assert _matches_surface(entry, shim_gate), entry + assert _original_surface("DATA_SURFACE") == APPEND_GATE_SPEC.data_surface + for widened in ("scripts/receipt_pins.py", "pyproject.toml", "uv.lock"): + assert not _matches_surface(widened, original_gate), widened + assert _matches_surface(widened, shim_gate), widened + + @pytest.fixture(scope="session") def original_oracle(tmp_path_factory: pytest.TempPathFactory) -> pathlib.Path: """Copy the authenticated original scripts into one executable tree.""" diff --git a/tests/test_thesis_append_shim_isolation.py b/tests/test_thesis_append_shim_isolation.py index 61e6d4c8..063d0223 100644 --- a/tests/test_thesis_append_shim_isolation.py +++ b/tests/test_thesis_append_shim_isolation.py @@ -57,6 +57,7 @@ def _subject_line(clone: pathlib.Path, candidate: str, base: str | None) -> str: line += f" base commit {base} tree {_git(clone, 'rev-parse', base + '^{tree}')}" return line + # A commit id of the right shape that no repository holds. ABSENT_OBJECT_ID = "0" * 40 @@ -942,6 +943,242 @@ def test_a_true_append_is_accepted_end_to_end(tmp_path): _assert_nothing_left_behind(clone, tmp_path / "tmp") +# Files that decide a verdict when they sit in the judging checkout, one per +# way in: the pins the shim imports, the uv inputs the workflow provisions the +# judge from, and files that are not there today but would be read if added. +# Until 2026-09-29 the first three were off the gate surface, so a resolver- +# shaped append that also edited them was judged as plain data and never named +# them (PolicyEngine/chronicle#299 review). +GATE_DECIDERS = ( + "scripts/receipt_pins.py", + "pyproject.toml", + "uv.lock", + "uv.toml", + ".python-version", + "scripts/sitecustomize.py", + ".venv/lib/python3.14/site-packages/zz_injected.pth", +) + + +def _change_gate_decider(relative: str): + """Return a mutation that changes one decider, or adds it if absent.""" + + def mutate(root: pathlib.Path) -> None: + path = root / relative + path.parent.mkdir(parents=True, exist_ok=True) + with path.open("a", encoding="utf-8") as handle: + handle.write("# a change riding the proposal\n") + + return mutate + + +def _copy_existing_gate_deciders(root: pathlib.Path) -> None: + """Put the repository's own copy of every decider it has into the base.""" + + for relative in GATE_DECIDERS: + source = ROOT / relative + if source.is_file(): + destination = root / relative + destination.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(source, destination) + + +@pytest.mark.parametrize("relative", GATE_DECIDERS) +def test_an_append_that_also_changes_a_gate_decider_is_refused_as_mixed( + tmp_path, relative +): + """The witnessed append plus one decider change cannot pass as data. + + The refusal comes before any ledger check and names the decider, so a trust + change can no longer ride an append that the resolver merges on its own. + """ + + clone, base, candidate = _replay_latest_release( + tmp_path, + prepare=_copy_existing_gate_deciders, + mutate=_change_gate_decider(relative), + ) + + completed = _run_shim( + clone, commit=candidate, base_ref=base, temporary_root=tmp_path / "tmp" + ) + + assert completed.returncode == 1, completed.stdout + completed.stderr + assert completed.stdout == "" + assert f"{FAILED}mixed data/gate proposal is forbidden: " in completed.stderr + assert ( + f"; GATE_SURFACE changes={[relative]!r}; split them into separate pull requests" + ) in completed.stderr + _assert_nothing_left_behind(clone, tmp_path / "tmp") + + +@pytest.mark.parametrize("relative", GATE_DECIDERS) +def test_a_gate_decider_change_alone_is_a_named_gate_only_proposal(tmp_path, relative): + clone, base = _replay_current_state(tmp_path) + _copy_existing_gate_deciders(clone) + base = _commit(clone, "deciders in the base") + _change_gate_decider(relative)(clone) + candidate = _commit(clone, f"change {relative}") + + completed = _run_shim( + clone, commit=candidate, base_ref=base, temporary_root=tmp_path / "tmp" + ) + + assert completed.returncode == 0, completed.stdout + completed.stderr + assert completed.stdout.splitlines() == [ + "thesis-facts append check OK: gate-only proposal; DATA_SURFACE " + f"unchanged; GATE_SURFACE changes={[relative]!r}", + _subject_line(clone, candidate, base), + ] + _assert_nothing_left_behind(clone, tmp_path / "tmp") + + +def test_an_append_beside_unchanged_gate_deciders_still_passes(tmp_path): + """The resolver's shape: ledger and release files only, deciders untouched.""" + + clone, base, candidate = _replay_latest_release( + tmp_path, prepare=_copy_existing_gate_deciders + ) + changed = set(_git(clone, "diff", "--name-only", base, candidate).splitlines()) + assert changed and all( + path.startswith(("ledger/", "releases/manifests/")) for path in changed + ), changed + + completed = _run_shim( + clone, commit=candidate, base_ref=base, temporary_root=tmp_path / "tmp" + ) + + assert completed.returncode == 0, completed.stdout + completed.stderr + assert completed.stdout == ( + f"{APPEND_GATE_OK}\n{_subject_line(clone, candidate, base)}\n" + ) + _assert_nothing_left_behind(clone, tmp_path / "tmp") + + +OPENED_FILES_DRIVER = """\ +import json +import os +import pathlib +import sys + +opened = set() + + +def _record(event, arguments): + if event == "open" and isinstance(arguments[0], (str, bytes, os.PathLike)): + opened.add(os.fsdecode(arguments[0])) + + +sys.addaudithook(_record) +sys.path.insert(0, {scripts!r}) + +import check_thesis_facts_append as shim # noqa: E402 + +try: + code = shim.main() +finally: + opened.update( + getattr(module, "__file__", None) or "" for module in list(sys.modules.values()) + ) + pathlib.Path({report!r}).write_text(json.dumps(sorted(opened)), encoding="utf-8") +raise SystemExit(code) +""" + + +def test_every_file_the_gate_reads_from_its_own_checkout_is_on_the_gate_surface( + tmp_path, +): + """The invariant behind GATE_SURFACE, measured on an accepting run. + + Every file the gate process opens or imports from inside the judging + checkout is on the surface. That is the pins, the gate's scripts, the + trust anchors, and the installed receipt wheel, which lives in the + checkout's own .venv just as it does in the workflow's base-gate clone. + """ + + from receipt.append_gate import _matches_surface + + from scripts.receipt_pins import APPEND_GATE_SPEC + + clone, base, candidate = _replay_latest_release(tmp_path) + report = tmp_path / "opened.json" + driver = tmp_path / "driver" / "driver.py" + driver.parent.mkdir() + driver.write_text( + OPENED_FILES_DRIVER.format(scripts=str(SHIM_SCRIPTS), report=str(report)), + encoding="utf-8", + ) + + completed = subprocess.run( + [ + sys.executable, + str(driver), + "--root", + str(clone), + "--commit", + candidate, + "--base-ref", + base, + ], + cwd=clone, + capture_output=True, + text=True, + check=False, + ) + assert completed.returncode == 0, completed.stdout + completed.stderr + + root = ROOT.resolve() + inside = set() + for name in json.loads(report.read_text(encoding="utf-8")): + if not name: + continue + path = pathlib.Path(name) + if not path.is_absolute(): + path = clone / path + resolved = path.resolve() + if resolved.is_relative_to(root): + inside.add(resolved.relative_to(root).as_posix()) + assert "scripts/receipt_pins.py" in inside + assert any(path.startswith("releases/anchors/") for path in inside), inside + off_surface = sorted( + path + for path in inside + if not _matches_surface(path, APPEND_GATE_SPEC.gate_surface) + ) + assert off_surface == [], off_surface + + +def test_the_gate_surface_covers_the_judges_import_path_and_environment(): + """What a run cannot show: files that would decide a verdict if added. + + The judge runs a script in scripts/, so scripts/ is sys.path[0], and both + pull request jobs also put it on PYTHONPATH, where a sitecustomize.py runs + at startup. The whole directory is therefore on the surface, not just the + files imported today. The judge's environment comes from the base's own + uv project, so its inputs are on the surface too. + """ + + from scripts.receipt_pins import APPEND_GATE_SPEC + + workflow = (ROOT / ".github" / "workflows" / "thesis-facts-append.yml").read_text( + encoding="utf-8" + ) + assert 'PYTHONPATH="$base_gate/scripts"' in workflow + assert 'uv sync --locked --no-dev --project "$base_gate"' in workflow + assert SHIM.parent.relative_to(ROOT).as_posix() == "scripts" + for required in ( + "scripts/**", + ".github/workflows/thesis-facts-append.yml", + "pyproject.toml", + "uv.lock", + "uv.toml", + ".python-version", + ".venv/**", + "releases/anchors/**", + ): + assert required in APPEND_GATE_SPEC.gate_surface, required + + def test_the_scratch_directory_is_private_to_the_run(tmp_path): """The private directory is created 0700, and the shim asserts that it was. From 8438230fb0ac54e46f086a6364cbd702efcb2102 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sun, 29 Nov 2026 07:26:42 -0500 Subject: [PATCH 2/4] Narrow the gate surface to the files the gate reads All of scripts/ on the surface would refuse a catalog-builder change shipped with the ledger/series_catalog.json it generates, as #128 did. The catalog tests require the two to land together, so that shape could not be split. The surface now lists the gate's own scripts and receipt_pins.py, plus the files that set up its interpreter and environment: scripts/sitecustomize.py, scripts/__pycache__/** (Python loads an unchecked-hash .pyc there in place of its source; observed), pyproject.toml, uv.lock, uv.toml, .python-version and .venv/**. A new module under scripts/ that shadows one of the gate's imports is now off the surface. A strict-xfail test records that limit; the fix is for the gate to stop importing from scripts/. Tests: a builder change beside an append stays a data proposal; the decider list gains the unchecked-hash .pyc; fixtures force-add the changed decider so an ignore file cannot drop it. Co-Authored-By: Claude Opus 5.5 --- README.md | 13 +-- scripts/receipt_pins.py | 32 ++++++-- tests/test_thesis_append_shim_isolation.py | 96 ++++++++++++++++++++-- 3 files changed, 119 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 74351fb5..1c3bc81f 100644 --- a/README.md +++ b/README.md @@ -560,8 +560,11 @@ package with this repository's trust pins committed in `scripts/receipt_pins.py`; see `releases/README.md` (immutable post-genesis, like everything under `releases/`) for the schema, offline verification procedure, and security limits. The gate surface in that file -lists every base-checkout file that can decide a verdict: all of `scripts/`, -the append workflow, the anchors, and the uv inputs that build the gate's -environment (`pyproject.toml`, `uv.lock`, `uv.toml`, `.python-version`, -`.venv/`). The gate refuses a pull request that changes any of them together -with the ledger, and names them when a pull request changes only them. +lists the base-checkout files the gate reads (its scripts, the trust pins, the +anchors and the append workflow), plus the files that set up its interpreter +and environment: `scripts/sitecustomize.py`, `scripts/__pycache__/`, +`pyproject.toml`, `uv.lock`, `uv.toml`, `.python-version` and `.venv/`. The +gate refuses a pull request that changes any of them together with the +ledger, and names them when a pull request changes only them. A new module +under `scripts/` that shadows one of the gate's imports is not on the surface +yet. diff --git a/scripts/receipt_pins.py b/scripts/receipt_pins.py index ed1328ee..13dd3442 100644 --- a/scripts/receipt_pins.py +++ b/scripts/receipt_pins.py @@ -86,17 +86,31 @@ (f"releases/anchors/{LEDGER_SPEC.producer_public_key_filename}"), } ), - # Every file in the judging (base) checkout that can decide a verdict. A - # proposal that changes one of them together with the ledger is refused as - # mixed, and a proposal that changes only these is reported by name. + # The files in the judging (base) checkout that the gate reads, and the + # files that set up its interpreter and environment. A proposal that + # changes one of them together with the ledger is refused as mixed, and a + # proposal that changes only these is reported by name. + # + # Not covered: a new module under scripts/ that shadows an import (a + # scripts/tempfile.py, or a scripts/receipt/ package). The judge runs a + # script there, so scripts/ is sys.path[0], and both pull request jobs + # also put it on PYTHONPATH. Listing all of scripts/ would close that, but + # it would also refuse a catalog-builder change shipped with its + # regenerated ledger/series_catalog.json (as in #128), which the catalog + # tests require to land together. The fix is for the gate to stop + # importing from scripts/. gate_surface=frozenset( { - # The judge runs scripts/check_thesis_facts_append.py, so scripts/ - # is sys.path[0], and both pull request jobs also put it on - # PYTHONPATH. Any file there can decide the verdict: these pins, - # a module that shadows an import (the standard library's - # included), or a sitecustomize.py, which runs at startup. - "scripts/**", + "scripts/check_thesis_facts_append.py", + "scripts/verify_release_chain.py", + "scripts/canonical_json.py", + "scripts/cut_release_manifest.py", + "scripts/receipt_pins.py", + # Python runs a sitecustomize.py it finds on PYTHONPATH at + # startup, and loads an unchecked-hash .pyc from __pycache__ in + # place of its source. + "scripts/sitecustomize.py", + "scripts/__pycache__/**", ".github/workflows/thesis-facts-append.yml", # `uv sync --locked --no-dev --project ` builds the judge's # environment from these, including the receipt version that diff --git a/tests/test_thesis_append_shim_isolation.py b/tests/test_thesis_append_shim_isolation.py index 063d0223..6cb6892c 100644 --- a/tests/test_thesis_append_shim_isolation.py +++ b/tests/test_thesis_append_shim_isolation.py @@ -946,9 +946,9 @@ def test_a_true_append_is_accepted_end_to_end(tmp_path): # Files that decide a verdict when they sit in the judging checkout, one per # way in: the pins the shim imports, the uv inputs the workflow provisions the # judge from, and files that are not there today but would be read if added. -# Until 2026-09-29 the first three were off the gate surface, so a resolver- -# shaped append that also edited them was judged as plain data and never named -# them (PolicyEngine/chronicle#299 review). +# Before PolicyEngine/chronicle#308 the first three were off the gate surface, +# so a resolver-shaped append that also edited them was judged as plain data +# and never named them (PolicyEngine/chronicle#299 review). GATE_DECIDERS = ( "scripts/receipt_pins.py", "pyproject.toml", @@ -956,6 +956,7 @@ def test_a_true_append_is_accepted_end_to_end(tmp_path): "uv.toml", ".python-version", "scripts/sitecustomize.py", + "scripts/__pycache__/receipt_pins.cpython-314.pyc", ".venv/lib/python3.14/site-packages/zz_injected.pth", ) @@ -972,6 +973,20 @@ def mutate(root: pathlib.Path) -> None: return mutate +def _force_add(relative: str): + """Stage one path even where an ignore file lists it. + + ``__pycache__`` and ``.venv`` are commonly ignored, and the default global + ignore file applies even with GIT_CONFIG_GLOBAL unset, so ``git add -A`` + alone could leave the decider out of the candidate. + """ + + def stage(root: pathlib.Path) -> None: + _git(root, "add", "--force", "--", relative) + + return stage + + def _copy_existing_gate_deciders(root: pathlib.Path) -> None: """Put the repository's own copy of every decider it has into the base.""" @@ -997,6 +1012,7 @@ def test_an_append_that_also_changes_a_gate_decider_is_refused_as_mixed( tmp_path, prepare=_copy_existing_gate_deciders, mutate=_change_gate_decider(relative), + mutate_index=_force_add(relative), ) completed = _run_shim( @@ -1018,7 +1034,7 @@ def test_a_gate_decider_change_alone_is_a_named_gate_only_proposal(tmp_path, rel _copy_existing_gate_deciders(clone) base = _commit(clone, "deciders in the base") _change_gate_decider(relative)(clone) - candidate = _commit(clone, f"change {relative}") + candidate = _commit(clone, f"change {relative}", _force_add(relative)) completed = _run_shim( clone, commit=candidate, base_ref=base, temporary_root=tmp_path / "tmp" @@ -1055,6 +1071,38 @@ def test_an_append_beside_unchanged_gate_deciders_still_passes(tmp_path): _assert_nothing_left_behind(clone, tmp_path / "tmp") +def test_an_append_beside_a_catalog_builder_change_is_still_data(tmp_path): + """A script the gate never reads stays off the surface. + + PolicyEngine/chronicle#128 shipped scripts/build_series_catalog.py with the + ledger/series_catalog.json it generates, and the catalog tests require the + two to land together. With all of scripts/ on the surface, that shape would + be refused as mixed and could not be split. + """ + + builder = "scripts/build_series_catalog.py" + + def prepare(root: pathlib.Path) -> None: + (root / "scripts").mkdir(exist_ok=True) + shutil.copyfile(ROOT / builder, root / builder) + + clone, base, candidate = _replay_latest_release( + tmp_path, prepare=prepare, mutate=_change_gate_decider(builder) + ) + changed = set(_git(clone, "diff", "--name-only", base, candidate).splitlines()) + assert builder in changed, changed + + completed = _run_shim( + clone, commit=candidate, base_ref=base, temporary_root=tmp_path / "tmp" + ) + + assert completed.returncode == 0, completed.stdout + completed.stderr + assert completed.stdout == ( + f"{APPEND_GATE_OK}\n{_subject_line(clone, candidate, base)}\n" + ) + _assert_nothing_left_behind(clone, tmp_path / "tmp") + + OPENED_FILES_DRIVER = """\ import json import os @@ -1153,11 +1201,15 @@ def test_the_gate_surface_covers_the_judges_import_path_and_environment(): The judge runs a script in scripts/, so scripts/ is sys.path[0], and both pull request jobs also put it on PYTHONPATH, where a sitecustomize.py runs - at startup. The whole directory is therefore on the surface, not just the - files imported today. The judge's environment comes from the base's own - uv project, so its inputs are on the surface too. + at startup. Python also loads an unchecked-hash .pyc from + scripts/__pycache__ in place of its source. The judge's environment comes + from the base's own uv project, so its inputs are on the surface too. The + rest of scripts/ is not: the catalog builder ships with the catalog it + generates. """ + from receipt.append_gate import _matches_surface + from scripts.receipt_pins import APPEND_GATE_SPEC workflow = (ROOT / ".github" / "workflows" / "thesis-facts-append.yml").read_text( @@ -1167,7 +1219,13 @@ def test_the_gate_surface_covers_the_judges_import_path_and_environment(): assert 'uv sync --locked --no-dev --project "$base_gate"' in workflow assert SHIM.parent.relative_to(ROOT).as_posix() == "scripts" for required in ( - "scripts/**", + "scripts/check_thesis_facts_append.py", + "scripts/verify_release_chain.py", + "scripts/canonical_json.py", + "scripts/cut_release_manifest.py", + "scripts/receipt_pins.py", + "scripts/sitecustomize.py", + "scripts/__pycache__/**", ".github/workflows/thesis-facts-append.yml", "pyproject.toml", "uv.lock", @@ -1177,6 +1235,28 @@ def test_the_gate_surface_covers_the_judges_import_path_and_environment(): "releases/anchors/**", ): assert required in APPEND_GATE_SPEC.gate_surface, required + assert not _matches_surface( + "scripts/build_series_catalog.py", APPEND_GATE_SPEC.gate_surface + ) + + +@pytest.mark.xfail( + strict=True, + reason=( + "open limit: a new module under scripts/ that shadows one of the gate's " + "imports is not on the gate surface; the fix is for the gate to stop " + "importing from scripts/" + ), +) +@pytest.mark.parametrize( + "shadow", ["scripts/tempfile.py", "scripts/receipt/__init__.py"] +) +def test_a_module_that_shadows_a_gate_import_is_on_the_gate_surface(shadow): + from receipt.append_gate import _matches_surface + + from scripts.receipt_pins import APPEND_GATE_SPEC + + assert _matches_surface(shadow, APPEND_GATE_SPEC.gate_surface) def test_the_scratch_directory_is_private_to_the_run(tmp_path): From e0f67345d07fe1193be99835cb75e741f9d0ac33 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 1 Dec 2026 11:43:40 -0500 Subject: [PATCH 3/4] Cover the bare surface directories and the judge's build inputs A "dir/**" entry matches only paths below dir, so a symlink committed at .venv or scripts/__pycache__ itself was unclassified and passed beside a ledger append. List each such directory bare as well, with a test that a symlink there is refused as mixed. Add the other files that decide the judge's environment or the anchor bytes it checks out: .python-versions, hatch.toml and hatch_build.py (uv installs this project with hatchling), a root sitecustomize.py (the editable install puts the root on sys.path), and .gitattributes and releases/.gitattributes. Record the limit that remains: a new module on the judge's import path, under scripts/ or at the root, and the project's own build inputs such as README.md. Running the judge isolated and without installing the project closes it. Pin the exact surface and the exact widening over the original gate in the tests, and let the shadowing xfail pass only on an AssertionError. Co-Authored-By: Claude Opus 5.5 --- README.md | 27 ++++-- scripts/receipt_pins.py | 56 +++++++++---- tests/test_receipt_shim_transparency.py | 37 ++++++-- tests/test_thesis_append_shim_isolation.py | 98 +++++++++++++++++++--- 4 files changed, 175 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 1c3bc81f..7d265ca4 100644 --- a/README.md +++ b/README.md @@ -559,12 +559,21 @@ environment. Verification machinery is consumed from the `receipt` package with this repository's trust pins committed in `scripts/receipt_pins.py`; see `releases/README.md` (immutable post-genesis, like everything under `releases/`) for the schema, offline -verification procedure, and security limits. The gate surface in that file -lists the base-checkout files the gate reads (its scripts, the trust pins, the -anchors and the append workflow), plus the files that set up its interpreter -and environment: `scripts/sitecustomize.py`, `scripts/__pycache__/`, -`pyproject.toml`, `uv.lock`, `uv.toml`, `.python-version` and `.venv/`. The -gate refuses a pull request that changes any of them together with the -ledger, and names them when a pull request changes only them. A new module -under `scripts/` that shadows one of the gate's imports is not on the surface -yet. +verification procedure, and security limits. The gate surface, +`APPEND_GATE_SPEC.gate_surface` in `scripts/receipt_pins.py`, lists the +files in the base checkout that decide the gate's verdict: + +- the gate's scripts, the trust pins, the anchors, and the append workflow; +- the files that build its interpreter and environment: `pyproject.toml`, + `uv.lock`, `uv.toml`, `.python-version`, `.python-versions`, `.venv`, + `hatch.toml`, `hatch_build.py`, `sitecustomize.py` (in `scripts/` and at + the root) and `scripts/__pycache__`; +- `.gitattributes` and `releases/.gitattributes`, which decide the anchor + bytes git checks out. + +The gate refuses a pull request that changes any of them together with the +ledger, and names them when a pull request changes only them. Not covered +yet: a new module on the judge's import path that shadows one of its imports, +under `scripts/` or at the root (the editable install adds the root), and the +project's own build inputs such as `README.md`. Closing that means running the +judge isolated (`python -I`) without installing this project. diff --git a/scripts/receipt_pins.py b/scripts/receipt_pins.py index 13dd3442..cedde0a6 100644 --- a/scripts/receipt_pins.py +++ b/scripts/receipt_pins.py @@ -86,19 +86,31 @@ (f"releases/anchors/{LEDGER_SPEC.producer_public_key_filename}"), } ), - # The files in the judging (base) checkout that the gate reads, and the - # files that set up its interpreter and environment. A proposal that + # The files in the judging (base) checkout that decide the gate's verdict: + # the gate's code and pins, the trust anchors, the files that build its + # interpreter and environment, and the append workflow. A proposal that # changes one of them together with the ledger is refused as mixed, and a - # proposal that changes only these is reported by name. + # proposal that changes only these is reported by name. A "dir/**" entry + # matches only paths below dir, so each one is also listed bare: otherwise + # a symlink or file committed at dir itself would be unclassified, and + # dropped on the data path. # - # Not covered: a new module under scripts/ that shadows an import (a - # scripts/tempfile.py, or a scripts/receipt/ package). The judge runs a - # script there, so scripts/ is sys.path[0], and both pull request jobs - # also put it on PYTHONPATH. Listing all of scripts/ would close that, but - # it would also refuse a catalog-builder change shipped with its - # regenerated ledger/series_catalog.json (as in #128), which the catalog - # tests require to land together. The fix is for the gate to stop - # importing from scripts/. + # Not covered: modules on the judge's import path that this list cannot + # name in advance. + # - The judge runs a script in scripts/, so scripts/ is sys.path[0], and + # both pull request jobs also put it on PYTHONPATH. A new module there + # shadows an import: a scripts/tempfile.py, a scripts/receipt/ package, + # or another spelling of sitecustomize or receipt_pins (a package, a + # sourceless .pyc, an extension module). + # - uv installs this project editable, and the .pth file that adds puts + # the repository root on sys.path. So a new module at the root, such as + # a sitecustomize/ package, can be imported at startup, and the editable + # build also reads README.md. + # Listing all of scripts/ would close the first, but it would also refuse + # a catalog-builder change shipped with its regenerated + # ledger/series_catalog.json (as in #128), which the catalog tests require + # to land together. The fix for both is in how the workflow runs the + # judge: isolated (python -I), without installing this project. gate_surface=frozenset( { "scripts/check_thesis_facts_append.py", @@ -106,21 +118,35 @@ "scripts/canonical_json.py", "scripts/cut_release_manifest.py", "scripts/receipt_pins.py", - # Python runs a sitecustomize.py it finds on PYTHONPATH at - # startup, and loads an unchecked-hash .pyc from __pycache__ in - # place of its source. + # Python runs a sitecustomize.py it finds on PYTHONPATH, or on + # the path the editable install adds, at startup, and loads an + # unchecked-hash .pyc from __pycache__ in place of its source. "scripts/sitecustomize.py", + "sitecustomize.py", + "scripts/__pycache__", "scripts/__pycache__/**", ".github/workflows/thesis-facts-append.yml", # `uv sync --locked --no-dev --project ` builds the judge's # environment from these, including the receipt version that # implements the gate. uv also reads the project's uv.toml and - # .python-version, and reuses a .venv it finds there. + # .python-version (or .python-versions), and reuses a .venv it + # finds there. It installs this project with hatchling, which + # reads hatch.toml and runs a hatch_build.py hook when one is + # configured. "pyproject.toml", "uv.lock", "uv.toml", ".python-version", + ".python-versions", + ".venv", ".venv/**", + "hatch.toml", + "hatch_build.py", + # Git applies these when it checks out the judge, so they decide + # the bytes of the anchors it pins. + ".gitattributes", + "releases/.gitattributes", + "releases/anchors", "releases/anchors/**", } ), diff --git a/tests/test_receipt_shim_transparency.py b/tests/test_receipt_shim_transparency.py index 095e5f19..55a86297 100644 --- a/tests/test_receipt_shim_transparency.py +++ b/tests/test_receipt_shim_transparency.py @@ -135,10 +135,12 @@ def test_the_shim_gate_surface_deliberately_widens_the_originals() -> None: """The one place the pair is meant to disagree about classification. The originals' GATE_SURFACE predates scripts/receipt_pins.py, where the - shim's trust pins now live, and never listed the uv inputs that provision - the judge. The shim's surface covers every original entry and adds those, - so a proposal that changes one of them is refused as mixed (with rows) or - named as gate-only (alone), where the original judged it as plain data. + shim's trust pins now live, and never listed the files that build the + judge's interpreter and environment or decide the anchor bytes it checks + out. The shim's surface covers every original entry and adds exactly + those, so a proposal that changes one of them is refused as mixed (with + rows) or named as gate-only (alone), where the original judged it as plain + data. No case in this file changes such a file, so the byte-identity asserted here is unaffected; tests/test_thesis_append_shim_isolation.py holds the shim to the wider surface. @@ -156,9 +158,30 @@ def test_the_shim_gate_surface_deliberately_widens_the_originals() -> None: else: assert _matches_surface(entry, shim_gate), entry assert _original_surface("DATA_SURFACE") == APPEND_GATE_SPEC.data_surface - for widened in ("scripts/receipt_pins.py", "pyproject.toml", "uv.lock"): - assert not _matches_surface(widened, original_gate), widened - assert _matches_surface(widened, shim_gate), widened + widened = { + "scripts/receipt_pins.py", + "scripts/sitecustomize.py", + "sitecustomize.py", + "scripts/__pycache__", + "scripts/__pycache__/**", + "pyproject.toml", + "uv.lock", + "uv.toml", + ".python-version", + ".python-versions", + ".venv", + ".venv/**", + "hatch.toml", + "hatch_build.py", + ".gitattributes", + "releases/.gitattributes", + "releases/anchors", + } + assert shim_gate - original_gate == widened + for entry in widened: + named = entry.removesuffix("/**") + assert not _matches_surface(named, original_gate), entry + assert _matches_surface(named, shim_gate), entry @pytest.fixture(scope="session") diff --git a/tests/test_thesis_append_shim_isolation.py b/tests/test_thesis_append_shim_isolation.py index 6cb6892c..13eeaeac 100644 --- a/tests/test_thesis_append_shim_isolation.py +++ b/tests/test_thesis_append_shim_isolation.py @@ -944,8 +944,9 @@ def test_a_true_append_is_accepted_end_to_end(tmp_path): # Files that decide a verdict when they sit in the judging checkout, one per -# way in: the pins the shim imports, the uv inputs the workflow provisions the -# judge from, and files that are not there today but would be read if added. +# way in: the pins the shim imports, the uv and hatchling inputs the workflow +# provisions the judge from, the attributes git checks the anchors out with, +# and files that are not there today but would be read if added. # Before PolicyEngine/chronicle#308 the first three were off the gate surface, # so a resolver-shaped append that also edited them was judged as plain data # and never named them (PolicyEngine/chronicle#299 review). @@ -955,11 +956,23 @@ def test_a_true_append_is_accepted_end_to_end(tmp_path): "uv.lock", "uv.toml", ".python-version", + ".python-versions", + "hatch.toml", + "hatch_build.py", "scripts/sitecustomize.py", + "sitecustomize.py", "scripts/__pycache__/receipt_pins.cpython-314.pyc", ".venv/lib/python3.14/site-packages/zz_injected.pth", + ".gitattributes", + "releases/.gitattributes", ) +# A "dir/**" entry matches only paths below dir, so these directories are also +# on the surface bare: a symlink committed in their place is a decider too. +# (releases/anchors is listed bare as well; the chain checks refuse a symlink +# there on their own.) +SURFACE_DIRECTORIES = (".venv", "scripts/__pycache__") + def _change_gate_decider(relative: str): """Return a mutation that changes one decider, or adds it if absent.""" @@ -1049,6 +1062,43 @@ def test_a_gate_decider_change_alone_is_a_named_gate_only_proposal(tmp_path, rel _assert_nothing_left_behind(clone, tmp_path / "tmp") +def _link_surface_directory(relative: str): + """Return a mutation that commits a symlink where a surface directory goes.""" + + def mutate(root: pathlib.Path) -> None: + path = root / relative + if path.is_symlink() or path.is_file(): + path.unlink() + elif path.exists(): + shutil.rmtree(path) + path.parent.mkdir(parents=True, exist_ok=True) + path.symlink_to("ledger" if "/" not in relative else "../ledger") + + return mutate + + +@pytest.mark.parametrize("relative", SURFACE_DIRECTORIES) +def test_an_append_beside_a_symlinked_surface_directory_is_refused_as_mixed( + tmp_path, relative +): + clone, base, candidate = _replay_latest_release( + tmp_path, + mutate=_link_surface_directory(relative), + mutate_index=_force_add(relative), + ) + assert _git(clone, "ls-tree", candidate, "--", relative).startswith("120000 ") + + completed = _run_shim( + clone, commit=candidate, base_ref=base, temporary_root=tmp_path / "tmp" + ) + + assert completed.returncode == 1, completed.stdout + completed.stderr + assert completed.stdout == "" + assert f"{FAILED}mixed data/gate proposal is forbidden: " in completed.stderr + assert f"GATE_SURFACE changes=[{relative!r}" in completed.stderr + _assert_nothing_left_behind(clone, tmp_path / "tmp") + + def test_an_append_beside_unchanged_gate_deciders_still_passes(tmp_path): """The resolver's shape: ledger and release files only, deciders untouched.""" @@ -1203,9 +1253,10 @@ def test_the_gate_surface_covers_the_judges_import_path_and_environment(): pull request jobs also put it on PYTHONPATH, where a sitecustomize.py runs at startup. Python also loads an unchecked-hash .pyc from scripts/__pycache__ in place of its source. The judge's environment comes - from the base's own uv project, so its inputs are on the surface too. The - rest of scripts/ is not: the catalog builder ships with the catalog it - generates. + from the base's own uv project, built with hatchling, so its inputs are on + the surface too, and git's attributes decide the anchor bytes it checks + out. The rest of scripts/ is not: the catalog builder ships with the + catalog it generates. """ from receipt.append_gate import _matches_surface @@ -1218,23 +1269,37 @@ def test_the_gate_surface_covers_the_judges_import_path_and_environment(): assert 'PYTHONPATH="$base_gate/scripts"' in workflow assert 'uv sync --locked --no-dev --project "$base_gate"' in workflow assert SHIM.parent.relative_to(ROOT).as_posix() == "scripts" - for required in ( + pyproject = (ROOT / "pyproject.toml").read_text(encoding="utf-8") + assert 'build-backend = "hatchling.build"' in pyproject + assert APPEND_GATE_SPEC.gate_surface == { "scripts/check_thesis_facts_append.py", "scripts/verify_release_chain.py", "scripts/canonical_json.py", "scripts/cut_release_manifest.py", "scripts/receipt_pins.py", "scripts/sitecustomize.py", + "sitecustomize.py", + "scripts/__pycache__", "scripts/__pycache__/**", ".github/workflows/thesis-facts-append.yml", "pyproject.toml", "uv.lock", "uv.toml", ".python-version", + ".python-versions", + ".venv", ".venv/**", + "hatch.toml", + "hatch_build.py", + ".gitattributes", + "releases/.gitattributes", + "releases/anchors", "releases/anchors/**", - ): - assert required in APPEND_GATE_SPEC.gate_surface, required + } + # Every "dir/**" entry is also listed bare, so dir itself is covered. + for pattern in APPEND_GATE_SPEC.gate_surface: + if pattern.endswith("/**"): + assert pattern[: -len("/**")] in APPEND_GATE_SPEC.gate_surface, pattern assert not _matches_surface( "scripts/build_series_catalog.py", APPEND_GATE_SPEC.gate_surface ) @@ -1242,14 +1307,23 @@ def test_the_gate_surface_covers_the_judges_import_path_and_environment(): @pytest.mark.xfail( strict=True, + raises=AssertionError, reason=( - "open limit: a new module under scripts/ that shadows one of the gate's " - "imports is not on the gate surface; the fix is for the gate to stop " - "importing from scripts/" + "open limit: a new module on the judge's import path (under scripts/, " + "or at the root through the editable install) that shadows one of its " + "imports is not on the gate surface; the fix is to run the judge " + "isolated (python -I) without installing this project" ), ) @pytest.mark.parametrize( - "shadow", ["scripts/tempfile.py", "scripts/receipt/__init__.py"] + "shadow", + [ + "scripts/tempfile.py", + "scripts/receipt/__init__.py", + "scripts/receipt_pins/__init__.py", + "scripts/sitecustomize/__init__.py", + "sitecustomize/__init__.py", + ], ) def test_a_module_that_shadows_a_gate_import_is_on_the_gate_surface(shadow): from receipt.append_gate import _matches_surface From c29e1de425431ab5e856e58f9f1be35b5f2238ed Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 1 Dec 2026 13:35:02 -0500 Subject: [PATCH 4/4] List the nested .gitattributes git applies to the judge Git applies scripts/.gitattributes, .github/.gitattributes and .github/workflows/.gitattributes when it checks out the judge. receipt 0.6.2 already refuses filter, ident and working-tree-encoding on every surface path at any depth, and Python reads either line ending, so none of the three can change a verdict today. Listing them keeps that from depending on the receipt version. A structural test now checks that every .gitattributes above a surface entry is on the surface. Co-Authored-By: Claude Opus 5.5 --- README.md | 9 +++++-- scripts/receipt_pins.py | 28 +++++++++++++++------- tests/test_receipt_shim_transparency.py | 7 ++++-- tests/test_thesis_append_shim_isolation.py | 24 +++++++++++++++---- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 7d265ca4..13771d6d 100644 --- a/README.md +++ b/README.md @@ -568,8 +568,13 @@ files in the base checkout that decide the gate's verdict: `uv.lock`, `uv.toml`, `.python-version`, `.python-versions`, `.venv`, `hatch.toml`, `hatch_build.py`, `sitecustomize.py` (in `scripts/` and at the root) and `scripts/__pycache__`; -- `.gitattributes` and `releases/.gitattributes`, which decide the anchor - bytes git checks out. +- every `.gitattributes` git applies to these files when it checks out the + judge: at the root and in `releases/`, which decide the anchor bytes, and + in `scripts/`, `.github/` and `.github/workflows/`. Receipt already refuses + `filter`, `ident` and `working-tree-encoding` on the gate's scripts and the + workflow, and line endings do not change how Python reads a script, so + these three cannot change a verdict today; listing them keeps that from + depending on the receipt version. The gate refuses a pull request that changes any of them together with the ledger, and names them when a pull request changes only them. Not covered diff --git a/scripts/receipt_pins.py b/scripts/receipt_pins.py index cedde0a6..cd2c8df2 100644 --- a/scripts/receipt_pins.py +++ b/scripts/receipt_pins.py @@ -88,12 +88,13 @@ ), # The files in the judging (base) checkout that decide the gate's verdict: # the gate's code and pins, the trust anchors, the files that build its - # interpreter and environment, and the append workflow. A proposal that - # changes one of them together with the ledger is refused as mixed, and a - # proposal that changes only these is reported by name. A "dir/**" entry - # matches only paths below dir, so each one is also listed bare: otherwise - # a symlink or file committed at dir itself would be unclassified, and - # dropped on the data path. + # interpreter and environment, the append workflow, and the .gitattributes + # files git applies to any of them. A proposal that changes one of them + # together with the ledger is refused as mixed, and a proposal that + # changes only these is reported by name. A "dir/**" entry matches only + # paths below dir, so each one is also listed bare: otherwise a symlink or + # file committed at dir itself would be unclassified, and dropped on the + # data path. # # Not covered: modules on the judge's import path that this list cannot # name in advance. @@ -142,10 +143,21 @@ ".venv/**", "hatch.toml", "hatch_build.py", - # Git applies these when it checks out the judge, so they decide - # the bytes of the anchors it pins. + # Git applies the .gitattributes in each directory above a file + # when it checks out the judge, so every one above an entry here + # is listed. The root and releases/ files decide the bytes of the + # anchors the judge pins. The scripts/ file reaches the gate's + # Python, and the .github/ files reach no entry here but the + # workflow, which the judge does not read. Receipt refuses filter, + # ident and working-tree-encoding on every surface path, and + # Python reads either line ending, so these three cannot change a + # verdict today. They are listed so that this does not depend on + # the receipt version. ".gitattributes", "releases/.gitattributes", + "scripts/.gitattributes", + ".github/.gitattributes", + ".github/workflows/.gitattributes", "releases/anchors", "releases/anchors/**", } diff --git a/tests/test_receipt_shim_transparency.py b/tests/test_receipt_shim_transparency.py index 55a86297..20962e0d 100644 --- a/tests/test_receipt_shim_transparency.py +++ b/tests/test_receipt_shim_transparency.py @@ -136,8 +136,8 @@ def test_the_shim_gate_surface_deliberately_widens_the_originals() -> None: The originals' GATE_SURFACE predates scripts/receipt_pins.py, where the shim's trust pins now live, and never listed the files that build the - judge's interpreter and environment or decide the anchor bytes it checks - out. The shim's surface covers every original entry and adds exactly + judge's interpreter and environment or the .gitattributes git checks it + out with. The shim's surface covers every original entry and adds exactly those, so a proposal that changes one of them is refused as mixed (with rows) or named as gate-only (alone), where the original judged it as plain data. @@ -175,6 +175,9 @@ def test_the_shim_gate_surface_deliberately_widens_the_originals() -> None: "hatch_build.py", ".gitattributes", "releases/.gitattributes", + "scripts/.gitattributes", + ".github/.gitattributes", + ".github/workflows/.gitattributes", "releases/anchors", } assert shim_gate - original_gate == widened diff --git a/tests/test_thesis_append_shim_isolation.py b/tests/test_thesis_append_shim_isolation.py index 13eeaeac..b03809e7 100644 --- a/tests/test_thesis_append_shim_isolation.py +++ b/tests/test_thesis_append_shim_isolation.py @@ -945,7 +945,7 @@ def test_a_true_append_is_accepted_end_to_end(tmp_path): # Files that decide a verdict when they sit in the judging checkout, one per # way in: the pins the shim imports, the uv and hatchling inputs the workflow -# provisions the judge from, the attributes git checks the anchors out with, +# provisions the judge from, the attributes git checks the judge out with, # and files that are not there today but would be read if added. # Before PolicyEngine/chronicle#308 the first three were off the gate surface, # so a resolver-shaped append that also edited them was judged as plain data @@ -965,6 +965,9 @@ def test_a_true_append_is_accepted_end_to_end(tmp_path): ".venv/lib/python3.14/site-packages/zz_injected.pth", ".gitattributes", "releases/.gitattributes", + "scripts/.gitattributes", + ".github/.gitattributes", + ".github/workflows/.gitattributes", ) # A "dir/**" entry matches only paths below dir, so these directories are also @@ -1254,9 +1257,9 @@ def test_the_gate_surface_covers_the_judges_import_path_and_environment(): at startup. Python also loads an unchecked-hash .pyc from scripts/__pycache__ in place of its source. The judge's environment comes from the base's own uv project, built with hatchling, so its inputs are on - the surface too, and git's attributes decide the anchor bytes it checks - out. The rest of scripts/ is not: the catalog builder ships with the - catalog it generates. + the surface too, and so is every .gitattributes git applies to a surface + file when it checks the judge out. The rest of scripts/ is not: the + catalog builder ships with the catalog it generates. """ from receipt.append_gate import _matches_surface @@ -1293,6 +1296,9 @@ def test_the_gate_surface_covers_the_judges_import_path_and_environment(): "hatch_build.py", ".gitattributes", "releases/.gitattributes", + "scripts/.gitattributes", + ".github/.gitattributes", + ".github/workflows/.gitattributes", "releases/anchors", "releases/anchors/**", } @@ -1300,6 +1306,16 @@ def test_the_gate_surface_covers_the_judges_import_path_and_environment(): for pattern in APPEND_GATE_SPEC.gate_surface: if pattern.endswith("/**"): assert pattern[: -len("/**")] in APPEND_GATE_SPEC.gate_surface, pattern + # Every .gitattributes above a surface entry is on the surface; one inside + # a "dir/**" entry is covered by that entry. + for pattern in APPEND_GATE_SPEC.gate_surface: + parts = pattern.removesuffix("/**").split("/") + for depth in range(len(parts)): + attributes = "/".join((*parts[:depth], ".gitattributes")) + assert _matches_surface(attributes, APPEND_GATE_SPEC.gate_surface), ( + pattern, + attributes, + ) assert not _matches_surface( "scripts/build_series_catalog.py", APPEND_GATE_SPEC.gate_surface )