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.

prompt
→ Claude
"Write code that makes these tests pass. Do NOT modify the tests. Keep iterating — run the suite, fix failures, run again — until all tests pass." (paraphrase of Cursor's official agent best-practices guidance)
claude-code

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.

Source: Cursor blog

More testing loops

Stabilize flaky tests for good

Measure the flakiness, fix one root cause at a time, and stop after a defined streak of stable full-suite runs.

prompt
→ Claude
Run [test suite] [N] times under the same conditions and list tests whose result changes. Fix the most frequent flake at its root cause—shared state, timing, ordering, or an external dependency—never with a blind sleep or retry. Run that test [N] times, then rerun the full suite. Repeat until [N] consecutive full-suite runs pass, progress stalls, or approval is required. Return each flake, root cause, fix, evidence, and justified quarantine.
testingmedium riskclaude-codecodex

Build a todo CLI app with tests

Loop/ralphnew

Ralph autonomously builds a todo CLI application with comprehensive test coverage over multiple iterations until complete.

prompt
→ Claude
/ralph-loop "Build a todo CLI app with tests" --max-iterations 30
testinglow riskclaude-code

Kill flaky tests

Loop/loop

Run your test suite repeatedly, collect every intermittent failure, and fix or quarantine flaky tests until you get five consecutive green runs.

prompt
→ Claude
/loop run my test suite 20 times, collect every intermittent failure, fix or quarantine the flaky ones, and don't stop until you get 5 consecutive fully-green runs
testinghigh riskclaude-codecursor