Coupons take off too much and tax is calculated wrongly

Done

/home/devdi/devswarm/evals/tasks/checkout_discount_tax/repo · 2026-11-09 16:08:36 UTC · took 36.9s

  1. Plan (done)
  2. Code (done)
  3. Test (done)
  4. Review (done)
  5. Finish (done)
Cost
$0.0046
Tests
Passed
Iterations
1
Re-plans
0
LLM calls
12
Prompt read from cache
76%

Usage by agent

Cost per agent
planner: $0.0011 planner planner, Cost: $0.0011 $0.0011 coder: $0.0013 coder coder, Cost: $0.0013 $0.0013 tester: $0.0012 tester tester, Cost: $0.0012 $0.0012 reviewer: $0.0009 reviewer reviewer, Cost: $0.0009 $0.0009
Tokens per agent
  • Cache read
  • Cache write
  • Input
  • Output
planner: 9,268 planner planner, Cache read: 6,056 planner, Cache write: 1,385 planner, Output: 1,819 9,268 coder: 18.4K coder coder, Cache read: 13.8K coder, Cache write: 3,002 coder, Output: 1,551 18.4K tester: 16.1K tester tester, Cache read: 11.3K tester, Cache write: 3,563 tester, Output: 1,269 16.1K reviewer: 9,910 reviewer reviewer, Cache read: 5,498 reviewer, Cache write: 3,519 reviewer, Output: 887 9,910
View as table
AgentCostCache readCache writeInputOutput
planner$0.00116,0561,38581,819
coder$0.001313,8213,002101,551
tester$0.001211,2533,56381,269
reviewer$0.00095,4983,5196887

Timeline

  1. planner iteration 1 Finished 3 calls · 9,268 tokens · $0.0011 · 11.0s

    Loading…

  2. coder iteration 1 Finished 4 calls · 18.4K tokens · $0.0013 · 9.5s

    Loading…

  3. tester iteration 1 Finished 3 calls · 16.1K tokens · $0.0012 · 9.9s

    Loading…

  4. verify iteration 1 Passed 0.5s
    ......                                                                   [100%]
    6 passed in 0.01s
    
  5. reviewer iteration 1 Finished 2 calls · 9,910 tokens · $0.0009 · 5.4s

    Loading…

Final diff

diff --git a/checkout.py b/checkout.py
index 2094fb6..0dcbbbd 100644
--- a/checkout.py
+++ b/checkout.py
@@ -3,7 +3,6 @@ from pricing import apply_discount
 
 
 def order_total(prices: list[float], coupon_percent: float = 0) -> float:
-    undiscounted = sum(prices)
-    subtotal = sum(apply_discount(price, coupon_percent) for price in prices)
-    subtotal = apply_discount(subtotal, coupon_percent)
-    return round(subtotal + undiscounted * TAX_RATE, 2)
+    subtotal = round(apply_discount(sum(prices), coupon_percent), 2)
+    tax = subtotal * TAX_RATE
+    return round(subtotal + tax, 2)
diff --git a/test_checkout.py b/test_checkout.py
index ea5239f..d617191 100644
--- a/test_checkout.py
+++ b/test_checkout.py
@@ -6,5 +6,23 @@ def test_no_coupon():
     assert order_total([10, 20]) == 33.0
 
 
+def test_coupon_applied_once_and_tax_on_discounted_subtotal():
+    assert order_total([10, 20], 10) == 29.70
+
+
+def test_coupon_not_applied_twice_and_tax_on_discounted_subtotal():
+    subtotal = apply_discount(30, 10)
+    assert round(subtotal, 2) == 27.00
+    assert round(order_total([10, 20], 10) - subtotal, 2) == 2.70
+
+
+def test_zero_coupon_equals_no_coupon():
+    assert order_total([10, 20], 0) == order_total([10, 20])
+
+
+def test_empty_order():
+    assert order_total([]) == 0.0
+
+
 def test_apply_discount():
     assert apply_discount(100, 25) == 75