Test: Six known bugs in one pull request Run: claude-rules-3 Tool: Claude Code 2.1.302, model Opus 5.5 (/code-review high, safe mode) Condition: Rules written in README Time: 54 s Planted bugs found: 6 of 6 Paths and user names are shortened; nothing else is changed. --- Our matching --- found 1. SQL built with an f-string found 2. codes stored without upper-casing found 3. end date excluded found 4. total below zero found 5. shared mutable default list found 6. exception swallowed other findings: 4 --- The review --- I found 10 problems in the `discount-codes` branch (`git diff main...HEAD`). There were no uncommitted changes, and the repo has no CLAUDE.md, so the conventions check had nothing to apply. Per the high-effort recipe, findings are deduplicated but not verified. They are ranked most severe first. The existing tests miss all of them: they only use upper-case codes with mid-range dates, one line per cart, and discounts smaller than the subtotal. ```json [ { "file": "shop/codes.py", "line": 33, "summary": "find_code builds its SQL by putting the user's code straight into an f-string, which allows SQL injection.", "failure_scenario": "Calling apply_code(db, \"x' OR '1'='1\", today) matches the first row in the table, so any made-up code gets a valid discount. A code containing a single quote, like \"o'brien\", raises sqlite3.OperationalError instead of InvalidCode. Fix: use a parameterized query (\"... WHERE code = ?\", (code.upper(),))." }, { "file": "shop/codes.py", "line": 42, "summary": "check_dates uses `today < ends`, so the end date doesn't count, but the README says both start and end days are included.", "failure_scenario": "A code with ends=2026-12-31 applied on today='2026-12-31' raises InvalidCode('expired') on its last valid day. A code with starts == ends is never valid." }, { "file": "shop/codes.py", "line": 27, "summary": "load_codes catches every exception with `except Exception: pass`, but the README says a file it cannot read is an error.", "failure_scenario": "A wrong csv_path (FileNotFoundError), a bad amount (ValueError from int()) or a missing column (KeyError) is ignored without any message. Zero or only some codes get loaded, and an error partway through skips db.commit(), leaving the rows inserted so far in an uncommitted transaction." }, { "file": "shop/codes.py", "line": 24, "summary": "load_codes saves row[\"code\"] exactly as written instead of upper-casing it, but find_code always looks up code.upper().", "failure_scenario": "If the CSV has the code 'save10', it is stored lower-case. apply_code(db, 'save10', ...) and apply_code(db, 'SAVE10', ...) both look up 'SAVE10' and raise InvalidCode, so the code can never be used. Mixed-case duplicates are also stored as separate rows." }, { "file": "shop/codes.py", "line": 48, "summary": "discounted_total doesn't stop the total at 0, but the README says it never goes below 0.", "failure_scenario": "A fixed 500-cent code on a 300-cent cart gives total_cents() == -200. A percent code with an amount over 100 also gives a negative total. Fix: max(0, ...)." }, { "file": "shop/cart.py", "line": 9, "summary": "Cart.add uses a mutable default `tags=[]`, so every line added without tags shares one list across all carts.", "failure_scenario": "c1.add('tea', 100) and c2.add('mug', 200) share the same tags list. Applying a code to c1 tags c2's line 'discounted' too, even though c2 has no code. The shared list keeps growing for the life of the process. Fix: use tags=None and build a new list each call." }, { "file": "shop/cart.py", "line": 22, "summary": "apply_code appends 'discounted' straight into lists that come from the caller or are shared, so applying again or sharing a list adds duplicate tags.", "failure_scenario": "Two lines in one cart that use the default tags (or the same tags list from the caller) both point at one list, so a single apply_code adds 'discounted' twice. Applying a code twice adds it again each time. The caller's own list (e.g. tags=GIFT_TAGS) is also changed. Fix: copy tags in add (list(tags)) and add the tag only if it's missing." }, { "file": "shop/cart.py", "line": 21, "summary": "Lines added after apply_code never get the 'discounted' tag, although the discount still covers them.", "failure_scenario": "Calling apply_code(...) and then add('mug', 1200) leaves the mug untagged, yet total_cents() still discounts the whole subtotal including the mug. The tags no longer match what was actually discounted." }, { "file": "shop/codes.py", "line": 41, "summary": "check_dates compares dates as strings, which only works if both sides are zero-padded ISO strings.", "failure_scenario": "Passing today=datetime.date(2026, 6, 1) raises TypeError (str <= date). A CSV date like '2026-1-5' compares wrong as text, e.g. '2026-1-5' > '2026-06-01', so the code is wrongly treated as expired or not yet started." }, { "file": "shop/codes.py", "line": 46, "summary": "discounted_total treats any kind other than 'percent' as fixed, so a typo or wrong-case kind in the CSV is silently charged as a fixed discount.", "failure_scenario": "A CSV row with kind='Percent' and amount=10 takes 10 cents off instead of 10%. Any unknown kind is also treated as fixed with no error. Fix: check kind in load_codes and raise for unknown values." } ] ```