fix(621): close three exemption holes and pin the guard's own wiring, per cold review
An independent cold-context review found the guard could be disabled or bypassed in four ways, one of them silently. HIGH — the guard's only wiring was untested. Deleting `wing_faults=record_wing_faults()` from main() left the ENTIRE suite green (120 passed) while a real block-scalar record vanished again with `decisions-validate: OK`. Every existing test either called the collector directly or handed validate() a hand-built list, so nothing pinned that main() ever invokes it — the #609 "prints OK while doing nothing" defect, one level up, inside the fix for that same defect. Independently reproduced before fixing. Now pinned by a monkeypatched sentinel test. MEDIUM — a record could escape by BASENAME. `_NON_DECISION_FILES` is a set of TOPIC-dir names ({README, migration-map, retrieval-eval}) and was applied to the wings too, so a genuine record at records/docs/retrieval-eval.md was skipped. Not hypothetical: the path<->key rule forces key `docs.retrieval-eval` to that exact filename, and dl.active_files() applies that filter only to the TOPIC_DIR glob — so the file would be a corpus source while exempt from the guard. Now nothing is exempt by basename. MEDIUM — the archive exemption was by LOCATION but justified by IDENTITY. Anything directly in archive/ was skipped, so a new unparseable archive/foo.md would vanish in the one directory left unwatched. Now exempt only if it really is a #610 stripped index: one keyless record with a known generated heading. LOW — parse-to-WRONG. `rule: >-` with an UNINDENTED continuation containing a colon parses to one VALID keyed record whose rule is literally ">-", plus a junk key, silently truncating the real value. PyYAML rejects that input, so the hand reader is more permissive than the writer. Now faulted via an unknown-frontmatter-key check. LOW — an absent or empty wing reported clean. Now loud: refusing to certify a corpus from a scan of nothing. Doc corrections, all measured rather than asserted: "all 167 records use single quoted lines" was false (117 of 168 rule: values are unquoted plain scalars — the invariant is single-LINE); the archive shape in the record, ci-cd.md and the rule: field said `archive/<area>/` where the code deliberately uses archive/** ; the mutation count is 10, not five; and the "converts ANY reader limitation" claim is softened to the class it actually covers. 125 passed. Refs #621
This commit is contained in:
@@ -834,3 +834,76 @@ def test_wing_faults_sees_a_DEEPER_nested_archive_record(tmp_path):
|
||||
|
||||
faults = dv.record_wing_faults(records, archive)
|
||||
assert len(faults) == 1 and "broken.md" in faults[0], faults
|
||||
|
||||
|
||||
# --- #621 cold-review findings ------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_main_actually_CALLS_the_wing_scan(monkeypatch, capsys):
|
||||
"""The guard's only wiring was untested: deleting `wing_faults=record_wing_faults()` from
|
||||
main() left the entire suite green, and a real block-scalar record vanished again with
|
||||
`decisions-validate: OK`. Every other test either calls the collector directly or hands
|
||||
validate() a hand-built list, so nothing pinned that main() invokes it at all — the #609
|
||||
'marker that printed OK while doing nothing' defect, one level up."""
|
||||
monkeypatch.setattr(dv, "record_wing_faults", lambda *a, **k: ["SENTINEL-WING-FAULT"])
|
||||
rc = dv.main([])
|
||||
assert rc == 1, "a wing fault must fail the validator"
|
||||
assert "SENTINEL-WING-FAULT" in capsys.readouterr().err
|
||||
|
||||
|
||||
def test_a_record_is_not_exempted_by_its_BASENAME(tmp_path):
|
||||
"""`_NON_DECISION_FILES` is a set of TOPIC-dir names ({README, migration-map, retrieval-eval}).
|
||||
Applying it to the wings meant a genuine record at `records/docs/retrieval-eval.md` was
|
||||
silently skipped — and that path is forced, not hypothetical: the path<->key rule puts key
|
||||
`docs.retrieval-eval` at exactly that filename. Worse, dl.active_files() applies the filter
|
||||
only to the TOPIC_DIR glob, so such a file IS a corpus source while being exempt from the
|
||||
guard."""
|
||||
records, archive = _wing(tmp_path)
|
||||
(records / "docs").mkdir(parents=True, exist_ok=True)
|
||||
(records / "ci" / "good.md").write_text(_GOOD)
|
||||
(records / "docs" / "retrieval-eval.md").write_text("# just a note, not a record\n")
|
||||
faults = dv.record_wing_faults(records, archive)
|
||||
assert len(faults) == 1 and "retrieval-eval.md" in faults[0], faults
|
||||
|
||||
|
||||
def test_archive_toplevel_is_exempt_by_IDENTITY_not_by_location(tmp_path):
|
||||
"""Exempting everything directly in `archive/` left that one directory unguarded: a new
|
||||
unparseable `archive/foo.md` would vanish silently. The exemption is for the five #610 stripped
|
||||
INDEX files, so it must test for that shape — one keyless record with a known generated
|
||||
heading — not merely for sitting in that directory."""
|
||||
records, archive = _wing(tmp_path)
|
||||
(records / "ci" / "good.md").write_text(_GOOD)
|
||||
(archive / "api.md").write_text("# api\n\n## Records formerly in this file\n\n- `api.thing`\n")
|
||||
assert dv.record_wing_faults(records, archive) == [], "a real stripped index must stay exempt"
|
||||
|
||||
(archive / "foo.md").write_text("rule: >-\n wrapped\n value\n")
|
||||
faults = dv.record_wing_faults(records, archive)
|
||||
assert len(faults) == 1 and "foo.md" in faults[0], faults
|
||||
|
||||
|
||||
def test_junk_frontmatter_key_from_a_split_value_is_faulted(tmp_path):
|
||||
"""parse-to-WRONG, the case the structural check alone cannot see. A block scalar with an
|
||||
UNINDENTED continuation containing a colon parses to ONE valid keyed record whose `rule` is
|
||||
literally `>-`, plus a junk key from the continuation — silently truncating the real value.
|
||||
PyYAML rejects this input, so the hand reader is more permissive than the writer."""
|
||||
records, archive = _wing(tmp_path)
|
||||
bad = records / "ci" / "corrupt.md"
|
||||
bad.write_text(_GOOD.replace("rule: 'a rule on one quoted line'\n",
|
||||
"rule: >-\nthe real rule: with a colon\n"))
|
||||
recs = dl.parse_file(bad)
|
||||
assert len(recs) == 1 and recs[0].key, "precondition: this parses to one KEYED record"
|
||||
assert recs[0].rule == ">-", f"precondition: the real value was truncated, got {recs[0].rule!r}"
|
||||
|
||||
faults = dv.record_wing_faults(records, archive)
|
||||
assert len(faults) == 1 and "unrecognized key" in faults[0], faults
|
||||
|
||||
|
||||
def test_an_empty_or_missing_record_wing_is_LOUD(tmp_path):
|
||||
"""A guard that reports a clean corpus from a scan of nothing is the defect it exists to close,
|
||||
applied to itself. Reachable via a partial checkout, a renamed directory, or a bad monkeypatch."""
|
||||
missing = dv.record_wing_faults(tmp_path / "nope" / "records", tmp_path / "nope" / "archive")
|
||||
assert missing and "missing or contains no" in missing[0], missing
|
||||
|
||||
records, archive = _wing(tmp_path) # exists but holds no *.md
|
||||
empty = dv.record_wing_faults(records, archive)
|
||||
assert empty and "missing or contains no" in empty[0], empty
|
||||
|
||||
Reference in New Issue
Block a user