Skip to content

Commit 196dbd5

Browse files
committed
ci: make the five post-removal checks name no removed file
Five checks failed on the fixture-less tree by demanding a file the private-fixture PR removes. Each now treats exactly the pinned private set as allowed-absent with a named reason, and stays exact everywhere else: * check_oracle_sha256.py: the pin (tests/oracle.sha256) moves to schema v2, naming the three removed oracle sources under privateFixtureAbsent and pinning the aggregate hash of the remaining tree (treeSha256WithoutPrivate). Present files must match their pinned hashes, unpinned files fail, and a restored private file with other bytes is still "content changed". * check_oracle_twin_census.py: a missing oracle fails unless it is one of the three; the CHECK counts and exact-include rules are enforced unchanged for every oracle the tree carries. * check_native_feature_rulings.py: a ruled consumer that is absent is a named skip when its row (or a _l4* twin row) is pinned in tests/private_fixture_rows.txt, a finding otherwise; present consumers and a tree without the pin file keep the previous fail-closed behaviour. * check_twin_parity.py: an A29 family whose base source the PR removed is skipped with a named reason instead of "missing A29 twin"; enforced as before when the file is present. This is also what unblocked the real source-guard-twin-parity stage, and with it the test_ci_verify driver rows. * scripts/test_oracle_fixture_checks.py is new: eight controls that build a synthetic repo root from this tree and run the two oracle checks for real, one green and seven must-fail cases.
1 parent 86d8f45 commit 196dbd5

6 files changed

Lines changed: 318 additions & 20 deletions

‎scripts/check_native_feature_rulings.py‎

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,47 @@ def parse_rulings(adr_text: str) -> list[Ruling]:
168168
return rulings
169169

170170

171+
def private_fixture_rows(root: Path) -> frozenset[str]:
172+
"""The pinned private-fixture ctest rows (tests/private_fixture_rows.txt)."""
173+
path = root / "tests" / "private_fixture_rows.txt"
174+
if not path.is_file():
175+
return frozenset()
176+
return frozenset(line.strip() for line in path.read_text().splitlines()
177+
if line.strip() and not line.startswith("//"))
178+
179+
180+
def private_consumer(root: Path, path: str) -> bool:
181+
"""True when a consumer path names a source the private-fixture PR removes.
182+
183+
A path like tests/test_native_price_grid.cpp is private when the row it
184+
registers (test_native_price_grid, or its _l4* switched-route twin) is
185+
pinned in tests/private_fixture_rows.txt. A tree without that file -- the
186+
mutation self-test's synthetic inputs -- has no private consumers, so the
187+
check keeps failing closed there.
188+
"""
189+
rows = private_fixture_rows(root)
190+
if not rows:
191+
return False
192+
stem = Path(path).stem
193+
return bool(re.fullmatch(r"[A-Za-z0-9_]+", stem)) and (
194+
stem in rows or any(re.fullmatch(re.escape(stem) + r"_l4\w*", row) for row in rows))
195+
196+
197+
def default_private_consumer(path: str) -> bool:
198+
return private_consumer(ROOT, path)
199+
200+
171201
def check(header_text: str, adapter_text: str, adr_text: str, source_layer_text: str,
172-
read_file: Callable[[str], str | None]) -> list[str]:
173-
"""Findings for one tree; shape errors propagate."""
202+
read_file: Callable[[str], str | None],
203+
is_private: Callable[[str], bool] = default_private_consumer) -> list[str]:
204+
"""Findings for one tree; shape errors propagate.
205+
206+
A ruled consumer the tree does not carry is named in the skip report, not
207+
a finding, when it is one of the private-fixture rows; the same path is
208+
checked exactly as before whenever it is present, and it still satisfies a
209+
native-only ruling's tests/ requirement (the row that reads it is the
210+
pinned private-fixture row).
211+
"""
174212
fields = spec_fields(header_text)
175213
declared = adapter_declared(adapter_text, fields)
176214
findings: list[str] = []
@@ -207,6 +245,8 @@ def check(header_text: str, adapter_text: str, adr_text: str, source_layer_text:
207245
for path in ruling.consumers:
208246
text = read_file(path)
209247
if text is None:
248+
if is_private(path):
249+
continue # named in the skip report, not a finding
210250
findings.append(f"{name}: consumer {path} does not exist")
211251
continue
212252
for field in ruling.fields:
@@ -254,10 +294,13 @@ def read_file(relative: str) -> str | None:
254294
return 2
255295
try:
256296
source_layer_text = read_source_layer(root)
257-
findings = check(header_text, adapter_text, adr_text, source_layer_text, read_file)
297+
findings = check(header_text, adapter_text, adr_text, source_layer_text, read_file,
298+
is_private=lambda path: private_consumer(root, path))
258299
fields = spec_fields(header_text)
259300
declared = adapter_declared(adapter_text, fields)
260301
rulings = parse_rulings(adr_text)
302+
skipped = sorted({path for ruling in rulings for path in ruling.consumers
303+
if read_file(path) is None and private_consumer(root, path)})
261304
except ShapeError as error:
262305
print(f"check_native_feature_rulings: {error}", file=sys.stderr)
263306
return 1
@@ -273,7 +316,8 @@ def read_file(relative: str) -> str | None:
273316
print(f"check_native_feature_rulings: {len(fields)} NativeRunSpec fields, {len(declared)} declared by "
274317
f"the adapter's project(), {len(fields) - len(declared)} ruled ("
275318
+ ", ".join(f"{counts[kind]} {kind}" for kind in RULING_KINDS)
276-
+ "), every ruling backed by an executed native consumer")
319+
+ "), every ruling backed by an executed native consumer"
320+
+ (", private fixtures not present: " + ", ".join(skipped) if skipped else ""))
277321
return 0
278322

