Test: Six known bugs in one pull request Run: claude-norules-1 Tool: Claude Code 2.1.302, model Opus 5.5 (/code-review high, safe mode) Condition: Rules not written Time: 39 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 --- No `CLAUDE.md` exists in the repo, so the conventions angle produced nothing. The diff came from `git diff main...HEAD` and the working tree was clean. I found 10 issues, listed most severe first. ```json [ { "file": "shop/codes.py", "line": 34, "summary": "find_code builds its SQL with an f-string around the user-supplied code, so the lookup can be injected.", "failure_scenario": "apply_code(db, \"x' OR '1'='1\", today) runs `WHERE code = 'X' OR '1'='1'` and returns the first row in the table, so any made-up string gets a valid discount. A code containing a single quote, like \"o'neil\", raises sqlite3.OperationalError instead of InvalidCode. Use a parameterized query: `WHERE code = ?`, (code.upper(),)." }, { "file": "shop/cart.py", "line": 9, "summary": "The mutable default `tags=[]` is one list shared by every line in every cart, and apply_code appends \"discounted\" to it.", "failure_scenario": "Cart A adds 'tea' with default tags and applies a code. Cart B then adds 'mug' with no code. B's line already has tags == ['discounted'] because both carts use the same list. A cart with N lines also appends N copies to that one list. Use `tags=None` and copy into a new list per line." }, { "file": "shop/codes.py", "line": 27, "summary": "load_codes catches every exception with a bare `except Exception: pass`, so a missing file or bad CSV fails silently and can leave a partial, uncommitted load.", "failure_scenario": "The CSV path is wrong, or one row has amount='ten' or is missing the 'ends' column. load_codes returns normally with zero codes loaded, or with the rows before the bad one inserted but not committed (still visible on this connection). Every customer code then fails with InvalidCode and nothing reports why." }, { "file": "shop/codes.py", "line": 48, "summary": "discounted_total does not clamp at zero, 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 shop would owe the customer money. A percent code with amount 150 gives the same result. Return max(0, ...)." }, { "file": "shop/codes.py", "line": 34, "summary": "find_code upper-cases the input but load_codes stores codes exactly as written in the CSV, so codes with lowercase letters can never be found.", "failure_scenario": "The CSV has 'summer25'. A user types 'summer25', the query looks for 'SUMMER25', and InvalidCode is raised. Normalize to upper case in load_codes too, or compare with COLLATE NOCASE." }, { "file": "shop/codes.py", "line": 42, "summary": "check_dates compares the dates as plain strings, with `ends` exclusive, so a code is rejected on its last day and non-string dates break the check.", "failure_scenario": "A code with ends=2026-12-31 is rejected as 'expired' on 2026-12-31. Passing today=datetime.date(...) raises TypeError (str vs date) instead of InvalidCode. A CSV date like '2026-1-5' sorts lexically wrong and gives wrong valid/expired results." }, { "file": "shop/codes.py", "line": 48, "summary": "discounted_total treats any kind other than 'percent' as a fixed amount, so a typo in the CSV kind applies the wrong discount instead of being rejected.", "failure_scenario": "A CSV row with kind 'Percent' or 'pct' and amount 10 is applied as a fixed 10-cent discount, not 10%. Validate kind against {'percent','fixed'} when loading." }, { "file": "shop/cart.py", "line": 20, "summary": "apply_code tags only the lines present at that moment and re-appends the tag each time it runs, so the 'discounted' tags drift from the actual discount state.", "failure_scenario": "Apply a code, then add another item: the new line has no 'discounted' tag although total_cents discounts it. Apply a code twice: each line gets ['discounted', 'discounted']. Work the tag out from self.code when needed instead of mutating the stored lists." }, { "file": "shop/cart.py", "line": 11, "summary": "add stores the caller's tags list by reference, and apply_code later mutates it in place.", "failure_scenario": "A caller passes one list, e.g. `t = ['gift']`, for several adds or reuses it elsewhere. After apply_code, the caller's list has 'discounted' appended once per line that shares it. Store list(tags)." }, { "file": "tests/test_codes.py", "line": 34, "summary": "The new tests do not cover the dangerous paths: expired codes, fixed discount above subtotal, a quote in the code string, a failed or malformed CSV load, and tag sharing across carts.", "failure_scenario": "Every bug above passes the current test suite. For example, a regression where load_codes silently loads nothing would only show up as test_percent failing with an InvalidCode that looks unrelated." } ] ```