Test: Six known bugs in one pull request Run: claude-rules-2 Tool: Claude Code 2.1.302, model Opus 5.5 (/code-review high, safe mode) Condition: Rules written in README Time: 47 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 --- Eight angles run, near-duplicates merged. No CLAUDE.md exists in the repo, so the conventions angle found nothing. Nothing in this list was verified. ```json [ { "file": "shop/codes.py", "line": 33, "summary": "find_code builds its SQL with an f-string that inserts the user-supplied code directly, 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', returns the first code in the table and applies a discount the user never had. A code containing a single quote, such as O'NEIL, raises sqlite3.OperationalError instead of InvalidCode. Fix: use a parameter, WHERE code = ?, (code.upper(),)." }, { "file": "shop/cart.py", "line": 9, "summary": "The tags=[] default is one list shared by every call, and apply_code appends \"discounted\" to it, so the tag leaks to lines that were never discounted.", "failure_scenario": "Cart A adds 'tea' with no tags and applies SAVE10, which appends 'discounted' to the shared default list. Cart B then adds 'mug' with no tags and a code is never applied, yet its line already shows ['discounted']. apply_code also changes the list the caller passed in (tags=['gift'] becomes ['gift','discounted'] in the caller's own variable). Fix: default to None and copy, tags=list(tags or ())." }, { "file": "shop/codes.py", "line": 41, "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": "SAVE10 ends 2026-12-31. apply_code(db, 'SAVE10', '2026-12-31') raises InvalidCode('expired') on the code's last valid day. Fix: starts <= today <= ends." }, { "file": "shop/codes.py", "line": 48, "summary": "discounted_total does not stop at 0, but the README says the total never goes below 0.", "failure_scenario": "A cart with a subtotal of 300 cents and the FIVE code (fixed, 500) gives total_cents() == -200. A percent code with an amount over 100 also goes negative. Fix: return max(0, ...)." }, { "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": "load_codes(db, 'missing.csv') returns quietly with no codes loaded, and every later apply_code raises InvalidCode with no hint of why. A bad row (non-integer amount, missing column) partway through also exits silently: earlier inserts sit uncommitted in an open transaction and later rows are skipped. Fix: remove the try/except, or re-raise." }, { "file": "shop/codes.py", "line": 24, "summary": "load_codes stores row[\"code\"] exactly as written in the CSV instead of upper-casing it, but find_code always looks up code.upper().", "failure_scenario": "A CSV row 'save10,percent,10,...' is stored as 'save10'. apply_code(db, 'save10', ...) and apply_code(db, 'SAVE10', ...) both look up 'SAVE10' and raise InvalidCode. This breaks the README rule that codes are case-insensitive and stored upper-case. Fix: row['code'].strip().upper()." }, { "file": "shop/cart.py", "line": 21, "summary": "apply_code appends \"discounted\" every time it runs and tags only the lines that exist at that moment.", "failure_scenario": "Calling apply_code twice (for example, to change codes) gives tags ['discounted','discounted']. Lines added after the code is applied get the discount in total_cents() but never get the 'discounted' tag, so the tags and the totals disagree. Fix: check whether the tag is already there, or work out the tag from self.code." }, { "file": "shop/codes.py", "line": 46, "summary": "discounted_total treats any kind other than \"percent\" as fixed, so a bad or misspelled kind in the CSV is accepted and handled as a cents discount.", "failure_scenario": "A CSV row 'BIG,Percent,50,...' (capital P) is loaded, and applying BIG takes 50 cents off instead of 50%. Fix: check kind in {'percent','fixed'} when loading or applying, and reject anything else." }, { "file": "shop/codes.py", "line": 41, "summary": "Dates are compared as raw strings, which only works for zero-padded ISO YYYY-MM-DD values, and nothing checks the format.", "failure_scenario": "A CSV with ends='2026-6-30' compared against today='2026-06-15' fails because '2026-06-15' < '2026-6-30' is a string comparison, which gives the wrong answer here. Fix: parse with datetime.date.fromisoformat when loading and when calling, then compare date objects." }, { "file": "tests/test_codes.py", "line": 34, "summary": "The tests miss every behavior the README promises that the code gets wrong: inclusive end date, floor at 0, unreadable file raising an error, lowercase codes in the CSV, and tags.", "failure_scenario": "The suite passes with every bug above still present. In particular, nothing tests the expired path or the last valid day, so the off-by-one in check_dates goes unnoticed." } ] ```