Skip to content

Commit 2d2cd17

Browse files
committed
test: check the compact samples, which nothing was checking
The two text formats spell a check name differently — the default output prints the kebab-case name, --compact prints the config key — so a sample of one cannot be validated against the other. The existing guard only matches the default format, which meant every --compact sample on the site was checked by nothing at all. That is the same blind spot that let a pre-2.13 sample sit unnoticed in the troubleshooting page: the sample was stale in a format the guard could not see, and every test still passed. Fixing that one sample did not close the hole it came through. Two samples were uncovered, in example.md and rules.md — one indented inside a content tab, one not, so the pattern allows leading whitespace. Verified by breaking one deliberately: the guard names the file and both spellings, rather than only going red. This also decides what happens if commit-check#528 reconciles the two formats upstream. Today that would quietly leave both samples wrong; now docs-sync fails and says which lines to rewrite. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U9zFxq8V4qxG4aMzJhGBFn
1 parent deeb0bd commit 2d2cd17

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/docs_sync_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def _read_doc(name: str) -> str:
3232
#: A pasted failure line, e.g. ``CC003 subject-imperative check failed ==> ...``
3333
_SAMPLE_FAILURE = re.compile(r"(CC\d{3}) (\S+) check failed ==>")
3434

35+
#: A pasted ``--compact`` line, e.g. ``[FAIL] CC003 subject_imperative: ...``.
36+
#: Indented, because these samples sit inside content tabs.
37+
_COMPACT_FAILURE = re.compile(r"^\s*\[FAIL\] (CC\d{3}) ([^:\s]+):", re.M)
38+
3539

3640
def _rule_section(content: str, rule_id: str) -> str:
3741
"""Return just the part of the rules page belonging to one rule."""
@@ -83,6 +87,33 @@ def test_sample_output_matches_what_the_tool_prints(self):
8387
)
8488
assert not stale, "sample output is out of date:\n " + "\n ".join(stale)
8589

90+
def test_compact_sample_output_matches_what_the_tool_prints(self):
91+
"""Pasted ``--compact`` output names rules the way that format does.
92+
93+
The two text formats spell a check differently: the default output
94+
prints the kebab-case name, and ``--compact`` prints the config key.
95+
A sample of one therefore cannot be validated against the other, and
96+
the guard above only matches the default format — so the compact
97+
samples were checked by nothing at all. That is the blind spot that
98+
let a pre-2.13 sample sit unnoticed in the troubleshooting page.
99+
100+
If the two formats are ever reconciled (see commit-check#528), this
101+
is what will point at the samples that need rewriting.
102+
"""
103+
by_id = {entry.rule_id: entry for entry in ALL_RULES}
104+
stale = []
105+
for page in DOCS.rglob("*.md"):
106+
for rule_id, printed in _COMPACT_FAILURE.findall(page.read_text("utf-8")):
107+
entry = by_id.get(rule_id)
108+
if entry and printed != entry.check:
109+
stale.append(
110+
f"{page.relative_to(DOCS)}: {rule_id} shown as "
111+
f"'{printed}', --compact prints '{entry.check}'"
112+
)
113+
assert not stale, (
114+
"compact sample output is out of date:\n " + "\n ".join(stale)
115+
)
116+
86117
def test_every_rule_explains_itself(self):
87118
"""Each rule section must answer what it does and why it matters."""
88119
content = _read_doc("rules.md")

0 commit comments

Comments
 (0)