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:
2026-07-26 12:03:43 +02:00
parent caf3ca72c1
commit 0f565b1f7e
5 changed files with 243 additions and 1 deletions
+69
View File
@@ -96,9 +96,15 @@ def validate(
rewritten,
archive_records=None,
demoted=(),
wing_faults=(),
) -> list[str]:
errs: list[str] = []
archive_records = archive_records or []
# #621: structural "one keyed record per file". ERRORS, not warnings — a file under the record
# wings that is not a record is a mistake by definition. Reported first because a file that
# failed to parse is absent from `records`, so every downstream check below is silently
# evaluating an incomplete corpus.
errs += list(wing_faults)
decision_recs = [r for r in records if r.heading not in SKIP_HEADINGS and r.status != "legacy-unmigrated"]
active_by_key: dict[str, int] = {}
@@ -406,6 +412,68 @@ def _diff_findings(base: str, head: str) -> tuple[list[str], list[str], list[str
return sorted(set(removed)), sorted(set(rewritten)), sorted(set(demoted))
def record_wing_files(records_dir: Path | None = None, archive_dir: Path | None = None) -> list[Path]:
"""Every file that MUST be exactly one keyed record.
Scope is the split-layout record wings only:
* `docs/decisions/records/**/*.md` — the active wing
* `docs/decisions/archive/<area>/*.md` — the archived wing, nested by area since #610
Deliberately NOT included: `docs/decisions/archive/*.md` at the top level. Those are the five
stripped legacy topic files left behind by the #610 split (`api.md`, `scan.md`, `spa.md`,
`startup.md`, `release-ci-governance.md`); each parses to a single KEYLESS pseudo-record from its
generated "Records formerly in this file" index, which is exactly what keeps older date-based
pointers resolvable. They are indexes, not records. `_NON_DECISION_FILES` (README.md and
friends) is filtered on top of that.
"""
records_dir = dl.RECORDS_DIR if records_dir is None else records_dir
archive_dir = dl.ARCHIVE_DIR if archive_dir is None else archive_dir
files: list[Path] = []
if records_dir.exists():
files += sorted(records_dir.rglob("*.md"))
if archive_dir.exists():
files += sorted(archive_dir.glob("*/*.md")) # area-nested only — see docstring
return [p for p in files if p.name not in dl._NON_DECISION_FILES]
def record_wing_faults(records_dir: Path | None = None, archive_dir: Path | None = None) -> list[str]:
"""Structural check (#621): every file in the record wings parses to exactly ONE keyed record.
Without this, a file the frontmatter reader cannot parse yields `[]` and simply VANISHES — no
error, no warning, validator OK, catalog "up to date", record absent from the corpus. That is
the corpus's own failure mode turned on itself: the one thing worse than a missing record is a
missing record that reports success (cf. the #609 marker that printed OK while doing nothing and
the #603 `stale-after` that silently never fired).
An EXISTING record disappearing was already loud — the no-vanish diff check catches it. This
closes the case the diff check structurally cannot see: a NEWLY ADDED record, where the author's
own PR looks clean because there is no prior state to diff against.
Making it path-driven rather than record-driven is the point: it converts ANY present or future
reader limitation from silent to loud, instead of enumerating the constructs we happen to know
about today.
"""
faults: list[str] = []
for p in record_wing_files(records_dir, archive_dir):
try:
recs = dl.parse_file(p)
except Exception as exc: # unreadable/undecodable file is a fault, not a crash
faults.append(f"{p}: could not be read as a decision record ({exc})")
continue
if len(recs) != 1:
faults.append(
f"{p}: parsed to {len(recs)} records, expected exactly 1 — a file under the record "
f"wings must be one record. Common cause: YAML the dependency-free frontmatter "
f"reader does not accept (a block scalar such as `rule: >-` or `rule: |`, any "
f"indented/nested structure, or unterminated `---` frontmatter). Put the value on "
f"ONE quoted line, as all other records do."
)
continue
if not recs[0].key:
faults.append(f"{p}: parsed to a record with no `key` — every record in the wings must be keyed.")
return faults
def _archive_keys() -> set[str]:
keys: set[str] = set()
if dl.ARCHIVE_DIR.exists():
@@ -491,6 +559,7 @@ def main(argv=None) -> int:
rewritten=rewritten,
archive_records=archive_records,
demoted=demoted,
wing_faults=record_wing_faults(),
)
if not budget_ok: