●  Agent loops \u00b7 coverage until threshold \u00b7 copy-paste playbook
EST. 20241 makerBuilt in public
Agent loop \u00b7 Test loop \u00b7 6 steps

Coverage Until Threshold
test to the number.

For code that works but is under-tested. Each round adds a few targeted tests for the least-covered lines, re-measures, and stops the moment the agreed threshold holds.

Typical run: 20–45 min typical \u00b7 Copy any prompt box and hand it to your agent as-is.

Loops / Coverage Until Threshold

\u00a7 01

When to use

6 steps20–45 min typical
  • A pull request adds logic without tests, and reviewers keep asking “where are the tests?”.
  • Coverage slipped after fast feature work and you want it back without a week-long testing detour.
  • You can state a number first (for example: 80% lines on changed files) instead of “tested enough”.
  • The suite runs locally in minutes, so measuring after every round is cheap.
\u00a7 02

The steps

one prompt per stepcopy \u00b7 paste \u00b7 run
01Set the number and the scope
Set the coverage target and scope in one message. Example: "Target: 80% lines and 70% branches on src/checkout/**. Measure with npm run coverage -- --scope=src/checkout. Report the current numbers and the 3 least-covered files, then stop. Do not write tests yet."
Why: A loop without a target number never ends — write both down first.
02List the uncovered lines
Read the latest coverage report. List the top 10 uncovered lines or branches in the scoped files, grouped by file. Do not write code yet — just report the list, then stop.
Why: Testing blind wastes rounds — aim at the exact lines the report names.
03Add one focused test batch
Write at most 3 focused tests covering items from the uncovered list. Each test name must reference the behavior it covers. Run only the scoped test files, paste the pass/fail result, then stop.
Why: Small batches keep each test tied to a line it covers.
04Re-measure the scope
Re-run the scoped coverage command. Report lines %, branches %, and whether the target is met. List what is still uncovered, then stop.
Why: Coverage must be re-read from the tool, never estimated.
05Prune weak tests
Review the tests added in this loop. Every test must fail if the code it covers is broken (mutate or comment out one line to check at least 2 tests). Delete or fix any test that passes regardless. Report which tests were checked, then stop.
Why: Threshold-chasing invites empty assertions — check each test earns its place.
06Lock the threshold
Add or update the coverage gate (CI config or package.json script) so the agreed target is enforced on the scoped files. Run the gate once to prove it passes. Paste the config snippet and the passing output, then stop.
Why: A passing number that is not enforced will drift again next week.
\u00a7 03

Stop conditions

exit criteria
  • Scoped lines % and branches % both meet or beat the agreed target on a fresh run.
  • The coverage gate is committed and passes in CI (or locally with the exact CI command).
  • Every test added this loop fails when its covered line is broken (spot-checked, at least 2 tests).
\u00a7 04

Failure modes

what goes wrong + guardrail

Vanity tests that assert nothing

Symptom: coverage climbs but bugs still slip through. Guardrail: require the break-it check in step 5 — a test that cannot fail is deleted.

Scope creep into the whole repo

Symptom: a 30-minute loop becomes a full-suite rewrite. Guardrail: freeze the file scope in step 1; out-of-scope files need a new loop.

Flaky tests get committed

Symptom: threshold passes once, fails on retry. Guardrail: run the new tests 3 times before locking; any flake is fixed or removed.

\u00a7 05

More loops

5 playbooks
\u2190 All loopsmosaic/lab \u00b7 agent loops