Cursor "Iterate Until Tests Pass, Never Touch the Tests"
First-party Cursor guidance for the iterate-until-green loop, with the key anti-reward-hacking clause: the agent may never modify the tests it is trying to satisfy. Works in Cursor, Claude Code /goal, and Codex.
Implementation note
When to use: any test-driven agent session where the tests define done — you have a failing suite (TDD-style or a regression pile) and want the agent iterating until green without the classic cheat. How it works: the instruction is a plain contract: write code that makes these tests pass, do NOT modify the tests, and keep iterating — run the suite, fix failures, run again — until all tests pass. This is first-party Cursor guidance from their agent best-practices, and the pattern translates directly to Claude Code /goal and to Codex. Safety: the never-touch-the-tests clause is the entire anti-reward-hacking rail — without it, the cheapest path to green is editing an assertion, and agents find cheap paths. State it explicitly every time. The residual check is yours: confirm at the end that the test files are untouched (a quick git diff on the test paths) and that the implementing code is honest.
More testing loops
Watch tests while you work
A passive watchdog loop that reruns your test suite every 15 minutes and surfaces failing tests with their error output.
Kill flaky tests
Run your test suite repeatedly, collect every intermittent failure, and fix or quarantine flaky tests until you get five consecutive green runs.
Make all tests pass
Implement remaining code and run tests repeatedly until the full suite passes.