An N+1 query
postgresTest time52→136msslower
- createOrder
- loadProducts
- ~select products×1 → ×12
- insert orders
Run your tests after each agent turn. See what each test did differently.
npx diffewcheckout > places an order
52 → 136 ms
The agent refactored loadProducts. All 14 tests pass. diffew flags one change in checkout > places an order: select products now runs 12 times in a row instead of once, and the test takes 84 ms more. 13 tests did not change.
src/checkout/PaymentStep.tsx+20 −16
@@ -1,34 +1,38 @@
1-import { useState } from "react"
2-import { Button } from "@/components/ui/button"
3-import { PromoCodeInput } from "./PromoCodeInput"
4-import { formatPrice } from "@/lib/format"
1+import { Button } from "@/components/ui/button"
2+import { ExpressCheckoutButton } from "./ExpressCheckoutButton"
3+import { formatMoney } from "@/lib/money"
4+import { useT } from "@/i18n"
55 import type { Order } from "@/types"
66
7-type Props = { order: Order; onSubmit: () => void; loading?: boolean }
7+interface PaymentStepProps {
8+ order: Order
9+ onPlaceOrder: () => Promise<void>
10+ isSubmitting?: boolean
11+}
812
9-export function PaymentStep({ order, onSubmit, loading }: Props) {
10- const [promo, setPromo] = useState("")
13+export function PaymentStep({ order, onPlaceOrder, isSubmitting = false }: PaymentStepProps) {
14+ const t = useT()
1115 return (
12- <section className="payment-step flex flex-col gap-4">
13- <h2 className="text-lg font-semibold">Order summary</h2>
16+ <section className={cn("payment-step", "grid gap-3")}>
17+ <h2 className="payment-step__title">{t("checkout.summary")}</h2>
1418 <ul className="payment-step__lines">
1519 {order.lines.map((line) => (
16- <li key={line.id} className="flex justify-between">
20+ <li key={line.sku} className="payment-step__line">
1721 <span>{line.title}</span>
18- <span>{formatPrice(line.amount)}</span>
22+ <span>{formatMoney(line.amount, order.currency)}</span>
1923 </li>
2024 ))}
2125 </ul>
22- <p className="flex justify-between font-semibold">
26+ <p className="payment-step__total">
2327 <span>{t("checkout.total")}</span>
24- <span>{formatPrice(order.total)}</span>
28+ <span>{formatMoney(order.total, order.currency)}</span>
2529 </p>
26- <PromoCodeInput value={promo} onChange={setPromo} />
2730 <div className="payment-step__actions">
31+ <ExpressCheckoutButton amount={order.total} onApprove={onPlaceOrder} />
28- <Button className="w-full" disabled={loading} onClick={onSubmit}>
32+ <Button size="lg" disabled={isSubmitting} onClick={onPlaceOrder}>
29- Pay now
33+ Place order
3034 </Button>
3135 </div>
3236 </section>
3337 )
3438 }
src/checkout/payment-step.css+9 −3
@@ -8,8 +8,14 @@
88 .payment-step__lines {
9- margin: 0;
9+ margin-block: var(--space-2);
1010 padding: 0;
1111 }
1212
13-.payment-step__actions { margin-top: 16px; }
13+.payment-step__actions {
14+ display: grid;
15+ gap: var(--space-2);
16+ margin-top: var(--space-4);
17+}
1418
15-.payment-step__total { font-weight: 600; }
19+.payment-step__total {
20+ font-weight: 600;
21+}
shopCartAccount
Order summary
Desk lamp€49.00
Bulb, warm white ×2€12.00
Total€61.00
Promo code~ Changedbutton “Place order”text “Pay now” → “Place order”
− Removedinput[textbox] “Promo code”
+ Addedbutton “Express checkout”
Test time171→186msslower
Test time52→136msslower
Test time136→256msslower
Test time18→352msslower
Test time136→128msfaster
shopCartAccount
Order summary
Desk lamp€49.00
Bulb, warm white ×2€12.00
Total€61.00
Promo codeshopCartAccount
Order summary
Desk lamp€49.00
Bulb, warm white ×2€12.00
Total€61.00
Promo code~ Changedbutton “Place order”text “Pay now” → “Place order”
− Removedinput[textbox] “Promo code”
+ Addedbutton “Express checkout”
What each test did differently, right on the pull request. Cloud
Moves order creation into createOrder and adds card payments.
loadProducts takes the cart items.chargeCard client for the payments API.Behaviour changed in 2 of 14 tests against main
| Test | What changed |
|---|---|
checkout › places an order | ~12 sequential select products (was 1) · +84 ms |
checkout › pays by card | +1 HTTP call POST /charge · +120 ms |
View the diff →
The same facts, as text. The agent fixes what it did not mean to change.
A Claude Code session. The user asks: add card payments to checkout. Claude updates src/orders/checkout.ts, then runs the tests under diffew and compares the runs. diffew reports that loadProducts now takes 41 ms instead of 4 and runs 12 postgres statements instead of 1, and that chargeCard is new. Claude says that it is 10 times slower because of an N+1, and loads the products in one query. It runs diffew again against main: the only server call that changed is chargeCard, added. Claude says: Verified, the only new behaviour is the card charge.
Open source
CLI and desktop app. Apache-2.0.
npx diffewHosted by you
Cloud soon
For teams and pull requests.
Everything in open source, plus