Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions scripts/check-memory-index.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,13 +960,44 @@ def main(argv: Optional[list[str]] = None) -> int:
print(summary)
return 0

# The failing summary names the faults this run *found*, not the four it could have
# found. Its pass-path twin above already appends a coverage clause for every reading
# it did not take, because the summary is the line a `| tail` takes; the failing side
# needs the same discipline pointed the other way. Measured 2026-11-18: an index
# holding one row for four active detail files printed the fixed sentence listing all
# four faults, three of them contradicted by the lines directly above it (`over 512:
# 0`, `no table row`, `unresolved: 0`), so the one line a reader takes sent them to
# three clean readings instead of to the three rows that are missing.
faults: list[str] = []
over_numbers = [
reading
for reading in readings
if reading.lines > MEMORY_INDEX_ROW_CAP
or reading.chars > INDEX_SIZE_WARN
or reading.over(INDEX_TITLE_MAX_CHARS)
]
if over_numbers:
faults.append(
f"{len(over_numbers)} of {len(readings)} index(es) over a number the rule "
f"names ({MEMORY_INDEX_ROW_CAP} lines, {INDEX_SIZE_WARN} chars, "
f"{INDEX_TITLE_MAX_CHARS} chars per row)"
)
cell_faults = sum(len(reading.cell_faults) for reading in readings)
if cell_faults:
faults.append(f"{cell_faults} table row(s) whose cells do not match its header's")
unresolved_links = sum(len(reading.unresolved()) for reading in readings)
if unresolved_links:
faults.append(f"{unresolved_links} row link(s) resolving to no file beside it")
unnamed = sum(len(reading.unnamed_details) for reading in readings)
if unnamed:
faults.append(f"{unnamed} active detail file(s) named by no row")
# `findings` is built from exactly these four conditions, so a non-zero count here
# always yields at least one clause; there is no empty-list case to spell out.
print(
f"{len(findings)} of {len(readings)} index(es) over a number the rule names, "
"carrying a row whose cells do not match its header's, carrying a row link "
"that resolves nowhere, or naming no row for an active detail file beside it; "
"the rule is compacted in "
"place, by the agent itself, and a stale row is rewritten or dropped when "
"the detail file is gone"
f"{len(findings)} of {len(readings)} index(es) with a finding: "
+ "; ".join(faults)
+ "; the rule is compacted in place, by the agent itself, and a stale row is "
"rewritten or dropped when the detail file is gone"
)
return 1

Expand Down
12 changes: 11 additions & 1 deletion tests/test_a_tree_reading_guard_names_its_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,17 @@ def test_every_runnable_guard_comes_back_clean_on_this_checkout(run_guard_once)
f"{'says the indexes are within the rule' if within else 'carries no OK line'} "
f"— the exit code and the reading must be one answer:\n{out}"
)
assert proc.returncode == 0 or "over a number the rule names" in out, (
# Both spellings of a finding line, because one guard now has more than one: the
# index guard reports the family it found (`with a finding: 3 active detail
# file(s) named by no row`), and only its length family still carries the older
# `over a number the rule names` phrase. Keying on that phrase alone made this
# assertion impossible to satisfy for the other three families - which nothing
# noticed while this checkout's index stayed clean, since the first arm carried it.
assert (
proc.returncode == 0
or "over a number the rule names" in out
or "with a finding:" in out
), (
f"{name}: rc=1 must carry that guard's own finding line, or the exit code is "
f"not a verdict this leg can read:\n{out}"
)
Expand Down
61 changes: 61 additions & 0 deletions tests/test_check_memory_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,67 @@ def test_a_detail_file_no_row_names_is_reported_with_its_name(mod, tmp_path, cap
assert "detail file a.md" not in out, "the named file must not be reported: " + out


# ── the failing summary: the faults it found, not the faults it knows ─────────


def test_the_failure_summary_names_the_fault_found_and_no_other(
mod, tmp_path, capsys
) -> None:
"""A run that finds one fault reports one fault.

Measured 2026-11-18: an index holding one row for four active detail files printed the
fixed sentence naming all four families, three of them contradicted by the lines
directly above it (`over 512: 0`, `no table row, so the cell reading had no subject`,
`row links 1, unresolved: 0`). The summary is the line a `| tail` takes, so it may not
send its reader to three readings that came back clean while the missing rows - the
fault that exists - go unmentioned.
"""
_entry(tmp_path, "a.md")
_entry(tmp_path, "b.md")
path = _index(tmp_path, "index.md", ["# Memory Index", "", "- [A](a.md)"])

assert mod.main([str(path)]) == 1
summary = [line for line in capsys.readouterr().out.splitlines() if line.strip()][-1]

assert "1 active detail file(s) named by no row" in summary, summary
assert "over a number the rule names" not in summary, summary
assert "cells do not match" not in summary, summary
assert "resolving to no file" not in summary, summary


def test_the_failure_summary_names_a_cell_fault_when_that_is_the_fault(
mod, tmp_path, capsys
) -> None:
"""The other direction on the same line: the family that fired is the one named.

Without this arm, a summary that named nothing at all would pass the test above - and
a failure report that names no fault is the defect inverted, not the fix.
"""
path = _cell_index(tmp_path, "bare.md", ["| a1 | `||` is not a pipe in cmd |"])

assert mod.main([str(path)]) == 1
summary = [line for line in capsys.readouterr().out.splitlines() if line.strip()][-1]

assert "table row(s) whose cells do not match its header's" in summary, summary
assert "over a number the rule names" not in summary, summary
assert "named by no row" not in summary, summary


def test_the_failure_summary_names_the_number_a_row_passed(mod, tmp_path, capsys) -> None:
"""And the length family, carrying the bound the row passed rather than the family alone."""
bound = mod.INDEX_TITLE_MAX_CHARS
_detail(tmp_path, "f.md")
path = _index(tmp_path, "long.md", ["# Memory Index", "", _row("tail", bound + 1)])

assert mod.main([str(path)]) == 1
summary = [line for line in capsys.readouterr().out.splitlines() if line.strip()][-1]

assert "over a number the rule names" in summary, summary
assert f"{bound} chars per row" in summary, summary
assert "cells do not match" not in summary, summary
assert "named by no row" not in summary, summary


def test_a_file_named_inside_a_code_span_is_named(mod, tmp_path, capsys) -> None:
"""Named, not linked: a merged row's backticks are the shape the rule prescribes.

Expand Down
Loading