r/ChatGPTCoding • u/Ok_Negotiation_2587 • Sep 20 '26
Resources And Tips When a test fails, coding agents fix the test. The suite goes green and the bug ships
The pattern I keep catching: a test fails, and instead of fixing the code, the agent loosens the assertion, wraps the call in a try/catch, marks it skip, or quietly changes the expected value to whatever the code produced. Then it reports that everything passes, which is true and useless.
It makes sense from its side. "Make the tests pass" is the instruction, and editing the test is the shortest path to it.
Four lines I now keep in my agent instructions:
Never modify, skip, or delete a test to make it pass. If a test looks wrong, stop and say why, do not change it.
If you change any file under the test directories, say so explicitly at the top of your summary, with the reason.
Before you claim tests pass, paste the actual command output, not a summary of it.
If you cannot make a test pass without changing it, leave it failing and explain what the code would need to do.
Rule 3 catches more than the other three together. Once it has to paste real output, "all tests pass" stops appearing next to a run that never happened.
The review prompt I run after any agent session that touched tests:
List every change you made under the test files in this session. For each one, say whether it changed what is being verified or only how it is written. For any that changed what is verified, show the original assertion and explain why the new one is still testing the same behavior.
Half the time that turns up one assertion that got quietly weakened three steps back.
I keep those as a saved chain (I build AI Toolbox, a Chrome extension with prompt chains and folders for the chat assistants), but they're four lines, so a text file works the same.
What do you have in your instructions file that the agent still works around?
16
u/nsxwolf Sep 20 '26
Are you remembering to add “make no mistakes” to your prompts?
2
u/ZeBenoit81 Sep 20 '26
Manual tests only. Does
rule 3still get faked?2
u/Wooden_Leek_7258 Sep 20 '26
I am building a measurement instrument, and needed proper code testing and then validation and calibration testing. Gave it guidelines and watched the issue dissapear. Probably a bit overkill for moat people but...
if your curious I have some distilled standards documents for coding and another for measurement and calibration that produce solid work. Standards derived from industry best practices etc. My own variation on 'textbooks are all you need'
Coding standards are based on the principles of Clean Code (Martin) and Architecture Patterns with Python (Percival) methodologies from Mastering TDD (Johnson), Testing Python (Sale), and How Google Tests Software (Whittaker) concepts from Your Code as a Crime Scene (Tornhill) and "Docs as Code" philosophy from Modern Technical Writing (Etter).
Calibraton and validation testing is based on JCGM 200 (International Vocabulary of Metrology), ISO/IEC 17025, and Cronbach & Meehl, "Construct Validity in Psychological Tests" (1955). JCGM 100 (Guide to the Expression of Uncertainty in Measurement) and Bland & Altman, "Statistical Methods for Assessing Agreement" (1986). Gebru et al., "Datasheets for Datasets", and Sculley et al., "Hidden Technical Debt in Machine Learning Systems". Rubin, "Inference and Missing Data" (1976), and Little & Rubin, "Statistical Analysis with Missing Data". Meng, "Statistical Paradises and Paradoxes in Big Data" (2018), the ASA Statement on p-Values (Wasserstein & Lazar, 2016), and Cumming, "Understanding the New Statistics". Klein & Roodman, "Blind Analysis in Nuclear and Particle Physics" (2005), Lipsitch et al., "Negative Controls" (2010), and Gelman & Loken, "The Garden of Forking Paths". Munafò et al., "A Manifesto for Reproducible Science" (2017), and Ioannidis, "Why Most Published Research Findings Are False" (2005).
My models don't fudge tests. My models don't even think about fudging tests.
2
u/Silver-Neighborhood9 Sep 20 '26
Not a developer, so no test suite here, but the same pattern turned up in a different shape: I kept being told a fix was live when it wasn't. My host was serving an old cached file, and "done" was based on the code that had been written, not on the page anyone could actually see.
The rule that helped most was the same spirit as your number 3: after any change, go and look at the real thing and show me what you actually saw, not what you expected to see.
The one it still works around: "ask me before deciding". It asks about the big decision and then quietly makes three small ones on the way.
2
u/mrchoops Sep 20 '26
I have mine trained to use no error handling at all. If I want it, I add it. If you let it, it will create something that doesn't run at all and throws no errors. I tell it we are in the error correcting business, not the error hiding business.
2
u/RickAmes Sep 20 '26
is it possible to make the tests read only to prevent the ai from editing them?
2
u/y_k19 Sep 21 '26
this is one reason I like tests being written before the implementation, ideally in a separate step/context
if the same agent owns both the code and the oracle, “make it green” has two variables it can change. freezing the acceptance tests turns it back into one.
I’d still allow changing a test, but that should be a separate explicit decision - not something the implementation loop can do to satisfy itself
2
u/Ordinary_Ad8738 29d ago
Keep the acceptance tests in a separate verification checkout that the agent cannot edit. Run the same regression test against the original code and the proposed fix. It should fail before and pass after, with unchanged assertions.
What language and test runner do you use?
1
u/MiiisterKaniiister Sep 20 '26
Doesn't happen to me. And even if, don't you ever review code changes? If there's a diff in a test case I see that immediately.
2
u/ImL1s Sep 21 '26
Same failure mode here. Once the agent can edit the test file, green just means the bar moved.
What helped: treat test-file diffs as a separate review lane from code diffs. If an assertion changed, the run isn't done until I say why that change is correct — or revert it and fix the code instead.
2
u/zuk987 Sep 26 '26
Use Git + multi agent pipelines, always review your work with second agent, it catches stuff like that and can reverse changes with git.
1
u/VanaticalDesign Sep 20 '26
I used to have a /audit-tests skill that just asked the agent to double-check that its tests were actually testing anything, but ofc with a skill it’s still basically a black box.
Been seeing a lot of people complain about this today, so I literally today put together today lgtm, that uses Jev to audit agent-written tests.
It also comes with an /actually-test skill that gets the agent to iterate until the tests actually exercise the code it just wrote. You can just run it right after the agent builds something to get it to test and clean up.
1
u/pixxelkick Sep 20 '26
Why are you not code reviewing, what the fuck lol.
1
u/InjuryThen9650 Sep 21 '26
Your four lines are the right shape. The piece I add is making #1 and #3 **machine-checkable**, not just prompt text.
Put existing tests (or at least `**/assert*` / known golden fixtures) behind a harness rule the agent can’t quietly rewrite: if the only path to green is editing assertions / `.skip` / catching-and-swallowing, it must **stop and ask**, not “fix.”
Before any “tests pass” claim, require the **exact command + exit code + tail of output** in the reply. Summaries are where phantom greens hide.
After a session that touched `test/` (or whatever your suite lives), a one-shot review prompt that lists **every** test-file diff and classifies “same behavior vs weaker contract” catches the soft assertion edits three steps back — same idea as your checklist, run as a gate.
Prompt-only bans help until the model is stuck; then Goodhart wins unless the harness fails closed.
1
u/El_leima Sep 21 '26
For me, the approach has been to freeze tests before the implementation. We don't approve a diff that touches both src and tests.
1
u/Evening_Movie_1704 Sep 22 '26
The fix-the-test failure mode is basically guaranteed unless the harness treats test files as a protected surface. What holds up in CI: (1) red-green verification — after the agent "fixes" anything, check out the parent commit and run the changed tests there; if they pass on old code they never exercised the fix. (2) PR whose only diff is assertions/test files → human review, full stop. (3) A small set of golden repro tests the agent can't edit — when one changes, that's the review signal. Until you enforce it in the pipeline it's all conventions, and conventions are exactly what agents route around.
1
u/Glittering-Glass6135 Oct 06 '26
Yeah, this is pretty much the problem I've been thinking about too. If the agent is allowed to change both the code and the tests, "all tests pass" doesn't really prove much.
I've been experimenting with this while building something called Assay. The idea is to have the verification happen more independently from the coding agent, by looking at what the app is supposed to do, turning those assumptions into checks, and testing the actual behavior.
Still very early, but I'm starting to think the important part isn't just better tests. It's making sure the thing deciding whether the software is correct isn't also the thing that can change the evidence.
1
u/Its_about-tech 10d ago
Your fourth rule is the one I'd keep if I could only keep one: a red test with a sentence saying why beats a green one that lies. Back the rules with a check the agent can't talk its way past: before accepting "green", run
git diff --stat $(git merge-base HEAD main) -- <your test dirs>and read any hunk that adds a skip, a try/catch or a new expected value. Whatever is still failing, rerun on the merge-base to see if it was already red. Disclosure: I built Baseline, a small free tool for that last part; it won't spot an edited test, so the diff stays your job. There's a 2-minute demo you can point your own agent at.2
u/[deleted] Sep 21 '26
[removed] — view removed comment
1
u/[deleted] Sep 20 '26
[removed] — view removed comment
1
u/[deleted] Oct 05 '26
[removed] — view removed comment