fix(621): make an unparseable decision record loud instead of silently invisible
A file under the record wings that the dependency-free frontmatter reader cannot parse returned [] and simply vanished from the corpus: decisions_validate.py printed OK, build_decisions_catalog.py --check said "up to date", the record was absent, and nothing anywhere errored. Reproduced end-to-end with a YAML block scalar (`rule: >-`), which is the natural thing to reach for on this corpus's very long rule: values and which parsed fine under PyYAML before #610's dependency-free reader. An EXISTING record disappearing was already loud (the no-vanish diff check). The hole was a NEWLY ADDED record, which that check structurally cannot see — no base state to diff against — so the author's own PR looks clean. Hence a per-PATH check, not a per-construct or diff-driven one: asserting "this path yields exactly one keyed record" turns any present or future reader limitation from silent to loud in one move. Adds record_wing_files/record_wing_faults to decisions_validate.py, surfaced through validate() as ERRORS (a file in the record wings that is not a record is a mistake by definition) and reported first, since a file that failed to parse leaves every downstream check silently evaluating an incomplete corpus. The five top-level stripped legacy archive files are exempt — they are generated "Records formerly in this file" indexes, keyless by construction, and are what keeps older date-based pointers resolvable. _read_frontmatter is deliberately NOT extended to accept block scalars; rationale in the new docs.record-wing-parse-guard record. 8 tests, mutation-verified: with the check neutered 5 go red, restored all 119 pass. A live-corpus positive control asserts the wings are non-empty so a clean result can never be vacuous. Refs #621
This commit is contained in:
@@ -700,3 +700,121 @@ def test_retitling_a_record_is_not_reported_as_a_removal(tmp_path):
|
||||
assert removed == [], f"a retitle was reported as a removal: {removed}"
|
||||
assert rewritten == [], f"a retitle was reported as a prose rewrite: {rewritten}"
|
||||
assert demoted == [], f"a retitle was reported as a demotion: {demoted}"
|
||||
|
||||
|
||||
# --- #621: structural "one keyed record per file" over the record wings -----------------------
|
||||
#
|
||||
# The defect these cover: a file the dependency-free frontmatter reader cannot parse yields `[]`
|
||||
# and vanishes from the corpus with NO error anywhere — validator OK, catalog "up to date", record
|
||||
# absent. Only a NEWLY ADDED record is affected; an existing one disappearing is already caught by
|
||||
# the no-vanish diff check, which structurally cannot see a record that never existed in the base.
|
||||
|
||||
|
||||
def _wing(tmp_path) -> tuple[Path, Path]:
|
||||
"""A tmp record-wing pair: (records_dir, archive_dir)."""
|
||||
records = tmp_path / "docs" / "decisions" / "records"
|
||||
archive = tmp_path / "docs" / "decisions" / "archive"
|
||||
(records / "ci").mkdir(parents=True)
|
||||
(archive / "ci").mkdir(parents=True)
|
||||
return records, archive
|
||||
|
||||
|
||||
_GOOD = (
|
||||
"---\n"
|
||||
"key: ci.good\n"
|
||||
"title: '2026-01-01 — Good (#1)'\n"
|
||||
"status: active\n"
|
||||
"since: '2026-01-01'\n"
|
||||
"supersedes: none\n"
|
||||
"superseded-by: none\n"
|
||||
"rule: 'a rule on one quoted line'\n"
|
||||
"signals: 'concept · paths: a/b.py · issues: #1'\n"
|
||||
"mechanics: 'x'\n"
|
||||
"---\n\nRationale prose.\n"
|
||||
)
|
||||
|
||||
|
||||
def test_wing_faults_clean_corpus_is_silent(tmp_path):
|
||||
records, archive = _wing(tmp_path)
|
||||
(records / "ci" / "good.md").write_text(_GOOD)
|
||||
assert dv.record_wing_faults(records, archive) == []
|
||||
|
||||
|
||||
def test_wing_faults_block_scalar_record_fails_loudly(tmp_path):
|
||||
"""The exact reproduction from #621: a YAML block scalar — the natural thing to reach for on
|
||||
this corpus's very long `rule:` values — makes the whole record silently invisible."""
|
||||
records, archive = _wing(tmp_path)
|
||||
bad = records / "ci" / "blockscalar.md"
|
||||
bad.write_text(_GOOD.replace("rule: 'a rule on one quoted line'\n", "rule: >-\n a long rule wrapped\n over two lines\n"))
|
||||
|
||||
# Precondition: this really is the silent-vanish case, not some other parse error.
|
||||
assert dl.parse_file(bad) == [], "expected the reader to drop the record entirely"
|
||||
|
||||
faults = dv.record_wing_faults(records, archive)
|
||||
assert len(faults) == 1, faults
|
||||
assert "blockscalar.md" in faults[0]
|
||||
assert "expected exactly 1" in faults[0]
|
||||
|
||||
|
||||
def test_wing_faults_unterminated_frontmatter_fails_loudly(tmp_path):
|
||||
records, archive = _wing(tmp_path)
|
||||
bad = records / "ci" / "unterminated.md"
|
||||
bad.write_text("---\nkey: ci.unterminated\nstatus: active\n\nNo closing delimiter.\n")
|
||||
assert dl.parse_file(bad) == []
|
||||
|
||||
faults = dv.record_wing_faults(records, archive)
|
||||
assert len(faults) == 1, faults
|
||||
assert "unterminated.md" in faults[0]
|
||||
|
||||
|
||||
def test_wing_faults_stray_note_file_fails_loudly(tmp_path):
|
||||
"""A file under records/ that is not a record at all — no frontmatter whatsoever."""
|
||||
records, archive = _wing(tmp_path)
|
||||
(records / "ci" / "notes.md").write_text("# Scratch notes\n\nNot a record.\n")
|
||||
faults = dv.record_wing_faults(records, archive)
|
||||
assert len(faults) == 1, faults
|
||||
assert "notes.md" in faults[0]
|
||||
|
||||
|
||||
def test_wing_faults_keyless_record_fails_loudly(tmp_path):
|
||||
"""Parses to exactly one record, but carries no `key` — still a fault."""
|
||||
records, archive = _wing(tmp_path)
|
||||
(records / "ci" / "keyless.md").write_text(_GOOD.replace("key: ci.good\n", ""))
|
||||
faults = dv.record_wing_faults(records, archive)
|
||||
assert len(faults) == 1, faults
|
||||
assert "no `key`" in faults[0]
|
||||
|
||||
|
||||
def test_wing_faults_exempts_stripped_legacy_archive_files(tmp_path):
|
||||
"""The #610 split left five KEYLESS stripped topic files at the archive TOP level (api.md,
|
||||
scan.md, spa.md, startup.md, release-ci-governance.md) whose only content is a generated
|
||||
"Records formerly in this file" index — that index is what keeps older date-based pointers
|
||||
resolvable. They are indexes, not records, and must stay exempt. Their area-NESTED siblings
|
||||
are real records and are checked."""
|
||||
records, archive = _wing(tmp_path)
|
||||
(records / "ci" / "good.md").write_text(_GOOD)
|
||||
# a stripped legacy file at the archive top level: parses to a single keyless pseudo-record
|
||||
(archive / "api.md").write_text("# api\n\n## Records formerly in this file\n\n- `api.thing`\n")
|
||||
(archive / "README.md").write_text("# archive\n")
|
||||
assert dv.record_wing_faults(records, archive) == []
|
||||
|
||||
# ...but a real archived record nested under an area IS checked
|
||||
(archive / "ci" / "broken.md").write_text("# not a record\n")
|
||||
faults = dv.record_wing_faults(records, archive)
|
||||
assert len(faults) == 1 and "broken.md" in faults[0], faults
|
||||
|
||||
|
||||
def test_validate_surfaces_wing_faults_as_errors(tmp_path):
|
||||
"""Faults must arrive as validator ERRORS (exit 1), not warnings."""
|
||||
errs = _v([_rec(key="ci.a", source=Path("docs/decisions/records/ci/a.md"), heading="A")],
|
||||
wing_faults=["docs/decisions/records/ci/x.md: parsed to 0 records, expected exactly 1"])
|
||||
assert any("x.md" in e for e in errs), errs
|
||||
|
||||
|
||||
def test_real_repo_record_wings_are_all_parseable():
|
||||
"""Positive control against the LIVE corpus: every one of the real record files parses to
|
||||
exactly one keyed record. This is what makes the check's clean result meaningful rather than
|
||||
vacuous — if the wings were empty or unreadable, the checks above would pass trivially."""
|
||||
files = dv.record_wing_files()
|
||||
assert len(files) > 100, f"record wings look empty ({len(files)} files) — check is vacuous"
|
||||
assert dv.record_wing_faults() == []
|
||||
|
||||
Reference in New Issue
Block a user