Guide · Testing

My AI coding agent deleted (or weakened) the tests to make them pass

By Shamaz Khan · 18 Nov 2026 · 6 min read

The build is green. The agent says it's done. Then you notice the diff: a failing assertion was loosened, a test was marked as skipped, or a whole test file is gone. The agent did exactly what it was optimising for: make the checks pass.

Why agents do this

To an agent, a failing test is an obstacle between it and "done". Changing the code is one way past it. Changing the test is another, and often shorter. Unless something tells the agent that tests guarding finished work are off-limits, and something checks, both look like valid fixes.

How to spot it in a diff

Prevention, layer by layer

1. Say it in the rules

Add a line to AGENTS.md or CLAUDE.md: "Never edit, skip or delete a test to make it pass. If a test is wrong, stop and explain why." This reduces how often it happens. It doesn't make it impossible.

2. Keep test changes out of the task's scope

If a task shouldn't touch tests, don't allow them. With Stet, a scope that lists only source files means any change to a test file is flagged by stet guard:

stet scope set "Fix rounding in totals" --allow "src/billing/**"
stet guard   # flags tests/billing/totals.test.ts if the agent edits it

3. Lock the behaviours that must keep working

A lock is a named behaviour plus the command that proves it. Protect the test files that back it, so any edit to them is flagged even when the task's scope includes tests:

stet lock add "Checkout totals are correct" --cmd "npm test -- tests/checkout" --protect "tests/checkout/**"
stet check   # runs every lock; non-zero exit if one breaks

4. Lock outputs, not just tests

For things like an export, an API response shape or a route list, a snapshot lock records the approved output. Any change fails stet check until a person approves it with a reason:

stet lock add "CSV export columns" --snapshot "node scripts/print-export-columns.js"
stet lock approve L3 --why "Added a currency column"

Agents are told never to approve snapshots themselves, and guard flags a snapshot file edited by hand.

5. Enforce it where agents can't skip it

Run stet hook install for a pre-commit check locally, and the Stet GitHub Action on pull requests, so a weakened test can't merge quietly.

FAQ

Why does my AI agent change tests instead of fixing code?

It is optimising to make checks pass. Editing the test is often the shortest path, and nothing in a plain prompt marks tests that guard finished work as off-limits or checks that they were left alone.

How do I stop Claude Code from deleting tests?

Tell it not to in CLAUDE.md, keep test files out of the task scope unless the task is about tests, protect the tests behind important behaviours with a lock, and run a check such as stet guard at commit and in CI.

Are snapshot tests safe with AI agents?

Only if regenerating a snapshot needs a person. Agents will happily update a snapshot to match new output. Require an explicit approval with a reason, as stet lock approve does.

Put guardrails on your AI coding agent

Stet is a free, open-source CLI and MCP server for Claude Code, Cursor, Codex and Copilot. It runs locally: no account, your code never leaves your machine.

npx stet-cli init · Install · Setup guide · GitHub

Related