fix(610): de-brittle the count assertion; stop conflating index lines with preserved prose
Both surfaced when main gained two records mid-flight. - test_record_count_is_the_expected_166 hardcoded the total, so it failed the moment a record landed on main -- a merge turning an unrelated test red. The real invariant is before == after; the count only needs to prove the harness isn't parsing a stub corpus, so it is now equality plus a floor. - The migration's "lines preserved" figure silently absorbed the generated where-did-it-go index once that was threaded into the preamble string, jumping 507 -> 759 with no new prose preserved. It now reports the two separately: 514 lines of original prose, plus 245 generated index lines. A number that quietly changes meaning is worse than no number.
This commit is contained in:
@@ -136,12 +136,13 @@ def _preamble(path: Path, records: list[dl.Record]) -> str:
|
||||
return "\n".join(kept)
|
||||
|
||||
|
||||
def plan() -> tuple[list[tuple[dl.Record, Path]], dict[Path, str]]:
|
||||
def plan() -> tuple[list[tuple[dl.Record, Path]], dict[Path, str], dict[Path, int]]:
|
||||
"""(record -> destination) pairs, and (source file -> preamble to keep)."""
|
||||
sources = [p for p in dl.active_files() if p.exists()]
|
||||
sources += sorted(p for p in dl.ARCHIVE_DIR.glob("*.md") if p.name not in dl._NON_DECISION_FILES)
|
||||
moves: list[tuple[dl.Record, Path]] = []
|
||||
preambles: dict[Path, str] = {}
|
||||
kept_prose: dict[Path, int] = {} # ORIGINAL prose only, excluding the generated index
|
||||
for src in sources:
|
||||
if dl.RECORDS_DIR in src.parents or dl.has_frontmatter(src.read_text(encoding="utf-8")):
|
||||
continue # already migrated
|
||||
@@ -153,8 +154,9 @@ def plan() -> tuple[list[tuple[dl.Record, Path]], dict[Path, str]]:
|
||||
moves += [(r, record_path(r)) for r in keyed]
|
||||
body = _preamble(src, recs)
|
||||
idx = _moved_index(keyed)
|
||||
kept_prose[src] = len(body.splitlines())
|
||||
preambles[src] = f"{body.rstrip()}\n\n{idx}" if idx else body
|
||||
return moves, preambles
|
||||
return moves, preambles, kept_prose
|
||||
|
||||
|
||||
def main(argv=None) -> int:
|
||||
@@ -162,7 +164,7 @@ def main(argv=None) -> int:
|
||||
ap.add_argument("--dry-run", action="store_true", help="report the plan, write nothing")
|
||||
args = ap.parse_args(argv)
|
||||
|
||||
moves, preambles = plan()
|
||||
moves, preambles, kept_prose = plan()
|
||||
|
||||
dests = [d for _, d in moves]
|
||||
if len(set(dests)) != len(dests):
|
||||
@@ -170,9 +172,10 @@ def main(argv=None) -> int:
|
||||
raise SystemExit(f"destination collision — two records map to the same path: {dupes}")
|
||||
|
||||
print(f"{len(moves)} records -> {len({d.parent for d in dests})} directories")
|
||||
idx_lines = sum(len(v.splitlines()) for v in preambles.values()) - sum(kept_prose.values())
|
||||
print(
|
||||
f"{len(preambles)} source files kept, stripped to narrative "
|
||||
f"({sum(len(v.splitlines()) for v in preambles.values())} lines preserved)"
|
||||
f"{len(preambles)} source files kept: {sum(kept_prose.values())} lines of original prose "
|
||||
f"preserved, plus {idx_lines} generated index lines"
|
||||
)
|
||||
if args.dry_run:
|
||||
for rec, dest in sorted(moves, key=lambda m: str(m[1]))[:5]:
|
||||
|
||||
Reference in New Issue
Block a user