Skip to content

Commit e4199ec

Browse files
committed
P-037 Phase B / B1-F2-F4-R2: close the carve-out invariant generically
11f08d5 fixed the concrete dump.rs omission but left the CLASS of defect open: nothing derived expected INSTRUMENT_CARVE_OUTS from production_diff_ gate.rust's own mutable_items/mutable_files/unit (plus the extractor's unit), so a future widening -- e.g. adding src/render.rs to mutable_items without a matching carve-out -- would recreate the identical instrument/ treatment collision under a new filename and escape both the recorded-unit cross-check and a selftest that only knows today's three files by name. _record_closure_problems() now derives the expected Rust treatment set directly from the epoch record already in hand (no new runtime import of either diff-gate module -- their mutable_items/mutable_files/unit are already present in what epoch_record() reads) plus the extractor's own whole-unit carve-out, deliberately EXCLUDING production_diff_gate.rust. controls (tests/ is a different concept: production-gate churn, never Phase-B treatment provenance), and requires the derived set to equal INSTRUMENT_CARVE_OUTS exactly -- catching both a missing carve-out and an unjustified excess one, only once both recorded units are already confirmed correct (avoiding cascading noise from a bogus prefix). Hostile selftest, against a deep copy of the real committed epoch record: injecting a hypothetical src/render.rs mutable_items entry with no carve- out is refused; removing dump.rs's own entry (making its carve-out newly excess) is refused too. The real, current epoch record closes cleanly. Zero production semantics. Both diff gates report IDENTICAL against 3ac13fd; ruff, mypy, and the full test suite are clean. Touches exactly scripts/p037_evidence_b.py. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AN6xHbpovxrmZ4AMjS7WQA
1 parent 11f08d5 commit e4199ec

1 file changed

Lines changed: 80 additions & 3 deletions

File tree

‎scripts/p037_evidence_b.py‎

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
from __future__ import annotations
6969

7070
import argparse
71+
import copy
7172
import json
7273
import shutil
7374
import sys
@@ -286,7 +287,34 @@ def _record_closure_problems(doc: dict[str, Any]) -> list[str]:
286287
missing or names a different unit is exactly the same self-
287288
authorization hole B1-F1 found and fixed for the Rust side (check() must
288289
never trust a recorded allowlist the module itself did not also
289-
hard-code), now closed for the extractor from the start."""
290+
hard-code), now closed for the extractor from the start.
291+
292+
B1-F2-F4-R2 adds a third, GENERIC check, closing the CLASS of defect the
293+
dump.rs omission belonged to rather than only that one instance: every
294+
file `production_diff_gate.rust` names as carrying a mutable item
295+
(`mutable_items`) or being wholly mutable (`mutable_files`), plus the
296+
extractor's own whole-unit carve-out, is DERIVED from the epoch record
297+
already in hand and required to equal `INSTRUMENT_CARVE_OUTS` (hence
298+
`TREATMENT_PATHS`, the same tuple) EXACTLY -- not a subset check. A
299+
future item added to `mutable_items` with no matching carve-out (the
300+
dump.rs defect, generalized to any filename) is refused as MISSING; a
301+
carve-out left behind after its last mutable item is retired is refused
302+
as EXCESS -- an unjustified exclusion is also a false claim about what
303+
the instrument does not need to see, not merely over-caution.
304+
`production_diff_gate.rust.controls` (e.g. `tests/`) is deliberately
305+
EXCLUDED from this derivation: it names files the item-level PRODUCTION
306+
gate already permits to move for a different reason entirely (test/
307+
control churn, never Phase-B treatment provenance) -- folding it in
308+
would either wrongly demand `tests/` be carved out of the instrument or
309+
let a real treatment addition hide behind the controls list. No new
310+
runtime import of either diff-gate module is needed or added: their own
311+
`mutable_items`/`mutable_files`/`unit` are already present in the epoch
312+
record `epoch_record()` reads from the frozen commit, which is what
313+
this function is handed -- the gate modules themselves are not imported
314+
or executed here. The derived-set comparison only runs once both units
315+
are already confirmed correct above; a wrong unit is reported as that
316+
one root problem, not as a cascade of "everything is missing" noise
317+
computed from a bogus prefix."""
290318
problems: list[str] = []
291319
gate = doc.get("production_diff_gate", {})
292320
rust = gate.get("rust", {}) if isinstance(gate, dict) else {}
@@ -299,13 +327,39 @@ def _record_closure_problems(doc: dict[str, Any]) -> list[str]:
299327
if recorded_extractor_unit != "frontend/roslyn/OwnSharp.Extractor/":
300328
problems.append(f"the epoch record's production_diff_gate.extractor.unit "
301329
f"{recorded_extractor_unit!r} differs from this module's own")
330+
331+
if (recorded_unit == "rust/crates/own-bridge/"
332+
and recorded_extractor_unit == "frontend/roslyn/OwnSharp.Extractor/"):
333+
expected_carve_outs: set[str] = {recorded_extractor_unit}
334+
mutable_items = rust.get("mutable_items", {})
335+
if isinstance(mutable_items, dict):
336+
expected_carve_outs.update(
337+
recorded_unit + name for name in mutable_items if isinstance(name, str))
338+
mutable_files = rust.get("mutable_files", [])
339+
if isinstance(mutable_files, list):
340+
expected_carve_outs.update(
341+
recorded_unit + name for name in mutable_files if isinstance(name, str))
342+
actual_carve_outs = set(INSTRUMENT_CARVE_OUTS)
343+
for path in sorted(expected_carve_outs - actual_carve_outs):
344+
problems.append(
345+
f"production_diff_gate authorizes {path!r} as a mutable treatment "
346+
"file/unit, but it is not in INSTRUMENT_CARVE_OUTS -- it would still "
347+
"be inside the Phase-B instrument closure")
348+
for path in sorted(actual_carve_outs - expected_carve_outs):
349+
problems.append(
350+
f"INSTRUMENT_CARVE_OUTS carves out {path!r}, but no production_diff_gate "
351+
"mutable_items/mutable_files/unit entry justifies it any more")
302352
return problems
303353

304354

305355
def closure_problems(*, repo: Path = ROOT) -> list[str]:
306356
"""Static self-check: every repo-local runtime path is in the closure,
307-
the carve-outs are treatment under instrument roots, and HEAD's epoch
308-
record agrees with this module on the production-diff gate's unit."""
357+
the carve-outs are treatment under instrument roots, HEAD's epoch
358+
record agrees with this module on both production-diff gates' units,
359+
and (see _record_closure_problems) the epoch record's own mutable-item/
360+
mutable-file/unit declarations derive EXACTLY this module's
361+
INSTRUMENT_CARVE_OUTS -- catching a future widened allowlist with no
362+
matching carve-out generically, not only by filename."""
309363
problems: list[str] = []
310364
for path in RUNTIME_REPO_PATHS:
311365
if not _covered(path, SUBJECT_PATHS):
@@ -656,6 +710,29 @@ def selftest() -> int:
656710
_selfcheck("comparison-problems-catches-instrument-identity-mismatch",
657711
any("instrument identities differ" in p for p in problems), problems)
658712

713+
# B1-F2-F4-R2: the GENERIC carve-out/mutable-item invariant, proven
714+
# against a DEEP COPY of the real, committed epoch record (never a
715+
# hand-built shape that could silently drift from the real one) --
716+
# closing the CLASS of defect the dump.rs omission belonged to, not
717+
# only that one filename. See _record_closure_problems's own docstring.
718+
real_doc = epoch_record("HEAD")
719+
_selfcheck("current-real-epoch-record-closes-cleanly",
720+
not _record_closure_problems(real_doc), _record_closure_problems(real_doc))
721+
722+
hostile_missing = copy.deepcopy(real_doc)
723+
hostile_missing["production_diff_gate"]["rust"]["mutable_items"]["src/render.rs"] = ["fn foo"]
724+
problems = _record_closure_problems(hostile_missing)
725+
_selfcheck("hostile-mutable-item-with-no-matching-carve-out-is-refused",
726+
any("render.rs" in p and "is not in INSTRUMENT_CARVE_OUTS" in p for p in problems),
727+
problems)
728+
729+
hostile_excess = copy.deepcopy(real_doc)
730+
del hostile_excess["production_diff_gate"]["rust"]["mutable_items"]["src/dump.rs"]
731+
problems = _record_closure_problems(hostile_excess)
732+
_selfcheck("hostile-excess-carve-out-with-no-backing-mutable-item-is-refused",
733+
any("dump.rs" in p and "no production_diff_gate" in p for p in problems),
734+
problems)
735+
659736
if _failures:
660737
print(f"RESULT: {_failures} check(s) failed")
661738
return 1

0 commit comments

Comments
 (0)