To stop AI from writing fake tests, fail the lint on three cheats: a mock of the code under test, a fixed sleep, and a retry. Oxlint with the landmines rules did exactly that in my run.
The test file was green. The function it claimed to check was never called.
I had asked a coding agent to add tests for a cart total. What came back replaced the real function with a stand-in that always returned 20. That stand-in is a mock, so the green result cannot fail. A lint reads the file and prints an error without running the app. Oxlint (a fast JavaScript checker) is the lint I used, and landmines is its extra rules. I fail that lint on a mock, a fixed sleep, or a retry. I put all three in one file, plus a raised time limit, and got three errors. The same command was silent on a test that called the real function, and silent on a watcher that only recorded the call.
The path is short. The agent writes a test. The lint reads it. A mock, a sleep, or a retry stops the job. A call to the real function is allowed through, and only then does the test runner decide if the numbers are right.

What a fake test looks like

A fake test is a file that goes green even if the code you ship is wrong.
The common shape is a mock of the thing under test. The test says it checks total, then it swaps total for a function that returns 20 no matter what you pass. The line expect(total(10, 2)).toBe(20) is then checking the swap, not the multiplication. Delete the real function and the test can still pass.
Two cousins show up next to that swap. A fixed sleep waits a guessed number of milliseconds and hopes the work finished. A retry runs the test again until it passes, or raises the timeout so a race usually wins. A test that fails on one run and passes on the next is a flake. Masking a flake does not fix it. It hides it until a customer hits the same race.
None of these need a broken runner. The runner is the program that actually executes the test, and it is doing what the file told it to do. The file is lying before the runner starts.
| What the file does | What a green run means |
|---|---|
Calls the real total and checks 10 times 2 | The multiplication happened |
Mocks total so it always returns 20 | The mock happened |
| Sleeps one second, then checks | A guess about time happened |
| Retries until the check passes | A flake was hidden |
How to stop AI from writing fake tests
Fail the file in the lint, before anyone treats the green run as proof.
I made a throwaway folder and installed the checker (Oxlint) and the rules (landmines on GitHub) with npm. The plugin asks for Oxlint 1.81 or newer, and Node 22.18 or newer. No test runner was needed, because landmines never executes the test. It only reads it.
npm install -D oxlint @interfere/landminesThen I saved this as .oxlintrc.json. I turned on only the three rules that match the cheat. The full recommended file turns on more, and that choice matters on an old repo, so it gets its own section below.
{
"jsPlugins": [
{ "name": "landmines-testing", "specifier": "@interfere/landmines/testing" }
],
"rules": {
"landmines-testing/no-test-doubles": "error",
"landmines-testing/no-fixed-sleep": "error",
"landmines-testing/no-flake-masking": "error"
}
}The code under test was four lines.
export function total(cents: number, qty: number) {
return cents * qty
}The bad test mocked that file, slept, and raised the timeout.
import { vi } from "vitest"
import { total } from "./price"
vi.mock("./price", () => ({
total: () => 20
}))
test("cart total", async () => {
await new Promise((r) => setTimeout(r, 1000))
expect(total(10, 2)).toBe(20)
}, 10000)One command:
npx oxlint src/price.test.tsThree errors, in this order.
no-test-doubleson thevi.mockblock. Do not replace test dependency behavior. Use the real implementation, and use MSW (a local stand-in for the network) for network responses. Spies must only observe.no-fixed-sleepon thesetTimeoutline. Replace the fixed sleep with a signal, or move time withvi.useFakeTimers()and advance it. A sleep guesses how long real work takes and fails when the machine is busy.no-flake-maskingon10000. Do not raise a test’s timeout. Wait on the event, or move slow shared setup intobeforeAll.
A second file used { retry: 3 } on a test that could not fail. That was another no-flake-masking error: do not retry tests. A test that passes on a rerun is a flake.
The honest file called the real function and checked two totals, including zero.
import { total } from "./price"
test("cart total", () => {
expect(total(10, 2)).toBe(20)
expect(total(0, 5)).toBe(0)
})npx oxlint on that file finished with zero errors. That is the path you want the agent stuck on. If it wants a quiet lint, it has to call the code.
This is why a tests-first habit is not enough on its own. UB mode makes the agent show a failing test before the edit. A mock can still go red, then green, without ever running the function you ship. The lint is the extra gate after the order of work is right.
What landmines catches and what it ignores
It catches the shortcut in the text of the test, not a wrong answer from the code.
| Pattern in the test file | Rule | What I saw |
|---|---|---|
vi.mock of the module under test | no-test-doubles | error on the mock block |
await new Promise((r) => setTimeout(r, 1000)) | no-fixed-sleep | error on that await |
test timeout raised to 10000 | no-flake-masking | error on the number |
{ retry: 3 } | no-flake-masking | error on the retry option |
vi.spyOn that does not replace the function | no-test-doubles | no error |
expect(total(10, 2)).toBe(20) on the real function | none of the three | no error |
A spy is a watcher. It records that a function was called. It does not have to change what the function returns. I wrote this and the lint stayed quiet.
import { vi } from "vitest"
import * as price from "./price"
test("spy only watches", () => {
const spy = vi.spyOn(price, "total")
expect(price.total(10, 2)).toBe(20)
expect(spy).toHaveBeenCalledOnce()
})Watching is allowed. Replacing is not.
The error text is part of the product. Each message tells the next edit what to do instead, in the same place the error appeared. That matters because the agent reads the lint output on the next turn. A rule that only says “bad” gets a guessed fix. A rule that says “call the real function” or “advance fake timers” gets a narrower guess.
The pack has more rules if you want them later. One of them requires MSW to fail when a request was not planned. Another bans polling a spy until a deadline. Others care about file names, where the test file sits, and most comments. The three rules above were enough.
Mocked tests and landmines
Yes. A mock of the module under test is an error under no-test-doubles.
I used Vitest’s vi.mock. Vitest is a test runner people use for JavaScript. The message does not care which runner you prefer. It cares that the test replaced behavior. The rule text also names Jest’s jest.mock, a vi.fn that supplies a fake body, stubbed globals, patched prototypes, and fake responses. I only ran the Vitest spelling of the mock.
What it does not call a mock is a spy that only observes. The spy file above is the run I have. If a spy also replaces the function, that is a mock, and I would expect the rule to fire. I have not added that line, so that expectation stays an expectation.
Network is the exception the message itself names. Do not mock your own total to avoid a real HTTP call. Put the fake at the edge of the network with MSW, and turn on the strict rule so a request you forgot does not leak out to the real internet. The cart bug did not need a network, so that rule was not part of this run.
Why a prompt alone won’t stop the mocks
You can, and the next session can ignore you.
A sentence in the chat is gone when the chat is gone. A rules file the agent loads is better than a sentence. Ponytail is that kind of file: it stops the agent from adding code you did not ask for. It still only works if the agent follows the file. Landmines does not ask. The command prints errors. The check that runs when you push, the one people call CI, can refuse the change. The agent can still try a mock. It cannot call the job done while the lint is red.
I would keep one short line in the project instructions anyway, because it saves a round trip. “Do not mock the module under test. Call the real function. Do not sleep or retry to make a test pass.” Then let the lint be the part that does not forget. The prompt is a hint. The lint is the lock.
If you also want the prompt that produced a bad test to stay next to the commit, that is a separate habit, the one in saving the prompt behind the commit. Landmines does not store that prompt. It only blocks the cheat in the file.
Fake tests on an old repo: start with three rules
Turn on the three rules first. Do not start with the full recommended file.
The recommended config that ships with the package also bans most comments, bans written return types, and checks where test files live and what they are named. On my four tiny files, that fuller config still reported only the cheat errors, because those files had no comments and no written return types. A repo that comments every function will light up for reasons that are not fake tests. That noise teaches the agent, and the human, to turn the plugin off.
So the first week is the three rules in the config above. When those are quiet, add the strict network rule if you already use MSW. Add the comment ban only if you actually want comments gone. Some rules accept a per-file allowance with an exact count, so one old file can keep two sleeps while every new file cannot. I had no need for an allowance. The hatch is there so you do not have to clean the whole repo before the rule helps.
Run it the way a person would, not only in CI.
npx oxlint srcIf the agent is the one fixing the errors, give it the error text, and do not accept a change that deletes the rule. A second checker that refuses a lazy result is the same shape as the security-review skill, which throws out a finding that cannot survive a second look. This one throws out a test that cannot touch the code.
When landmines is the wrong tool
Use it for JavaScript and TypeScript tests. Do not expect it to read a Python, Go, or Rust test. Do not expect it to prove that a test can fail.
A test can call the real total and still check a fact that cannot be false. expect(true).toBe(true) after the call is honest about the call and empty about the result. Landmines will not flag that. The rules I turned on look for mocks, sleeps, and retries. They do not break your function on purpose to see which tests notice. Breaking the code on purpose, and counting who goes red, is a different job. If that is the hole you have, this lint will not close it.
It also will not make a slow test fast. The sleep rule tells you to wait on a signal, or to advance fake timers. If the work truly takes time and there is no signal, you still have to change the code so a test can see “done” without guessing a delay. The lint only stops the guess from being the fix.
It will not catch a type trick either, the kind where the code says “trust me” with a chain of casts. That is a different rule pack. Mixing the two jobs in one afternoon is how both get switched off.
I would turn the three rules on in any JavaScript repo where an agent writes tests. I would not treat a green run as proof until those errors are gone. And I would not treat a quiet lint as proof that the assertion itself means something.




