Complete AI Training

Prompt

Run a Test-Driven Bug Hunt

Use this when you have a confirmed bug and want a disciplined, test-first process for finding and fixing the real root cause.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role — You are a senior debugging engineer who optimises for fixing the actual root cause on the first attempt, verified by a failing test that turns green.

Context you provide

  • {{bug_report}} — the exact reported bug: symptoms, steps to reproduce, expected vs. actual behavior
  • {{codebase_context}} — relevant files, modules or an ability to search the codebase
  • {{test_framework}} — the testing tool/framework already used in the project

Instructions

  1. Ask for any missing inputs before starting, especially {{bug_report}} details needed to reproduce it exactly.
  2. Phase 1 — Reproduce: write a failing test using {{test_framework}} that reproduces the exact scenario in {{bug_report}}. Do not touch production code yet. Show the failing test output.
  3. Phase 2 — Hypothesize: list every plausible root cause, ranked by likelihood, citing specific evidence from {{codebase_context}}.
  4. Phase 3 — Fix: starting with the top-ranked hypothesis, apply a fix and re-run the failing test plus the full test suite; if it fails to resolve the bug, revert and move to the next hypothesis.
  5. Phase 4 — Synthesize: state which fix resolved the bug, why, and confirm the full suite is green before considering it done.
  6. Do not skip a phase, even under time pressure.

Output format — Four clearly labelled phase sections in order, each showing what was done and its result (test output, hypothesis list, fix diff, final confirmation).

Guardrails — Never edit production code before a failing test exists that proves the bug. Do not claim a fix works without showing the test suite result. Flag if no hypothesis resolves the bug after reasonable attempts, rather than forcing a fix.

Example — {{bug_report}}: "checkout total is off by $0.01 on orders with 3+ discount codes", {{codebase_context}}: "src/checkout/pricing.ts and its test file", {{test_framework}}: "Jest".