279323

‎scripts/check_oracle_sha256.py‎

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
#!/usr/bin/env python3
2-
"""Check the recorded SHA-256 tree pin for the frozen L0 oracle sources."""
2+
"""Check the recorded SHA-256 tree pin for the frozen L0 oracle sources.
3+
4+
The private-fixture PR removes three oracle sources (their rows are pinned in
5+
tests/private_fixture_rows.txt): test_oracle_day_key.cpp,
6+
test_oracle_reversal_same_bar_tx.cpp and test_oracle_stop_snapshot.cpp. The
7+
pin, tests/oracle.sha256, names them under ``privateFixtureAbsent`` and pins a
8+
second aggregate hash, ``treeSha256WithoutPrivate``, computed over exactly the
9+
files that remain when they are absent. Either shape is enforced exactly:
10+
11+
* every present file must be pinned and match its hash (a mutated oracle
12+
fails), an unpinned file present fails, and a removed pinned file that is
13+
not one of the three named private ones fails;
14+
* the aggregate tree hash must match the full ``treeSha256`` when every
15+
pinned file is present (an overlay carrying the private tree is verified
16+
too), or ``treeSha256WithoutPrivate`` when exactly the named private files
17+
are absent. Any other subset is drift.
18+
19+
The three private files are still verified hash-for-hash whenever they are
20+
present, so the fixture-less and overlay shapes are both pinned, never
21+
weakened to an always-pass.
22+
"""
323
from __future__ import annotations
424

525
import hashlib
@@ -10,28 +30,66 @@
1030
ROOT = Path(__file__).resolve().parents[1]
1131
ORACLE = ROOT / "tests" / "oracle"
1232
PIN = ROOT / "tests" / "oracle.sha256"
33+
SCHEMAS = ("pineforge-r4-d-oracle-tree/v1", "pineforge-r4-d-oracle-tree/v2")
1334

1435

