Foreman

Case study · Fix a bug

total() in cart.py multiplies price by qty

FIX: total() in cart.py ignores the quantity; an item with qty 3 should count three times

Fix a bug

fm code 'FIX: total() in cart.py ignores the quantity; an item with qty 3 should count three times' --worker claude

fm code tui at the end of this run: total() in cart.py multiplies price by qty

Plan FIX S · total() in cart.py multiplies price by qty

Steps

  1. Add a failing test to test_cart.py: total([{'price': 2, 'qty': 3}]) == 6
  2. Change cart.py line 3 to sum(i['price'] * i['qty'] for i in items)
  3. Run python3 -m unittest test_cart

Checks

  • PASS total() counts an item with qty 3 three timespython3 -c "from cart import total; assert total([{'price': 2, 'qty': 3}]) == 6" (failed before the work)
  • PASS the test suite passes, including a new qty > 1 testpython3 -m unittest test_cart -q && grep -q "'qty': 3" test_cart.py (failed before the work)

Changed

  • test_cart.py +3
  • cart.py +1 −1

Closed T-0001 closed; committed 1187356 (2 files). Undo: git revert --no-edit 1187356 (tokens: 66311 in, 503 out)

3 worker turns · 67k tokens · 57s · replay it: fm code tui --events demo/examples/fix.jsonl · the case study

The run, event by event

  1. 10s before fails: python3 -c "from cart import total; assert total([{'price': 2, 'qty': 3}]) == 6"
  2. 10s before fails: python3 -m unittest test_cart -q && grep -q "'qty': 3" test_cart.py
  3. 10s step step 1/3: Add a failing test to test_cart.py: total([{'price': 2, 'qty': 3}]) == 6
  4. 23s changed test_cart.py
  5. 23s step step 2/3: Change cart.py line 3 to sum(i['price'] * i['qty'] for i in items)
  6. 42s changed cart.py, test_cart.py
  7. 42s step step 3/3: Run python3 -m unittest test_cart
  8. 55s changed cart.py, test_cart.py
  9. 56s check passes: python3 -c "from cart import total; assert total([{'price': 2, 'qty': 3}]) == 6"
  10. 56s check passes: python3 -m unittest test_cart -q && grep -q "'qty': 3" test_cart.py
  11. 57s closed T-0001 closed; committed 1187356 (2 files). Undo: git revert --no-edit 1187356 (tokens: 66311 in, 503 out)

Back to fm code