wowprompt

Flaky test diagnosis from failing CI runs

Reads a test that passes and fails without code changes, along with its CI logs, and finds the likely cause, such as timing, shared state, order dependence or network calls, with a concrete fix. Use it when a pipeline keeps going red for no clear reason and retries have become the habit.

A ranked list of likely causes with the evidence from the logs, the fixed test code, and steps to confirm the test is stable
The output this prompt produced, unedited.

The prompt

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

  1. Compare the failing and passing runs and note what differs.
  2. 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.
  3. Name the most likely cause and point to the exact line.
  4. 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.
flaky testsintermittent test failuresci test failurestest isolationrace condition in testsunstable test suite

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity