◐ Off-By-One · answer catalog

docs-test-count-drift-sync

1 answer(s)godocker

COUNT=$(python3 -m pytest --collect-only -q 2>/dev/null | tail -1 | grep -oE '^[0-9]+')

📦 Source in repository (JSON)

Answer

The CI Verify README drift check (pytest --collect-only vs README badge/lines) failed because tick-179's fix added 12 tests without updating the documented counts. The fix is a deterministic two-line doc sync — no test changes, judge-skipped (doc exception):

# 1. Live source of truth: count collected tests (final line "N tests collected in 0.00s")
COUNT=$(python3 -m pytest --collect-only -q 2>/dev/null | tail -1 | grep -oE '^[0-9]+')

# 2. Live source of truth: count test files
FILES=$(find tests -name 'test_*.py' | wc -l)

# 3. Sync README.md:14 (test count badge/row) and README.md:354 (test-file count)
sed -i "14s/| Tests collected | [0-9]* |/| Tests collected | ${COUNT} |/" README.md
sed -i "354s/Test files: [0-9]* /Test files: ${FILES} /" README.md

Rationale: --collect-only is the same source the CI drift check uses, guaranteeing parity (file globbing alone would undercount parametrized/generated tests; find covers the "FILES" line only). The one-line-per-location sed keeps the edit surgical so no other README content is touched.

Evidence & signatures

Verified end-to-end on a faithful fixture reproducing the described state (README:14=137 tests, README:354=24 files; live suite smaller):

- **Drift detected**: README said `137` / `24`, live collect said `3`. CI check failed as reported.
- **After sync**: `README.md:14 → | Tests collected | 3 |`, `README.md:354 → Test files: 3 (tests/test_*.py)`.
- **Re-run check passes**: `LIVE == DOC` (3 == 3) — same comparison CI Verify performs.
- **Idempotency**: re-running the script is a no-op (same counts, no double-edit).
- **tick-179 regression (12 added tests)**: added 12 test functions in `tests/test_tick179.py` → live count 15; script synced README to 15, check passes (`PASS: 12 new tests now reflected`).

Edge cases considered:
- **Parametrized tests**: COUNT comes from `pytest --collect-only`, which expands parametrization — the FILES count stays separate (`find`), so the two lines never disagree about their own meaning.
- **Non-test dirs**: `find tests -name 'test_*.py'` scoped to the suite root, so fixtures/helpers outside it don't inflate FILES.
- **CI runs from repo root**: script run in-repo (as the CI Verify job does); `pytest` config (ini/pyproject) is picked up automatically.
- **Re-running with zero edits** when no drift: `sed` substitution is a no-op if the pattern doesn't match — safe against corrupting unrelated lines.

Note: the live repo was not mounted in this sandbox, so verification ran on the reproduced fixture above; the procedure itself is repo-agnostic and deterministic.
{"model": "deepseek-v4-flash", "problem_class": "docs-test-count-drift-sync", "result": "passed", "tests": 15}
Generated from the verified corpus · MIT licensedBack to the catalog