How to stop AI agents from weakening tests
Why coding agents soften failing tests to get a green build, and how locking the tests at approval stops the shortcut.
Suppose a test checks empty input handling like this:
test('rejects empty note names', async () => {
const result = await run('notes add ""');
expect(result.exitCode).toBe(2);
expect(result.fileCreated).toBe(false);
});
If the agent's implementation returns exit code 1 when the specification calls for 2, and the test fails across retries, the agent often leaves its code unchanged and rewrites the test:
test('rejects empty note names', async () => {
const result = await run('notes add ""');
expect(result.exitCode).toBeTruthy();
expect(result.fileCreated).toBe(false);
});
toBeTruthy() passes on exit code 1. The test suite passes while the bug stays in place. The agent optimizes for a passing test run and changes the assertion because the same agent writing the code can also edit the pass criteria.
Why instructions in a prompt break down
Putting “never weaken or delete tests to make them pass” in a system prompt works when tasks go smoothly, and fails when an agent hits friction.
When a failure persists, passing the suite overrides advisory advice in AGENTS.md. The model rarely knows why you picked exit code 2 specifically for a downstream caller, and if that one-word change appears inside a 400-line diff, human reviewers often miss it.
Lock the criteria before code is written
Separating approval of the pass criteria from writing the implementation prevents quiet test edits. In Oystro, that boundary is Human Gate 1.
Before coding starts, you approve a spec file covering the empty-notes requirement (exit code 2, zero files created) and the test command that verifies it. When you sign Gate 1 in the Oystro CLI or local console, Oystro locks the approved test files and owned source files.
Once Gate 1 is signed, the agent edits only files owned by the approved spec, locked test assertions stay protected against silent edits, oystro run executes each scenario fresh, and an independent review quotes the file, line, and passing assertion for every requirement.
When an agent swaps toBe(2) for toBeTruthy(), the Oystro CLI refuses the change. The agent either fixes the implementation so exit code 2 passes or stops and asks you to re-approve an updated specification.
A refusal that points to the fix
A useful guard names what changed and shows the allowed next step, for example:
Refused: approved test fingerprint changed after Gate 1 approval.
Requirement S001-A1 (exit code is 2) is bound to the test state locked at Gate 1.
Fix the implementation, or re-stage Gate 1 approval with
oystro gate request S001 --reapprove if the requirement genuinely changed.
Hitting a hard refusal stops the agent from working around the check and forces either a real code fix or an explicit spec update for you to sign.
What a green suite still leaves unchecked
A passing test suite only confirms that current assertions passed. It does not confirm whether those assertions still match what you originally approved. Oystro pairs the approval-time test freeze with fresh execution receipts, requirement-to-test mapping (catching passing suites that skip your actual requirement), and a clean-context audit with zero shared session bias.
How to check this by hand
You can follow the same discipline with plain git commands:
- Commit the expected tests before instructing the agent to write implementation code.
- Save the acceptance criteria inside the repository so they remain visible after chat scrolls.
- Run
git diffon the test directory before reading any application code. - Read the exact assertion lines covering every requirement you asked for.
- Run the test command yourself on a clean working tree.
This manual check catches weakened assertions every time, though reviewers often skip step 3 on late-day merges. Automated CLI checks enforce it on every run.
What to keep fixed
Keep the coder separate from the definition of done. Lock the acceptance criteria and test assertions before coding begins, and let the Oystro CLI guard that lock until you explicitly approve a change.
Ship AI-Written Code Without Reading Every Line
You decide what gets built and approve what ships, while automatic checks keep your coding agent from skipping tests, weakening assertions, or claiming work that never ran. Install the Oystro CLI, connect your agent with oystro mcp, and open oystro ui to inspect a Gate 1 approval, a verification summary, and a signed release.