🤖 The AI Prompt That Finds Which Test Assertion Is Flaky
When a single test in a large suite fails intermittently in CI, the hard part usually isn’t spotting that the test is flaky – it’s figuring out which of the several assertions inside that one test body is the one actually producing a different result between runs, especially in an integration test with ten or more assertions back to back. A well-structured prompt handed the test’s full source plus a handful of real CI run logs, both passing and failing, can narrow a forty-line test down to the one comparison that’s nondeterministic, in far less time than adding print statements and waiting for the flake to reproduce again.
📋 The Prompt
You are reviewing a flaky integration test. I will give you: 1. The full source of the test method (including every assertion) 2. Logs from 3 CI runs where the test PASSED 3. Logs from 3 CI runs where the test FAILED Your task: - For each assertion in the test, determine whether its expected and actual values could plausibly differ between runs (timing, ordering, floating-point precision, environment-dependent state, uninitialized shared fixtures, etc.) - Rank the assertions from most to least likely to be the actual source of the flake, with a one-sentence reason for each - For the single most likely assertion, propose the smallest possible code change that would make its outcome deterministic - Do NOT suggest simply adding a retry or increasing a timeout unless you can point to specific evidence in the logs that timing is the cause [paste test source] [paste passing run logs] [paste failing run logs]
✅ Use It Well
- Always include both passing AND failing log excerpts – a prompt given only the failure has to guess at the test’s normal behavior, while one with both can compare them directly and often spot the exact diverging value.
- Ask explicitly for a ranked list rather than a single answer; a test with multiple borderline assertions benefits from seeing the full reasoning, because the actual flake is sometimes the second-ranked guess rather than the first.
- Paste the real, unedited test source – trimming “irrelevant-looking” setup code is exactly how a shared fixture’s hidden state, the actual cause more often than not, gets accidentally removed from what the model can see.
🚨 Why This Is Dangerous
A ranked list of likely causes is a starting point for investigation, not a verdict – treating the model’s top guess as confirmed and shipping a fix without actually reproducing the flake under the proposed change can leave the real nondeterminism in place while everyone believes it’s solved.
The model doesn’t know which assertion is flaky any more than you do – what it’s actually good at is reading ten log lines faster than you can, and that’s the whole value of the prompt.




