fix(885): the cross-check's own COUNTING could be reverted with the suite green — extract it and drive it

`test_the_cross_check_COUNTS_locations_rather_than_collecting_NAMES` asserted the
property on the two COLLECTORS, not on the check that uses them. The comparison
itself was inlined in a loop over the real workflows, which agree under either
mechanism — so changing `walked != scanned` back to a name-set comparison, restoring
the exact blind spot this branch exists to close, left all 17 tests passing. A guard
whose distinguishing mechanism has no mutation proof is the shape
`testing.guard-ships-with-mutation-proof` names.

The per-file half is now `walk_versus_text_faults(name, text)`, driven on a
text/walk pair whose NAME SETS AGREE: a second `${{ secrets.REGISTRY_PASSWORD }}` in
a trailing comment, which the line-level strip leaves in the text half and the YAML
walk cannot reach. Counting reports it; the set comparison the branch replaced
reports nothing, and the test asserts BOTH halves of that so the contrast is the
assertion rather than a comment.

Measured: with `walked == scanned` mutated to `set(walked) == set(scanned)`,
1 failed / 16 passed; restored, 17 passed.

Refs #885

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015QqCpYFsKgnAnx6jVwrKiV
This commit is contained in:
2026-09-05 15:15:42 +02:00
co-authored by Claude Fable 5.1
parent ccc604aef7
commit 25ec811c73
@@ -492,6 +492,28 @@ def test_no_PULL_REQUEST_route_job_names_a_STORED_secret() -> None:
assert not faults, "\n".join(faults)
def walk_versus_text_faults(name: str, text: str) -> list[str]:
"""One file's half of the cross-check below, extracted so a negative control can DRIVE it.
Inlined in the loop it could be reverted to a name-set comparison — restoring the blind spot this
whole change is about — with every test in this file still green, because nothing but the loop
over the real workflows would ever call it and those agree either way
(`testing.guard-ships-with-mutation-proof`).
"""
walked = secret_name_counts(yaml.safe_load(text))
scanned = Counter(
_SECRET_REF.findall("\n".join(line for line in text.splitlines() if not line.lstrip().startswith("#")))
)
if walked == scanned:
return []
return [
f"{name}: the document walk reached {sorted(walked.items())} but the text scan found "
f"{sorted(scanned.items())}. The walk is what the stored-secret assertion runs over, so the "
f"difference is secret references this guard cannot see — widen `secret_names`' entry "
f"point, or take the reference out of the file."
]
def test_the_DOCUMENT_walk_finds_every_secret_reference_the_TEXT_does() -> None:
"""The document walk and a plain text scan must agree per file, COUNTED not merely named.
@@ -528,18 +550,8 @@ def test_the_DOCUMENT_walk_finds_every_secret_reference_the_TEXT_does() -> None:
total = Counter()
for path in workflow_files():
text = path.read_text()
walked = secret_name_counts(yaml.safe_load(text))
total += walked
scanned = Counter(
_SECRET_REF.findall("\n".join(line for line in text.splitlines() if not line.lstrip().startswith("#")))
)
if walked != scanned:
disagreements.append(
f"{path.name}: the document walk reached {sorted(walked.items())} but the text scan "
f"found {sorted(scanned.items())}. The walk is what the stored-secret assertion runs "
f"over, so the difference is secret references this guard cannot see — widen "
f"`secret_names`' entry point, or take the reference out of the file."
)
total += secret_name_counts(yaml.safe_load(text))
disagreements.extend(walk_versus_text_faults(path.name, text))
assert not disagreements, "\n".join(disagreements)
assert sum(total.values()) > 0, (
"no workflow reached by this check names a single `secrets.*` reference. Two empty Counters "
@@ -565,6 +577,24 @@ def test_the_cross_check_COUNTS_locations_rather_than_collecting_NAMES() -> None
assert secret_name_counts(twice) == Counter({"REGISTRY_PASSWORD": 2})
assert secret_name_counts(once) != secret_name_counts(twice)
# And the CROSS-CHECK ITSELF, on a text/walk pair whose NAME SETS AGREE. Reverting the
# comparison to name sets would restore the blind spot this change is about, so the difference
# is driven rather than left to the collectors' unit assertions above.
clean = 'jobs:\n j:\n env:\n A: "${{ secrets.REGISTRY_PASSWORD }}"\n'
assert walk_versus_text_faults("synthetic.yml", clean) == []
# The same name a SECOND time, at a location the YAML walk cannot reach — a trailing comment,
# which the line-level strip leaves in the text half.
duplicated = (
'jobs:\n j:\n env:\n A: "${{ secrets.REGISTRY_PASSWORD }}" # ${{ secrets.REGISTRY_PASSWORD }}\n'
)
faults = walk_versus_text_faults("synthetic.yml", duplicated)
assert len(faults) == 1, faults
assert "REGISTRY_PASSWORD" in faults[0]
# A name-set comparison — the mechanism this replaced — reports NOTHING on that same input.
assert secret_names(yaml.safe_load(duplicated)) == set(_SECRET_REF.findall(duplicated)) == {"REGISTRY_PASSWORD"}
# Two references in ONE scalar count twice, which is the shape a hoisted
# `user:${{ secrets.X }}:${{ secrets.Y }}` line takes.
pair = {"env": {"A": "${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_PASSWORD }}"}}