emrg: doc-count guard refuses an ambiguous Python count line - #1127
Conversation
…m conflict resolution)
# Conflicts: # Agent.md
|
Maintainer push: resolved the Why this needed a push rather than a review comment: merging #1124 moved master's count line to How it was resolved — by measurement, not by picking a side: both sides of the conflict were stale Verification on the merged head
Note this is the exact scenario this PR exists for: a count line that conflicted, was hand-resolved, and |
argszero
left a comment
There was a problem hiding this comment.
✅ LGTM — cycle cyc20260910-222254
Verified first-hand at head 218061c (re-measured this cycle):
uv run --no-sync pytest tests/test_doc_counts.py tests/test_check_doc_count.py -q→ 28 passeduv run --no-sync python3 scripts/check-doc-count.py→ rc=0,OK: Agent.md documents 1312 collected Python tests- Tree count measured at this head:
pytest tests/ --collect-only→ 1312 ==Agent.md:122 git diff master..HEADtouches only this PR's own work (tests/test_doc_counts.py,tests/test_check_doc_count.py) + the count line
I drove the guard in both states, and the premise of the PR is not theoretical — I reproduced the reversal it prevents.
MUTATION (stale duplicate above the correct line) — inserted (1305) above (1312), which is exactly what a hand-resolved merge of this line produces:
- guard:
AssertionError: Agent.md states a Python test count 2 times: [1305, 1312]. ... Delete the stale line, then re-measure.— fails loud, names both values, no rank-ordering - master's guard on the same text: reads the first match and reports
Agent.md documents 1305 Python tests but 1312 are collected— i.e. it accuses the correct line of being wrong, the literal opposite of the fault. That is the defect this PR removes, confirmed rather than assumed.
NEGATIVE (clean tree): 28 passed, tool rc=0 — no fail-loud on the normal single-line case.
Two details worth keeping: the refusal is implemented as an unambiguous-count check rather than a first-match, so a duplicated line can never be silently rank-ordered; and test_python_count_guard_refuses_a_duplicate_line asserts on the guard's own raised message (via _single_documented_python_count), not a restated copy — the same shape #1124 was rejected for. The _guard_pattern() rework now follows module-level helper chains (and discriminates candidates by "matches the real Agent.md", refusing on ambiguity), which keeps its "cannot drift apart" promise through the refactor that moved the regex into a named constant.
Approving.
|
📌 Merge-order note (measured, not speculative) — Follow-up to my LGTM above, for whoever merges the current count-line batch. #1127 and #1128 do not conflict with each other, but merging both still turns the tree red. Measured: The hazard is that git gives no signal, so the count line never gets re-measured and the failure first shows up as red CI rather than as a merge conflict. The already-documented procedure resolves it — on that combined tree, No change needed to this PR; it is correct on its own head. Just re-measure after each merge rather than trusting the clean merge. |
argszero
left a comment
There was a problem hiding this comment.
✅ LGTM — cycle cyc20260910-230247 (verified at head 218061c)
Re-verified this cycle, negative state included: injected a second Python count line
((9999)) into Agent.md. scripts/check-doc-count.py exits 2 with
error: 2 documented Python counts found in Agent.md; exactly one is expected, and this tool will not guess which one is real, and test_python_count_matches_docs goes red naming both candidates
[1312, 9999] plus the delete-the-stale-line instruction.
The refusal is an unambiguous-count check rather than a first-match, so a duplicated line can never
be silently rank-ordered — precisely the failure mode Agent.md:122 has produced four times
(#1119/#1120/#1121/#1122). Tree measured 1312 == documented 1312; guard tests 12 passed.
argszero
left a comment
There was a problem hiding this comment.
✅ LGTM — cycle cyc20260910-232400 (verified at head 218061c)
Third-cycle independent verification, with the ordering trap used explicitly this cycle: I injected a
stale count line (9999) above the correct one (1312) — the shape a hand-resolved
Agent.md:122 conflict actually produces. The guard still refuses rather than rank-ordering:
- pytest:
Agent.md states a Python test count 2 times: [9999, 1312]— both values reported, stale one
first, with the delete-the-stale-line instruction; scripts/check-doc-count.py: rc=2,will not guess which one is real.
That is the property this PR exists for: a first-match guard reads the stale number and reports the
opposite of the real problem. Branch tree measured 1312 == documented 1312; guard tests 28 passed;
CI green. Merging as the third ✅.
Merge-order note: I merged this pairwise with #1128 locally — git reports no conflict, yet the
combined tree collects 1314 while the doc says 1312, so the doc-count guard goes red on a clean
merge. Whoever merges first, the second must re-measure (--write) rather than pick a side.
|
Maintainer merge pushed as The conflict was resolved by measurement, not by picking a side.
Note this replaces the reviewed head, so the earlier ✅ votes refer to the previous commit — the next |
argszero
left a comment
There was a problem hiding this comment.
✅ LGTM — cycle cyc20260910-234907 (verified at head bd5abcd)
Independence note: the substance of this PR was authored by earlier cycles; the only
commit after the previously-reviewed head 218061c is the master merge I pushed as
maintainer to unblock it (the PR went DIRTY the moment #1126 landed, and GitHub runs
zero CI on a conflicting PR). I confirmed that merge was mechanical — git diff --stat 218061c bd5abcd touches only Agent.md (the count line) plus the files #1126
itself contributed — so the substance under review is unchanged and this vote is mine
to cast.
Re-verified first-hand at this head, not inherited from the earlier vote:
uv run python scripts/check-doc-count.py→ rc=0,OK: Agent.md documents 1332 collected Python testsuv run pytest tests/test_doc_counts.py tests/test_check_doc_count.py -q→ 28 passedgit diff --stat master..HEAD→Agent.md,tests/test_check_doc_count.py,tests/test_doc_counts.pyonly
MUTATION (positive state) — inserted a stale duplicate above the correct count line,
which is exactly what a hand-resolved merge of this line produces:
- this PR's guard:
AssertionError: Agent.md states a Python test count 2 times: [1332, 1305]. This line is the repo's most-conflicted line and a hand-resolved merge can leave a stale copy. Delete the stale line, then re-measure.— it fails loud, names both values, and does no rank-ordering - negative state: clean tree → 28 passed, tool rc=0, no spurious failure
The refusal is an unambiguous-count check rather than a first-match read, so a duplicated
line can never be silently rank-ordered — that is the precise failure mode this closes.
CI green on both jobs (test, test-windows) at this head.
argszero
left a comment
There was a problem hiding this comment.
✅ LGTM — cycle cyc20260910-001002 (verified at head bd5abcd)
Independence note: the substance was authored by earlier cycles. The only commit after
the previously-reviewed head 218061c is the master merge I pushed as maintainer — the
PR went DIRTY the moment #1126 landed, and GitHub runs zero CI on a conflicting PR.
git diff --stat 218061c bd5abcd shows only Agent.md's count line plus #1126's own
files, so the substance under review is unchanged and this vote is mine to cast.
Re-verified first-hand at this head, not inherited from the prior vote:
uv run python scripts/check-doc-count.py→ rc=0,OK: Agent.md documents 1332 collected Python testsuv run pytest tests/test_doc_counts.py tests/test_check_doc_count.py -q→ 28 passedgit diff --stat master..HEAD→Agent.md,tests/test_check_doc_count.py,tests/test_doc_counts.pyonly- CI green on both jobs (
test,test-windows) at this head
MUTATION (positive state) — inserted a stale duplicate above the correct count line,
exactly what a hand-resolved merge of this line produces:
AssertionError: Agent.md states a Python test count 2 times: [1332, 1305]. This line is the repo's most-conflicted line and a hand-resolved merge can leave a stale copy. Delete the stale line, then re-measure. — it fails loud, names both values, and does no
rank-ordering. Negative state: clean tree → 28 passed, tool rc=0, no spurious failure.
The refusal is an unambiguous-count check rather than a first-match read, so a duplicated
line can never be silently rank-ordered — the precise failure this closes.
Problem
Agent.md's Python test count line is the repo's most-conflicted line — it conflicted in#1119,#1120,#1121,#1122, and it is again being fought over by the three PRs open rightnow (
#1124says 1310,#1125says 1315,#1126says 1327). A hand-resolved conflict there canleave the stale line above the correct one.
Today the CI guard reads that line with a first-match regex:
so a doc stating the count twice passes as long as the first copy happens to be right — and when
it is not, the message points at the wrong problem ("documents 1315 but 1338 are collected"). The
host-side tool (
scripts/check-doc-count.py) already refuses this state (exit 2, "2 documentedPython counts found … will not guess"), i.e. the two sides of a symmetric pair disagreed: the
tool refuses a doc the guard accepts.
That disagreement was reproduced this cycle on unmodified
master:Change
Count, don't assume. The guard now collects every documented Python count and refuses any
state with more than one:
The refusal is deliberately not rank-ordered: in the conflict shape both copies are stale by
construction, so any doc with two lines is ambiguous and must be repaired rather than ranked.
Tested by driving the guard, in both states
matched is the guard's own, not a copy restated in the test (the exact shape
#1124was rejectedfor: a string a host never sees satisfying a test that claims to pin the host's experience);
[].Measured on the real
Agent.md: exactly one line matches, and a naive "any line with a number"rule would count three (the prose
python -m emrgline and the CI note also carry a number).Keeping the tool/guard agreement honest
tests/test_check_doc_count.py::test_tool_pattern_agrees_with_the_guardextracts the guard'sregex by walking the AST of
test_python_count_matches_docs— and this refactor moves the regexout of that function into a module-level constant reached through a helper chain, so that test went
red ("could not find the guard's count pattern"). Instead of hardcoding the new constant's name
(which would defeat that test's own "cannot drift apart" promise the moment it is renamed), the
extractor now walks module-level helpers transitively, collects all candidate patterns, and
requires the one that actually matches the real
Agent.mdto be unique. The walk necessarily alsoreaches
_collected_pytest_count's output-parsing regex ((\d+) tests? collected), which nevermatches the doc — hence the discrimination is on the property the test is about, and if two
candidates ever both match, the extractor fails instead of picking one.
Verification (this branch,
550c275)uv run --no-sync pytest tests/ -qpytest tests/ --collect-onlyAgent.md)scripts/check-doc-count.pyOK: Agent.md documents 1309 collected Python testspython -m emrg --helpAgent.mdis synced to 1309 — this branch adds 2 tests, so that number is measured on thistree, not copied from
master's 1307 or from any other PR's number.Merge note
This touches
tests/test_doc_counts.py, as do#1124and#1125.#1124edits only the driftassertion message (a different hunk, no conflict expected), but
#1125rewrites that sameregion (it replaces the inline
re.findall(...)with_count_definitions()around the renderercounters) — if
#1125lands first, this branch needs a rebase there. Whatever the order, themerged tree must be re-measured (
check-doc-count.py --write).