Coupons take off too much and tax is calculated wrongly

Done

/home/devdi/devswarm/evals/tasks/checkout_discount_tax/repo · 2026-11-09 16:09:14 UTC · took 37.7s

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

Usage by agent

Cost per agent
planner: $0.0010 planner planner, Cost: $0.0010 $0.0010 coder: $0.0009 coder coder, Cost: $0.0009 $0.0009 tester: $0.0018 tester tester, Cost: $0.0018 $0.0018
Tokens per agent
  • Cache read
  • Cache write
  • Input
  • Output
planner: 9,026 planner planner, Cache read: 6,052 planner, Cache write: 1,383 planner, Output: 1,583 9,026 coder: 13.2K coder coder, Cache read: 9,562 coder, Cache write: 2,600 coder, Output: 990 13.2K tester: 28.9K tester tester, Cache read: 22.5K tester, Cache write: 4,354 tester, Output: 2,071 28.9K
View as table
AgentCostCache readCache writeInputOutput
planner$0.00106,0521,38381,583
coder$0.00099,5622,6008990
tester$0.001822,4564,354122,071

Timeline

  1. planner iteration 1 Finished 3 calls · 9,026 tokens · $0.0010 · 10.2s

    Loading…

  2. coder iteration 1 Finished 3 calls · 13.2K tokens · $0.0009 · 7.6s

    Loading…

  3. tester iteration 1 Finished 5 calls · 28.9K tokens · $0.0018 · 18.8s

    Loading…

  4. verify iteration 1 Passed 0.5s
    .......                                                                  [100%]
    7 passed in 0.02s
    

Final diff

diff --git a/checkout.py b/checkout.py
index 2094fb6..b87dbc6 100644
--- a/checkout.py
+++ b/checkout.py
@@ -3,7 +3,5 @@ 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 = apply_discount(sum(prices), coupon_percent)
+    return round(subtotal + subtotal * TAX_RATE, 2)
diff --git a/test_checkout.py b/test_checkout.py
index ea5239f..314afa2 100644
--- a/test_checkout.py
+++ b/test_checkout.py
@@ -6,5 +6,29 @@ 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_full_coupon():
+    assert order_total([10, 20], 100) == 0.0
+
+
+def test_discounted_subtotal_is_27_and_tax_is_2_70():
+    total = order_total([10, 20], 10)
+    assert round(apply_discount(sum([10, 20]), 10), 2) == 27.00
+    assert round(total - 27.00, 2) == 2.70
+
+
+def test_total_rounded_to_two_decimals():
+    total = order_total([9.99], 15)
+    assert total == round(total, 2)
+    assert total == 9.34
+
+
+def test_zero_coupon_matches_no_coupon():
+    assert order_total([10, 20], 0) == order_total([10, 20]) == 33.0
+
+
 def test_apply_discount():
     assert apply_discount(100, 25) == 75