Skip to content

Commit 374821f

Browse files
opento-suggestionslywingedclaude
committed
test: walk the schema so a new digest site cannot join unlisted
test_every_known_site_is_listed asserted len(SCHEMA_SITES) == 6 and len(COMPILED_COPIES) == 5. Both are constants in this module, so no change to schemas/trace-claim.json could move either one. The module docstring and the commit message of f65e7c3 both said a seventh digest field appearing later would fail that test instead of joining silently. It would not. lywinged showed it by execution on the pull request that added the file: a seventh digest field carrying a drifted pattern left the suite green. This adds their test unchanged. It walks the schema for digest-shaped patterns and compares the walked set to SCHEMA_SITES, so a digest site present in the schema and absent from the list now fails, and dropping a site from the list is caught by the same assertion, and a listed entry naming no schema site fails from the other side. The list stays named, so adding a site is still a decision. The schema-side count is removed rather than kept beside the walk, because set equality against the schema is what that count stood in for. The compiled-side count stays. Nothing discovers a compiled copy: enum_drift.py walks the AST for set literals and a compiled regex is invisible to it, and a walk of the schema cannot see one either. The docstring now states that gap instead of implying the file closes both halves. Full suite green on this branch, and the plant reverts clean. Co-authored-by: LouieLuNZ <48041247+lywinged@users.noreply.github.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: opento-suggestions <opentosuggestionsofficial@gmail.com>
1 parent 30a655e commit 374821f

1 file changed

Lines changed: 43 additions & 8 deletions

File tree

tests/test_digest_parity.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@
1111
is invisible to it by construction. That is why these eleven were unguarded
1212
while the five enum copies were not.
1313
14-
The schema sites are named here rather than discovered by walking, so a seventh
15-
digest field appearing later fails the count below instead of joining silently.
14+
The schema sites are named here rather than discovered, and a walk checks the
15+
list against the schema: a seventh digest field appearing in the schema fails
16+
`test_no_digest_site_in_the_schema_is_missing_from_the_list` instead of joining
17+
silently. The list stays named, so adding a site is still a decision; it just
18+
cannot be skipped, and a listed entry naming no schema site fails from the
19+
other side.
20+
21+
The compiled copies get no such walk. `enum_drift.py` cannot see a compiled
22+
regex and neither can a walk of the schema, so nothing discovers a twelfth
23+
compiled copy; `assert len(COMPILED_COPIES) == 5` marks that boundary rather
24+
than closing it. That gap is stated here because the schema half no longer
25+
shares it.
1626
1727
Near misses, deliberately not listed: src/trace_tests/inclusion.py
1828
and tests/test_report.py each pin a sha256-only pattern. That is a
@@ -105,12 +115,37 @@ def test_a_compiled_digest_copy_matches_the_schema(label, get_copy, schema) -> N
105115
)
106116

107117

108-
def test_every_known_site_is_listed() -> None:
109-
"""A guard on the guard, in the shape `test_enum_parity.py` already uses.
118+
def test_no_digest_site_in_the_schema_is_missing_from_the_list(schema) -> None:
119+
walked: set[tuple[str, str]] = set()
120+
121+
def visit(node: object, parent: str | None, key: str | None) -> None:
122+
if isinstance(node, dict):
123+
pattern = node.get("pattern")
124+
if isinstance(pattern, str) and pattern.startswith("^sha") and parent and key:
125+
walked.add((parent, key))
126+
for name, value in node.items():
127+
if name == "properties" and isinstance(value, dict):
128+
for child, sub in value.items():
129+
visit(sub, key, child)
130+
else:
131+
visit(value, parent, key)
132+
133+
visit(schema, None, None)
134+
assert walked == set(SCHEMA_SITES), (
135+
"the schema's digest-shaped fields and SCHEMA_SITES disagree\n"
136+
f" in the schema, not listed: {sorted(walked - set(SCHEMA_SITES))}\n"
137+
f" listed, not in the schema: {sorted(set(SCHEMA_SITES) - walked)}"
138+
)
110139

111-
Eleven sites carry this pattern: six in the schema and five compiled. Adding
112-
a twelfth without listing it here would leave it unguarded, which is the
113-
state this file exists to end.
140+
141+
def test_every_known_site_is_listed() -> None:
142+
"""The compiled half of the guard, which no walk can supply.
143+
144+
The schema half is now checked against the schema itself by
145+
`test_no_digest_site_in_the_schema_is_missing_from_the_list`, so the count
146+
that stood in for it here is removed rather than kept alongside. A compiled
147+
copy is a compiled regex: `enum_drift.py` walks the AST for set literals and
148+
cannot see one, and a walk of the schema cannot see one either. This count is
149+
all that marks a twelfth compiled copy going unlisted.
114150
"""
115-
assert len(SCHEMA_SITES) == 6
116151
assert len(COMPILED_COPIES) == 5

0 commit comments

Comments
 (0)