← Saboteur

Saboteur Shop: try the bugs

These are the builds Saboteur tests: the correct app, and the same app with exactly one planted bug each. Open one, use it like a customer, and see whether you would have noticed. Saboteur's Kane CLI runs used local builds of the same code.

Test account: demo@saboteur.shop / sabotage123. Discount code: SAVE10.

cleanThe correct appOpen this build

No planted bug. Everything works as described.

M01Cart total skips the last itemOpen this build

Customer is charged less than the items in the cart: the last line item is left out of the subtotal and total

The patch
diff --git a/src/lib/cart.ts b/src/lib/cart.ts
index 7e943c2..e2d8d44 100644
--- a/src/lib/cart.ts
+++ b/src/lib/cart.ts
@@ -22,7 +22,7 @@ export function lineTotal(line: CartLine): number {
 
 export function subtotal(lines: CartLine[]): number {
   let sum = 0;
-  for (let i = 0; i < lines.length; i++) {
+  for (let i = 0; i < lines.length - 1; i++) {
     const line = lines[i];
     if (line) sum += lineTotal(line);
   }
M02"+" quantity button does nothingOpen this build

Customer cannot increase the quantity of an item with the + button

The patch
diff --git a/src/components/QtyStepper.tsx b/src/components/QtyStepper.tsx
index 4e709fc..129a6fd 100644
--- a/src/components/QtyStepper.tsx
+++ b/src/components/QtyStepper.tsx
@@ -24,7 +24,7 @@ export function QtyStepper({ value, onChange, label }: Props) {
         type="button"
         aria-label={`Increase quantity of ${label}`}
         disabled={value >= MAX_QTY}
-        onClick={() => onChange(value + 1)}
+        onClick={() => onChange(value)}
       >
         +
       </button>
M03Code SAVE10 takes 1% off instead of 10%Open this build

Customer gets a much smaller discount than SAVE10 promises

The patch
diff --git a/src/lib/discount.ts b/src/lib/discount.ts
index 4898229..ebaf7f6 100644
--- a/src/lib/discount.ts
+++ b/src/lib/discount.ts
@@ -1,5 +1,5 @@
 const CODES: Record<string, number> = {
-  SAVE10: 10,
+  SAVE10: 1,
 };
 
 export function discountPercent(code: string | null): number | null {
M04Shipping fee not added on orders under $50Open this build

Shop loses the $5.00 shipping fee on small orders; total is $5.00 too low

The patch
diff --git a/src/lib/cart.ts b/src/lib/cart.ts
index 7e943c2..44627a6 100644
--- a/src/lib/cart.ts
+++ b/src/lib/cart.ts
@@ -31,7 +31,7 @@ export function subtotal(lines: CartLine[]): number {
 
 export function shipping(afterDiscountCents: number, hasItems: boolean): number {
   if (!hasItems) return 0;
-  return afterDiscountCents < FREE_SHIPPING_FROM_CENTS ? SHIPPING_CENTS : 0;
+  return 0;
 }
 
 export function totals(lines: CartLine[], code: string | null): Totals {
M05Checkout accepts an email without a domain (a@)Open this build

Orders are placed with an email address nobody can reply to

The patch
diff --git a/src/lib/validate.ts b/src/lib/validate.ts
index 3a7b3db..cdfb863 100644
--- a/src/lib/validate.ts
+++ b/src/lib/validate.ts
@@ -1,4 +1,4 @@
-const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+const EMAIL = /^[^\s@]+@/;
 
 export function isValidEmail(value: string): boolean {
   return EMAIL.test(value.trim());
M06"Remove" deletes the first item, not the clicked oneOpen this build

Customer clicks Remove on one item and a different item disappears

The patch
diff --git a/src/state/cart.tsx b/src/state/cart.tsx
index ba15605..a2a3b91 100644
--- a/src/state/cart.tsx
+++ b/src/state/cart.tsx
@@ -41,7 +41,7 @@ export function CartProvider({ children }: { children: ReactNode }) {
       }));
     },
     remove(slug) {
-      setState((s) => ({ ...s, lines: s.lines.filter((l) => l.slug !== slug) }));
+      setState((s) => ({ ...s, lines: s.lines.slice(1) }));
     },
     applyCode(code) {
       setState((s) => ({ ...s, code }));
M07Out-of-stock product can still be added to cartOpen this build

Customer can order the Wool Beanie, which is out of stock

The patch
diff --git a/src/pages/Product.tsx b/src/pages/Product.tsx
index 8d13aac..853ca0b 100644
--- a/src/pages/Product.tsx
+++ b/src/pages/Product.tsx
@@ -30,7 +30,7 @@ export function Product() {
       <QtyStepper value={qty} onChange={setQty} label={product.name} />
       <button
         type="button"
-        disabled={!product.inStock}
+        disabled={false}
         onClick={() => {
           add(product.slug, qty);
           setAdded(true);
M08Order confirmation shows a blank order numberOpen this build

Customer has no order number to quote to support

The patch
diff --git a/src/pages/OrderConfirmed.tsx b/src/pages/OrderConfirmed.tsx
index 151585a..d7a90e2 100644
--- a/src/pages/OrderConfirmed.tsx
+++ b/src/pages/OrderConfirmed.tsx
@@ -19,7 +19,7 @@ export function OrderConfirmed() {
   return (
     <main className="confirmed">
       <h1>Thank you for your order</h1>
-      <p className="order-number">Order number: {order.id}</p>
+      <p className="order-number">Order number: {''}</p>
       <ul>
         {order.lines.map((l) => (
           <li key={l.slug}>
M09Login redirects to Home instead of AccountOpen this build

After signing in the customer lands on the home page, not My account

The patch
diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx
index 585578f..4fbfb62 100644
--- a/src/pages/Login.tsx
+++ b/src/pages/Login.tsx
@@ -12,7 +12,7 @@ export function Login() {
   function submit(e: FormEvent) {
     e.preventDefault();
     if (auth.signIn(email, password)) {
-      navigate('/account');
+      navigate('/');
     } else {
       setError('Email or password is incorrect');
     }
M10Cart empties on page refresh (state not saved)Open this build

Customer loses everything in the cart when the page reloads

The patch
diff --git a/src/state/cart.tsx b/src/state/cart.tsx
index ba15605..c69c32a 100644
--- a/src/state/cart.tsx
+++ b/src/state/cart.tsx
@@ -17,7 +17,7 @@ type CartApi = CartState & {
 const CartContext = createContext<CartApi | null>(null);
 
 export function CartProvider({ children }: { children: ReactNode }) {
-  const [state, setState] = useState<CartState>(() => load<CartState>(KEY, { lines: [], code: null }));
+  const [state, setState] = useState<CartState>(() => ({ lines: [], code: null }));
 
   useEffect(() => {
     save(KEY, state);
M11Cart badge counts distinct products instead of total quantityOpen this build

The header cart badge shows how many different products are in the cart, not how many items. Adding the same product twice still shows 1, so shoppers lose track of how many items they have.

The patch
diff --git a/src/lib/cart.ts b/src/lib/cart.ts
index 76ed184..6607943 100644
--- a/src/lib/cart.ts
+++ b/src/lib/cart.ts
@@ -42,7 +42,7 @@ export function totals(lines: CartLine[], code: string | null): Totals {
 }
 
 export function itemCount(lines: CartLine[]): number {
-  return lines.reduce((n, l) => n + l.qty, 0);
+  return lines.reduce((n, l) => n + (l.qty > 0 ? 1 : 0), 0);
 }
 
 export function clampQty(qty: number): number {
M12Free-shipping threshold checks the subtotal before the discountOpen this build

An order whose subtotal is $50 or more but drops below $50 after SAVE10 wrongly gets free shipping, so the customer is undercharged by $5.00.

The patch
diff --git a/src/lib/cart.ts b/src/lib/cart.ts
index 76ed184..fef1873 100644
--- a/src/lib/cart.ts
+++ b/src/lib/cart.ts
@@ -37,7 +37,7 @@ export function shipping(afterDiscountCents: number, hasItems: boolean): number
 export function totals(lines: CartLine[], code: string | null): Totals {
   const sub = subtotal(lines);
   const discount = discountCents(sub, code);
-  const ship = shipping(sub - discount, lines.length > 0);
+  const ship = shipping(sub, lines.length > 0);
   return { subtotal: sub, discount, shipping: ship, total: sub - discount + ship };
 }
 
M13Sign out leaves the customer signed inOpen this build

After pressing "Sign out" on the account page, the header still shows "Signed in as demo@saboteur.shop", so the customer appears to still be logged in until they refresh the page.

The patch
diff --git a/src/state/auth.tsx b/src/state/auth.tsx
index 211e79e..b68e70e 100644
--- a/src/state/auth.tsx
+++ b/src/state/auth.tsx
@@ -27,7 +27,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
       return ok;
     },
     signOut() {
-      setEmail(null);
+      setEmail(email);
       save(KEY, null);
     },
   };