Goal
Find why this test fails only some of the time and fix the cause, not the symptom.
Inputs
- Test framework and language: [e.g. Jest with TypeScript, pytest, JUnit]
- Test code: [paste the failing test and any setup or teardown it uses]
- Code under test: [paste the relevant function or module]
- Log from a failing run: [paste the error and stack trace]
- Log from a passing run, if available: [paste]
- Failure pattern: [e.g. 1 in 10 runs, only in CI, only when run with the full suite, only on Mondays]
Steps
- Compare the failing and passing runs and note what differs.
- Check these causes in order: test order and shared state, time and timezone, async waits and fixed sleeps, random data, real network or file system, parallel workers sharing a resource, leaked mocks.
- Name the most likely cause and point to the exact line.
- Rewrite the test or the code so the cause cannot occur.
Output format
- | Rank | Suspected cause | Evidence from the inputs | Confidence |
- The fixed code in one fenced block, with only the changed lines commented.
- A command to repeat the test many times or in random order to confirm the fix.
- One sentence on whether the code under test, not only the test, has a real bug.
Check before answering
- No fix that only adds a retry or a longer sleep.
- Evidence is quoted from the pasted logs, not assumed.
- If the inputs are not enough to decide, say which log or detail would settle it.






