Test: Six known bugs in one pull request Run: claude-norules-2 Tool: Claude Code 2.1.302, model Opus 5.5 (/code-review high, safe mode) Condition: Rules not written Time: 41 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 --- The diff adds discount codes and touches 4 files (`shop/cart.py`, `shop/codes.py`, `tests/test_codes.py`, `README.md`). I found 10 candidate issues, most severe first. Following the high-effort recipe, none of them went through a separate verification pass. I found no CLAUDE.md in the repo. I couldn't check `~/.claude/CLAUDE.md` because reading it needed a permission that wasn't granted, so the conventions angle produced nothing. ```json [ { "file": "shop/codes.py", "line": 34, "summary": "find_code builds the SQL query by putting the user-supplied code into an f-string, so the lookup is open to SQL injection.", "failure_scenario": "apply_code(db, \"x' OR '1'='1\", today) runs `WHERE code = 'X' OR '1'='1'`, which returns the first row in the table. Any user who can type a code can apply any discount without knowing a valid code. A code with an apostrophe (e.g. \"BOB'S\") raises sqlite3.OperationalError instead of InvalidCode." }, { "file": "shop/cart.py", "line": 9, "summary": "Cart.add uses a mutable default `tags=[]`, so every line added without tags shares one list, and apply_code appends \"discounted\" to that shared list.", "failure_scenario": "Cart A: add('tea', 100) and apply a code. Cart B (separate, no code): add('mug', 200). B's line already carries tags ['discounted'], because the shared default list was changed by A. Each further apply_code anywhere adds another 'discounted' entry for every cart." }, { "file": "shop/codes.py", "line": 27, "summary": "load_codes uses `except Exception: pass`, so a missing file, a missing column, a non-integer amount or a DB error is silently ignored.", "failure_scenario": "The CSV path is wrong, or one row has amount='10%'. load_codes returns normally with no codes, or only the rows before the bad one, and those are left uncommitted. Every later apply_code raises InvalidCode, with nothing showing that loading failed." }, { "file": "shop/codes.py", "line": 48, "summary": "discounted_total has no lower bound, so a fixed discount larger than the subtotal (or a percent over 100) gives a negative total.", "failure_scenario": "Cart with one 300-cent item plus code FIVE (fixed 500): total_cents() returns -200, so the customer would be owed money. A percent code with amount 150 on 1000 gives -500." }, { "file": "shop/codes.py", "line": 24, "summary": "load_codes stores codes exactly as written in the CSV, but find_code always looks up `code.upper()`, so any code that isn't uppercase in the CSV can never be found.", "failure_scenario": "CSV row 'save10,percent,10,...' gets stored as 'save10'. apply_code(db, 'save10', ...) queries 'SAVE10', finds nothing, and raises InvalidCode, even though the user typed exactly what is in the file." }, { "file": "shop/codes.py", "line": 42, "summary": "check_dates treats the end date as exclusive (`today < ends`), so a code is already rejected on its stated last day.", "failure_scenario": "Code with ends=2026-12-31 and apply_code(..., today='2026-12-31') raises InvalidCode('expired'), though the CSV says the code runs through Dec 31. Also, if today is a datetime.date rather than a string, comparing str with date raises TypeError." }, { "file": "shop/codes.py", "line": 46, "summary": "Any kind other than exactly 'percent' is treated as a fixed amount in cents, so a typo or different capitalisation silently changes what the discount means.", "failure_scenario": "CSV row 'HALF,Percent,50,...' or 'HALF,percentage,50,...' gets applied as a 50-cent discount instead of 50%. Nothing checks kind at load time or at apply time." }, { "file": "shop/cart.py", "line": 12, "summary": "Cart.items entries go from 3-tuples to 4-tuples, which breaks any outside code that unpacks `sku, price, qty` from cart.items.", "failure_scenario": "Existing code doing `for sku, price, qty in cart.items:` now raises ValueError (too many values to unpack). The README describes the cart API but does not mention this change." }, { "file": "shop/cart.py", "line": 21, "summary": "apply_code tags only the lines already in the cart and never removes the tags, so the 'discounted' tag drifts from the real discount state.", "failure_scenario": "add('tea'), apply_code, then add('mug', tags=[]): the mug is discounted in total_cents() but has no 'discounted' tag. Calling apply_code twice tags tea as ['discounted', 'discounted']. Passing the same list object as tags for several lines (or relying on the default) multiplies the appends." }, { "file": "shop/cart.py", "line": 18, "summary": "apply_code doesn't validate its input, so a None or non-string code crashes with AttributeError instead of raising InvalidCode.", "failure_scenario": "A form submits with no code field and apply_code(db, None, today) is called. `code.upper()` in find_code raises AttributeError: 'NoneType' object has no attribute 'upper', which callers catching InvalidCode won't handle." } ] ```