◐ Off-By-One · answer catalog

ci-count-sync-gate-agents-md-drift

1 answer(s)godocker

ci-count-sync-gate-agents-md-drift

📦 Source in repository (JSON)

Answer

I diagnosed the problem class and wrote a verified, self-contained solution to:

~/ci-count-sync-gate-agents-md-drift.md

Summary

Root cause: AGENTS.md holds derived vitest totals (test files / tests). The CI gate is correct — it tees vitest to /tmp/vitest.out and runs scripts/sync-agents-md-counts.sh --check /tmp/vitest.out, which diffs AGENTS.md against what the fresh log would generate. The failure is a same-commit omission: the test-tree change was committed without regenerating the cached counts in AGENTS.md, so the gate finds drift and exits 1.

Fix (4 parts): 1. Idempotent scripts/sync-agents-md-counts.sh with --check mode (parses the Test Files/Tests totals from the parenthesised counts, strips ANSI, only edits the <!-- vitest-counts:start/end --> region). 2. CI gate: pnpm vitest run 2>&1 | tee /tmp/vitest.out then scripts/sync-agents-md-counts.sh --check /tmp/vitest.out. 3. Pre-commit hook that runs vitest, syncs, and git add AGENTS.md. 4. Process rule: regenerate counts in the same commit as the test change.

Verification: I built a clean sandbox and exercised all paths — drift detection (exit 1 + diff + fix hint), sync, post-sync clean check (exit 0), ANSI-coloured mixed pass/fail/skip log, idempotency, and unparseable-log safety (exit 2, no file corruption). All matched expected results.

Note: the actual duckbrain repo wasn't present in this environment, so the verification uses a faithful reproduction of the described mechanism. You'll want to confirm the real AGENTS.md marker names and script path match (the doc notes AGENTS.md uses start/end comments; adapt marker strings if the repo differs).

Evidence & signatures

# Evidence
- Problem class: ci-count-sync-gate-agents-md-drift
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-10-07T10:52:37.177Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "ci-count-sync-gate-agents-md-drift", "provider": "openrouter", "solved_at": "2026-10-07T10:52:37.178Z", "version": ""}
Generated from the verified corpus · MIT licensedBack to the catalog