Ask a coding agent for tests and you get a wall of green checkmarks in a few minutes. Flip a > to >= in the code under test, run them again, and a worrying number are still green.

The fix isn't a better prompt. It's a short chain of tools that tells the agent where the gaps are and then checks whether its tests would notice a bug. Here's the workflow I'd use in 2026 for backfilling tests on a TypeScript module, one tool per step.

Step 1: Find the gaps with Vitest coverage

Run vitest run --coverage with the default v8 provider. One catch: by default the report only lists files your tests already import, so set coverage.include to something like src/**/*.ts or the completely untested files never show up.

// vitest.config.ts export default defineConfig({ test: { coverage: { include: ['src/**/*.ts'] } }, }) 

Nice detail: when Vitest detects it's running inside an AI coding agent, it trims the text coverage report (fully covered files are hidden, a summary table is added) so the agent reads less output.

Step 2: Give the agent house rules in CLAUDE.md

Before the agent writes a single test, put the rules in CLAUDE.md, which Claude Code reads at the start of every session (it can also read an existing AGENTS.md). Mine would be short:

## Tests - Test current behavior first, even if it looks wrong. Note suspected bugs, don't fix them. - No snapshot tests for logic. - Never mock the module under test. - Run `npx vitest run <file>` after every new test file. 

The docs are clear that CLAUDE.md is context, not enforced config, so keep the rules specific and few.

Step 3: Stop real network calls with MSW

Agents love to mock fetch by hand, a different way in every file. Mock Service Worker describes the network once in request handlers, and the same handlers work with fetch, axios and friends. In Node it intercepts at the socket level, so one setupServer(...handlers) in your Vitest setup file covers every test, and a per-test server.use() override can fake a 429 or a 500 to test the error path.

Step 4: Add properties with fast-check

Example tests only cover the inputs someone thought of. fast-check generates hundreds of inputs per property and, when one fails, shrinks it down to the smallest input that breaks things. It works inside Vitest without any plugin. Ask the agent for one property per pure function, like "parsing what we serialized returns the original" or "sorting twice equals sorting once".

Step 5: Watch it all in Vitest UI

vitest --ui opens Vitest UI in the browser, stays in watch mode and reruns tests as the agent saves files. You can rerun a single test, see coverage inline and open the module graph, which beats scrolling the agent's terminal to figure out which of 40 new tests just broke.

Step 6: Check the tests can fail with StrykerJS

This is the step that separates real tests from decoration. StrykerJS makes small changes (mutants) to your source and reruns the suite; any mutant that survives is a bug your tests wouldn't catch. Install the Vitest runner and use incremental mode so reruns only test what changed:

npx stryker run --incremental --mutate src/pricing.ts 

Then paste the surviving mutants back to the agent and ask for tests that kill them.

Step 7: Check what's left on your plan with TokenBar

That last loop (survivors in, new tests out, Stryker again) is the longest and most token-hungry part of the whole job, and I'd rather not start it with ten minutes of quota left. TokenBar is a macOS 14+ menu bar app that shows usage and reset times for Claude, Codex, Cursor, Gemini and Copilot, so I can pick which agent runs the mutant loop. It's $5/month Basic or $15 lifetime Pro, gives no extra quota, and is built on Peter Steinberger's MIT-licensed CodexBar, with credit to Pixel Agents.

TokenBar menu bar panel showing Codex at 9% of its 5-hour session used, a reset in 1 minute, 42% of the weekly limit used with 2 days 4 hours left, and a pace check projected to last until reset

Step 8: Keep it honest on every PR with Codecov

Upload the coverage file from CI and Codecov comments on each pull request with patch coverage, so the next agent-written change can't quietly skip tests. The Developer plan is free (unlimited for public repos, 250 private repo uploads a month for one user), and Team is a paid per-user plan.

The chain at a glance

Step Tool What it answers
1 Vitest coverage Which files have no tests?
2 CLAUDE.md What counts as a good test here?
3 MSW How do we fake the network once?
4 fast-check What inputs did nobody think of?
5 Vitest UI What just broke?
6 StrykerJS Would these tests catch a bug?
7 TokenBar Is there quota left for the fix loop?
8 Codecov Did this PR add untested code?

What's your mutation score on the code your agent tested last, and have you ever dared to run it?