Test: Six known bugs in one pull request Run: claude-rules-1 Tool: Claude Code 2.1.302, model Opus 5.5 (/code-review high, safe mode) Condition: Rules written in README Time: 31 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 --- ```json [ { "file": "shop/codes.py", "line": 34, "summary": "find_code builds its SQL with an f-string around user-supplied input, so the code lookup is open to SQL injection.", "failure_scenario": "apply_code(db, \"X' OR '1'='1\", today) runs `WHERE code = 'X' OR '1'='1'`. That returns the first row in the table, so any made-up string applies a real discount. A code containing a single quote, like \"O'NEIL\", raises sqlite3.OperationalError instead of InvalidCode. Fix: use `WHERE code = ?` with `(code.upper(),)`." }, { "file": "shop/codes.py", "line": 42, "summary": "check_dates uses `today < ends`, so the end date is excluded, 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. It should be `starts <= today <= ends`." }, { "file": "shop/codes.py", "line": 48, "summary": "discounted_total never clamps at 0, although the README says the total never goes below 0.", "failure_scenario": "Cart with a 300-cent item plus the FIVE code (fixed 500) gives total_cents() == -200. A percent code with amount > 100, such as 150, also goes negative." }, { "file": "shop/codes.py", "line": 24, "summary": "load_codes stores the code exactly as written in the CSV, but find_code looks it up upper-cased, so any code with lowercase letters in the CSV can never be found.", "failure_scenario": "A CSV row 'save10,percent,10,...' is stored as 'save10'. apply_code(db, 'save10', ...) and apply_code(db, 'SAVE10', ...) both query 'SAVE10' and raise InvalidCode. The README says codes are stored upper-case, so it should insert row[\"code\"].upper()." }, { "file": "shop/codes.py", "line": 27, "summary": "load_codes catches every exception and passes, but the README says a file it cannot read is an error.", "failure_scenario": "A missing path, a permission error, a malformed amount ('ten'), or a missing column all return silently. Rows inserted before the failing row stay in the connection uncommitted, so you get a partial, silent load, and later every apply_code fails with a misleading InvalidCode." }, { "file": "shop/cart.py", "line": 8, "summary": "add() uses a mutable default `tags=[]`, so every line added without tags shares one list, and apply_code appends to it.", "failure_scenario": "c1.add('tea', 100) followed by c1.apply_code(...) appends 'discounted' to the shared default list. A new Cart c2.add('mug', 200) in the same process then starts out tagged ['discounted'], and the tag carries across carts. Fix: use `tags=None` and `list(tags or [])`." }, { "file": "shop/cart.py", "line": 22, "summary": "apply_code changes the caller's tags list in place and appends again on every call, so tags leak and repeat.", "failure_scenario": "t = ['gift']; c.add('a', 100, tags=t); c.add('b', 200, tags=t) followed by apply_code gives t == ['gift', 'discounted', 'discounted']. Both lines show the duplicated tag, and calling apply_code twice adds more duplicates." }, { "file": "shop/cart.py", "line": 21, "summary": "The 'discounted' tag is added only to lines present when apply_code is called, so lines added afterward get the discount in total_cents but not the tag.", "failure_scenario": "c.apply_code(db, 'SAVE10', d) followed by c.add('mug', 1200): the mug is discounted through the subtotal but has no 'discounted' tag. This breaks the README rule that applying a code tags every line. It would be simpler to work out the tag from self.code when it is needed than to store it on each line." }, { "file": "shop/codes.py", "line": 42, "summary": "Dates are compared as raw strings, so the check only works if `today` is an ISO string with the same zero-padding as the CSV values.", "failure_scenario": "Passing today=datetime.date.today() raises TypeError (comparing a str with a date). A CSV with non-padded dates like '2026-1-5' compares wrongly as text, for example '2026-10-01' < '2026-1-5'." }, { "file": "tests/test_codes.py", "line": 22, "summary": "The new tests miss every edge case the README promises, so the bugs above go uncaught.", "failure_scenario": "Nothing tests a code on its end date, a fixed discount larger than the subtotal, a lowercase code in the CSV, an unreadable CSV path, or tags. The suite passes even though each of those behaviors is broken." } ] ```