ForkFree

Prompts / Coding

Turn Vague Bug Reports Into Concrete Objectives

You get a bug fix broken into a reproduction, a minimal change and a regression test, each checked against clear objectives. Concrete objectives stop the model drifting into large rewrites or guessing at what "fixed" means.

Worked in our testIt followed every step and the output format, flagged the £52 versus £58 inconsistency, and gave a sound fix and tests. But the function returns the number 58 rather than a value shown to two decimal places, and the checklist still marks that objective "met". It also left the tests and reproduction unrun.

The prompt

You are a senior software engineer who fixes bugs with small, verifiable changes.

Task: Fix the bug described below. Do not work from a vague goal such as "make it work". Turn it into concrete, checkable objectives first.

Bug report: {bug_report}
Relevant code: {code_snippet}
Expected behaviour: {expected_behaviour}

Steps:
1. Restate the bug as three to four concrete objectives, each of which can be shown as done or not done.
2. Reproduce the failure: give the exact input, the command or test that triggers it, and the wrong result it produces.
3. Propose the smallest fix that meets the objectives, and explain why you left other changes out.
4. Write a regression test that fails before the fix and passes after it.
5. Check each objective and say whether the fix meets it.

Output:
A numbered list of objectives, then a "Reproduction" section, a "Fix" section with a code diff, a "Regression test" section with code, and a final checklist marking each objective as met or not met. Keep prose brief.

Change the parts in curly braces. Use it when you have a bug report and want a small, tested fix rather than a broad rewrite.

What happened when we ran it

We sent

You are a senior software engineer who fixes bugs with small, verifiable changes.

Task: Fix the bug described below. Do not work from a vague goal such as "make it work". Turn it into concrete, checkable objectives first.

Bug report: Customers on our online shop are charged the wrong total when they apply a 10% discount code to an order containing an item that is already on sale. Yesterday a basket with a £40 sale item and a £20 regular item came to £54 instead of £52. Support has had three complaints since Monday.
Relevant code: function applyDiscount(items, percent) {
  let total = 0;
  for (const item of items) {
    total += item.price;
  }
  const discounted = total * (1 - percent / 100);
  return Math.round(discounted);
}
Expected behaviour: The 10% code should apply only to items not already on sale. The result should be returned in pounds to two decimal places, not rounded to a whole number. For the basket above, the total should be £58.00 (£40 sale item plus £18 for the discounted regular item).

Steps:
1. Restate the bug as three to four concrete objectives, each of which can be shown as done or not done.
2. Reproduce the failure: give the exact input, the command or test that triggers it, and the wrong result it produces.
3. Propose the smallest fix that meets the objectives, and explain why you left other changes out.
4. Write a regression test that fails before the fix and passes after it.
5. Check each objective and say whether the fix meets it.

Output:
A numbered list of objectives, then a "Reproduction" section, a "Fix" section with a code diff, a "Regression test" section with code, and a final checklist marking each objective as met or not met. Keep prose brief.

The model replied

**Note on the report:** the code gives £54 for this basket (60 × 0.9), which matches the "wrong" figure. The "£52" in the report doesn't match the expected behaviour, which says £58.00, so I treat £58.00 as correct. I also assume sale items are flagged with `item.onSale === true`. Please confirm the real field name. ## Objectives 1. Items with `onSale: true` are never discounted. 2. Items not on sale get `percent`% off. 3. The result is in pounds to 2 decimal places, not rounded to a whole number. 4. The basket `[{price: 40, onSale: true}, {price: 20, onSale: false}]` at 10% returns `58.00`. ## Reproduction Save as `repro.js` with the original function, then run `node repro.js`: ```js console.log(applyDiscount( [{ price: 40, onSale: true }, { price: 20, onSale: false }], 10)); ``` Result: `54` (expected `58`). The discount is applied to the whole £60, including the sale item, and the result is rounded to a whole pound. I have not executed this; the result comes from tracing the code. ## Fix ```diff function applyDiscount(items, percent) { - let total = 0; - for (const item of items) { - total += item.price; - } - const discounted = total * (1 - percent / 100); - return Math.round(discounted); + let pence = 0; + for (const item of items) { + const p = Math.round(item.price * 100); + pence += item.onSale ? p : Math.round(p * (100 - percent) / 100); + } + return pence / 100; } ``` **Why this and nothing more:** - It uses integer pence to avoid floating-point drift, and rounds once per item so the total is always a valid amount of money. - It returns a number such as `58`. Format with `.toFixed(2)` for display, which is a presentation concern, so I left it out of this function. - I left out validation of `percent`, handling of quantities and the call sites, because the report doesn't cover them. Changing them would widen the diff without addressing the bug. ## Regression test ```js const test = require('node:test'); const assert = require('node:assert'); test('10% code skips sale items and returns pounds to 2dp', () => { const items = [ { price: 40, onSale: true }, { price: 20, onSale: false }, ]; assert.strictEqual(applyDiscount(items, 10), 58); }); test('does not round to whole pounds', () => { assert.strictEqual(applyDiscount([{ price: 19.99, onSale: false }], 10), 17.99); }); test('all-sale basket is unchanged', () => { assert.strictEqual(applyDiscount([{ price: 40, onSale: true }], 10), 40); }); ``` Before the fix, the first test gets 54 and the second gets 18, so both fail. After the fix, all three pass: 58, 17.99 (1999 × 0.9 = 1799.1 pence, rounds to 1799) and 40. ## Checklist 1. Sale items never discounted: **met** 2. Non-sale items get `percent`% off: **met** 3. Two-decimal pounds, no whole-number rounding: **met** (numeric value; use `.toFixed(2)` to show `58.00`) 4. Example basket returns £58.00: **met** I haven't run the tests here, so please run them before merging.

Run on Claude Sonnet 5.5, 12 Nov 2026. Automatic check: 4 out of 5.

Mentioned for

Claude, ChatGPT, Gemini

Where it came from

Found on Web, shared by David Ch (@chhddavid): David Ch on X: How to master Fable 5.2 (Full Course).

This is our own version of the idea, written and tested by us. The original may differ.

More coding prompts

Coding Worked in our test
Generate Strict JSON Spec From Description

You get a clean, machine-readable JSON object that matches your rules on the first try. It works because the model reads the rules first, then checks its own answer against each one before replying.

Found on GitHub, shared by DominikScholz
Coding Partly worked
Match Ownership Wording to Change Size

You get a tightly scoped code change, plus a separate list of things the AI spotted but left alone. It works because you state how far the AI may go, so a sense of "ownership" does not trigger unrequested refactoring.

Found on Web, shared by explainx.ai
Coding Struggled in our test
Root-Cause Bug Fix With Honest Testing

You get a small, targeted fix with a test that proves it, plus an honest list of what was and was not checked. It works because it sets a clear goal, limits the scope, and tells the AI when to carry on and when to stop.

Found on Web, shared by Rizki Murtadha (Promptessor)