Skip to content
Agent loop · Testing

Coverage Until Threshold

Measure test coverage, write meaningful tests for the least covered code, and repeat until the project clears your coverage target without padding.

Up to 8 iterationsStop rules and safety limits
The prompt

Copy the Coverage Until Threshold loop

Stops when line coverage meets the target and every new test passes, or after 8 iterations. Edit the settings block, then paste the whole prompt into your agent.

coverage-until-threshold.prompt.md
You are running the "Coverage Until Threshold" loop.

Settings (edit before running):
- Coverage command: npx vitest run --coverage
- Target: 80% line coverage
- Scope: src/ (ignore generated files, type-only files, and test helpers)
- Max iterations: 8

Goal: reach the line coverage target with tests that check real behavior.

Each iteration:
1. Run the coverage command and read the per-file report for the scope above.
2. Pick up to three files with the most uncovered lines that contain real logic.
3. For each, write tests that assert results: normal cases, edge cases, and error paths. Follow the existing test style, naming, and helpers.
4. Run the full test suite. Every test must pass.
5. Sanity check one new test per file: temporarily break the code it covers, confirm the test fails, then restore the code.
6. Re-run coverage. Write one line: iteration, files covered, coverage before and after.

Stop when:
- Coverage meets the target and the suite passes. Success.
- You reach the max iteration count.
- Two iterations in a row raise coverage by less than 1 point. Report which code is hard to test and why.

Rules:
- Do not change production code, except to export something a test needs. Mention every such change.
- No snapshot-only tests, no tests without assertions, and no assertions that only check that a function was called.
- Do not lower the threshold, change coverage configuration, or add files to the ignore list.
- Mock network and time, but do not mock the module under test.

Final report: coverage before and after, new test files, and the uncovered areas you would test next.
When to use it

When this loop fits

  • CI enforces a coverage threshold and a new module dragged the number below it.
  • You inherited a codebase with thin tests and want a safety net before refactoring.
  • You want tests for a specific directory without hand-writing the boilerplate.
How it works

What happens on each pass

The agent repeats these steps until the stop condition holds or it runs out of iterations.

  1. Measure. Run the coverage command and read the per-file report.
  2. Pick targets. Choose the files with the most uncovered lines that contain real logic, skipping generated code and plain re-exports.
  3. Write behavior tests. Add tests that assert outcomes, including edge cases and error paths, not just calls that execute lines.
  4. Run and verify. Run the suite, confirm the new tests pass, and check that they fail when the code under test is broken.
  5. Re-measure. Record the new coverage number and continue until the target is met.
Recommended servers

MCP servers for this loop

The 6 strongest of 1059 matching servers, ranked by how closely they fit and then by trust score.

More in Developer tools
  • Trust score 67 of 100, Good

    Medicare national and local coverage policy from the official CMS Coverage API.

    RegistryRemote
    LicenseQualityMaintenanceLicense: A. MIT is a permissive open source license.Quality: A. 95/100 for listing completeness. Lost points: short summary.Maintenance: A. Last commit or release 10 days ago.
    0 stars31/wk weekly downloads27 tools
  • Trust score 55 of 100, Fair

    Testing MCP for coding agents: exercise real user journeys, find bugs, verify them with evidence.

    Registry
    LicenseQualityMaintenanceLicense: Not graded. No license is recorded for this server.Quality: Not graded. No README or tool list has been captured yet.Maintenance: Not graded. No commit or release date has been recorded.
    — stars—/wk weekly downloads— tools
  • Trust score 55 of 100, Fair

    Scans live pages with the AudioEye rules engine and maps accessibility issues to JSX source.

    Registry
    LicenseQualityMaintenanceLicense: Not graded. No license is recorded for this server.Quality: Not graded. No README or tool list has been captured yet.Maintenance: Not graded. No commit or release date has been recorded.
    — stars—/wk weekly downloads— tools
  • Apex by DRIP: A/B testing for online shops logo
    Trust score 52 of 100, Fair

    A/B testing for online shops. Read results, build and preview test variations from chat.

    RegistryRemote
    LicenseQualityMaintenanceLicense: Not graded. No license is recorded for this server.Quality: Not graded. No README or tool list has been captured yet.Maintenance: Not graded. No commit or release date has been recorded.
    — stars—/wk weekly downloads— tools
  • Trust score 52 of 100, Fair

    Book backflow testing in Charleston, SC: prices, ZIP coverage, free callback.

    RegistryRemote
    LicenseQualityMaintenanceLicense: Not graded. No license is recorded for this server.Quality: Not graded. No README or tool list has been captured yet.Maintenance: Not graded. No commit or release date has been recorded.
    — stars—/wk weekly downloads— tools
  • Trust score 52 of 100, Fair

    Coverage Cat

    Unknown author

    Insurance calculators and umbrella/homeowners shopping, purchase status, policies, and support.

    RegistryRemote
    LicenseQualityMaintenanceLicense: Not graded. No license is recorded for this server.Quality: Not graded. No README or tool list has been captured yet.Maintenance: Not graded. No commit or release date has been recorded.
    — stars—/wk weekly downloads— tools
Run it

How to run this loop

  1. Connect the tools. Install a server the loop can use, for example Medicare Coverage, or rely on your agent's built-in terminal and file access.
  2. Edit the settings block. Replace the example commands, targets, and limits with your project's own. Keep the iteration cap low on the first run.
  3. Paste it into an agent session. Start a fresh session in Claude Code, Cursor, or VS Code agent mode, in the repository root, and paste the prompt.
  4. Review before you merge. Read the final report and the diff. The loop leaves its work for you to review rather than shipping it.
FAQ

Coverage Until Threshold questions

When does the Coverage Until Threshold loop stop?

It stops as soon as line coverage meets the target and every new test passes. It also stops after 8 iterations by default, or earlier when the prompt's own stop rules say it is stuck, and then reports what changed and what is left. Change the cap in the settings block at the top of the prompt.

How do I stop the agent from writing tests that only chase the number?

The prompt bans assertion-free and snapshot-only tests and asks the agent to break the code under test once to prove a new test can fail. That mutation check is the single best guard against tests that execute lines without verifying anything.

What coverage target should I use?

Use the threshold your CI already enforces, or a few points above your current number. Raising coverage from 40% to 90% in one run tends to produce shallow tests; several runs with modest targets give better ones.

Keep exploring
All loops