15-
def digest_tree() -> tuple[dict[str, str], str]:
16-
files = {
36+
def digest_files(files: dict[str, str]) -> str:
37+
material = "".join(name + "\0" + value + "\n" for name, value in files.items()).encode()
38+
return hashlib.sha256(material).hexdigest()
39+
40+
41+
def digest_tree() -> dict[str, str]:
42+
return {
1743
str(path.relative_to(ORACLE)): hashlib.sha256(path.read_bytes()).hexdigest()
1844
for path in sorted(ORACLE.rglob("*")) if path.is_file()
1945
}
20-
material = "".join(name + "\0" + value + "\n" for name, value in files.items()).encode()
21-
return files, hashlib.sha256(material).hexdigest()
2246

2347

2448
def main() -> int:
2549
try:
2650
pin = json.loads(PIN.read_text())
2751
except (OSError, json.JSONDecodeError) as error:
2852
raise SystemExit("oracle SHA-256 pin: cannot read pin: " + str(error))
29-
files, tree = digest_tree()
30-
if pin.get("schema") != "pineforge-r4-d-oracle-tree/v1":
53+
if pin.get("schema") not in SCHEMAS:
3154
raise SystemExit("oracle SHA-256 pin: unexpected schema")
32-
if pin.get("files") != files or pin.get("treeSha256") != tree:
33-
raise SystemExit("oracle SHA-256 pin: tests/oracle tree drift")
34-
print(f"oracle SHA-256 pin: {len(files)} files, {tree}, OK")
55+
pinned = pin.get("files")
56+
if not isinstance(pinned, dict) or not pinned:
57+
raise SystemExit("oracle SHA-256 pin: pin has no files")
58+
private_absent = pin.get("privateFixtureAbsent", [])
59+
if not isinstance(private_absent, list) or not all(isinstance(name, str) for name in private_absent):
60+
raise SystemExit("oracle SHA-256 pin: privateFixtureAbsent must be a list of names")
61+
private_absent = sorted(private_absent)
62+
files = digest_tree()
63+
unexpected = sorted(set(files) - set(pinned))
64+
if unexpected:
65+
raise SystemExit("oracle SHA-256 pin: tests/oracle tree drift (unpinned file: "
66+
+ unexpected[0] + ")")
67+
missing = sorted(set(pinned) - set(files))
68+
undeclared = [name for name in missing if name not in private_absent]
69+
if undeclared:
70+
raise SystemExit("oracle SHA-256 pin: tests/oracle tree drift (missing pinned file: "
71+
+ undeclared[0] + ")")
72+
for name, digest in files.items():
73+
if digest != pinned[name]:
74+
raise SystemExit("oracle SHA-256 pin: tests/oracle tree drift (content changed: "
75+
+ name + ")")
76+
if not missing:
77+
tree = digest_files(files)
78+
if pin.get("treeSha256") != tree:
79+
raise SystemExit("oracle SHA-256 pin: tests/oracle tree drift")
80+
detail = f"{len(files)} files, {tree}"
81+
elif missing == private_absent:
82+
tree = digest_files(files)
83+
if pin.get("treeSha256WithoutPrivate") != tree:
84+
raise SystemExit("oracle SHA-256 pin: tests/oracle tree drift "
85+
"(private-fixture-absent tree hash changed)")
86+
detail = (f"private fixtures not present: "
87+
+ ", ".join("tests/oracle/" + name for name in missing)
88+
+ f"; {len(files)} files, {tree}")
89+
else:
90+
raise SystemExit("oracle SHA-256 pin: tests/oracle tree drift (partial private "
91+
"fixture removal: missing " + ", ".join(missing) + ")")
92+
print(f"oracle SHA-256 pin: {detail}, OK")
3593
return 0
3694

3795

‎scripts/check_oracle_twin_census.py‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,30 @@ def check_count(path: Path) -> int:
6363
if not DEFINE.match(line))
6464

6565

66+
# The oracle sources the private-fixture PR removes (their rows are pinned in
67+
# tests/private_fixture_rows.txt: test_native_oracle_day_key_l2,
68+
# test_native_oracle_reversal_same_bar_tx_l2, test_oracle_day_key,
69+
# test_oracle_reversal_same_bar_tx, test_oracle_stop_snapshot and
70+
# test_native_oracle_stop_snapshot_full_l2). They are allowed to be absent --
71+
# named in the output -- and are censused exactly like the rest whenever they
72+
# are present (an overlay carrying the private tree is verified too). Any other
73+
# missing oracle, any unpinned oracle, a changed CHECK count or a twin that no
74+
# longer includes exactly its oracle still fails.
75+
PRIVATE_FIXTURE_ORACLES = ("test_oracle_day_key", "test_oracle_reversal_same_bar_tx",
76+
"test_oracle_stop_snapshot")
77+
78+
6679
def main() -> int:
6780
actual = {path.stem: path for path in ORACLE.glob("test_oracle_*.cpp")}
68-
if set(actual) != set(TWINS) or set(actual) != set(EXPECTED_CHECKS):
69-
raise SystemExit("oracle twin census: oracle/twin inventory drift")
81+
unexpected = sorted(set(actual) - set(TWINS) | set(actual) - set(EXPECTED_CHECKS))
82+
if unexpected:
83+
raise SystemExit("oracle twin census: oracle/twin inventory drift (unpinned oracle: "
84+
+ unexpected[0] + ")")
85+
missing = sorted(set(TWINS) - set(actual))
86+
undeclared = [name for name in missing if name not in PRIVATE_FIXTURE_ORACLES]
87+
if undeclared:
88+
raise SystemExit("oracle twin census: oracle/twin inventory drift (missing oracle: "
89+
+ undeclared[0] + ")")
7090
total = 0
7191
for name, oracle in sorted(actual.items()):
7292
count = check_count(oracle)
@@ -82,7 +102,11 @@ def main() -> int:
82102
if re.search(r"\bint\s+main\s*\(|\bCHECK\s*\(", text):
83103
raise SystemExit("oracle twin census: hand-copied body remains in " + twin.name)
84104
total += count
85-
print(f"oracle twin census: {len(actual)} exact includes, {total} CHECK calls, OK")
105+
detail = f"{len(actual)} exact includes, {total} CHECK calls"
106+
if missing:
107+
detail += (", private fixtures not present: "
108+
+ ", ".join("tests/oracle/" + name + ".cpp" for name in missing))
109+
print(f"oracle twin census: {detail}, OK")
86110
return 0
87111

88112

‎scripts/check_twin_parity.py‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,36 @@ def find_twin(tests: Path, name: str) -> Path:
364364
return matches[0]
365365

366366

367+
PRIVATE_FIXTURE_ROWS_FILE = "tests/private_fixture_rows.txt"
368+
369+
370+
def private_fixture_rows(root: Path) -> frozenset[str]:
371+
"""The pinned private-fixture ctest rows (tests/private_fixture_rows.txt)."""
372+
path = root / PRIVATE_FIXTURE_ROWS_FILE
373+
if not path.is_file():
374+
return frozenset()
375+
return frozenset(line.strip() for line in path.read_text().splitlines()
376+
if line.strip() and not line.startswith("//"))
377+
378+
379+
def removed_private_test(root: Path, name: str) -> bool:
380+
"""True when the private-fixture PR removed this family's base source.
381+
382+
tests/<name>.cpp is gone AND its row (or a _l4* switched-route twin row)
383+
is pinned: the pair is named in the skip report and enforced exactly as
384+
before whenever the file is present. A base source removed without a
385+
pinned row -- or a tree with no pin file, as in the mutation self-test's
386+
synthetic roots -- keeps failing closed.
387+
"""
388+
if (root / "tests" / (name + ".cpp")).is_file():
389+
return False
390+
rows = private_fixture_rows(root)
391+
if not rows:
392+
return False
393+
return bool(name in rows
394+
or any(re.fullmatch(re.escape(name) + r"_l4\w*", row) for row in rows))
395+
396+
367397
def validate_covering_row(root: Path, row: LedgerLiteral | RangeLedgerLiteral) -> None:
368398
matches = list(COVERING_ROW.finditer(row.covering))
369399
if not matches:
@@ -420,7 +450,11 @@ def check_inventory(*, root: Path = ROOT, inventory: Path = INVENTORY,
420450
used_exact: set[tuple[str, str]] = set()
421451
used_ranges: set[tuple[str, int, int]] = set()
422452
restored_fingerprints: dict[str, str] = {}
453+
skipped_private: list[str] = []
423454
for name in selected:
455+
if removed_private_test(root, name):
456+
skipped_private.append(name)
457+
continue
424458
base_path = "tests/" + name + ".cpp"
425459
if base_reader is not None:
426460
base = extract_assertions(base_reader(name), base_path)
@@ -556,7 +590,10 @@ def check_inventory(*, root: Path = ROOT, inventory: Path = INVENTORY,
556590
total_ledgered += len(relevant) + sum(row.count for row in relevant_ranges.values())
557591
total_extra += extra
558592

559-
selected_paths = {"tests/" + name + ".cpp" for name in selected}
593+
for name in skipped_private:
594+
print("check_twin_parity: private fixtures not present: tests/" + name + ".cpp",
595+
file=sys.stderr)
596+
selected_paths = {"tests/" + name + ".cpp" for name in selected if name not in skipped_private}
560597
unused = {key for key in appendix if key[0].rsplit(":", 1)[0] in selected_paths} - used_exact
561598
if unused:
562599
first = next(iter(sorted(unused)))

0 commit comments

Comments
 (0)