Test: Six known bugs in one pull request Run: claude-norules-3 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 --- ```json [ { "file": "shop/codes.py", "line": 33, "summary": "find_code builds its SQL by putting the user-supplied code straight into an f-string, which allows SQL injection.", "failure_scenario": "Calling apply_code(db, \"x' OR '1'='1\", today) makes the query `WHERE code = 'X' OR '1'='1'`, which returns the first row in the table. A user with no valid code gets a discount, and a crafted UNION can return any kind/amount the attacker wants. A code containing a quote, such as \"O'NEIL\", raises sqlite3.OperationalError. The fix is to use a `?` parameter." }, { "file": "shop/cart.py", "line": 9, "summary": "The `tags=[]` default is a single list shared by every item added without tags, across all carts, and apply_code adds \"discounted\" to it.", "failure_scenario": "Cart A gets add('tea', 100) and then apply_code. Cart B, which has no code, then does add('mug', 200). The mug's tags already contain 'discounted'. Each further apply_code adds another 'discounted' to the shared list, so the list grows for the life of the process." }, { "file": "shop/codes.py", "line": 27, "summary": "load_codes catches every exception and discards it, so a missing file, a missing column, or a non-integer amount fails silently.", "failure_scenario": "If the CSV path is wrong or one row has amount='10%', nothing is reported. Rows inserted before the error are never committed, though the same connection can still see them. Every code, or every code after the bad row, then fails with InvalidCode and nothing says the load failed." }, { "file": "shop/codes.py", "line": 34, "summary": "Lookup uppercases the code the user enters, but load_codes stores CSV codes exactly as written, so any code with a lowercase letter in the CSV can never be matched.", "failure_scenario": "A CSV row with code 'Summer25' is stored as 'Summer25'. apply_code('Summer25') searches for 'SUMMER25', finds nothing, and raises InvalidCode even though the user typed the code exactly." }, { "file": "shop/codes.py", "line": 48, "summary": "The discount is not capped, so a fixed discount larger than the subtotal, or a percent above 100, gives a negative total.", "failure_scenario": "A cart holds one 300-cent item and the FIVE code (500 fixed) is applied. total_cents() returns -200, a negative charge or refund." }, { "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 casing silently produces a different discount.", "failure_scenario": "A CSV row has kind 'Percent' or 'percentage' with amount 10. The code is treated as a fixed 10-cent discount instead of 10%, and no error is raised." }, { "file": "shop/codes.py", "line": 41, "summary": "check_dates treats the end date as exclusive and compares raw strings, so a code is rejected on its listed last day, and date objects fail.", "failure_scenario": "SAVE10 has ends=2026-12-31, and apply_code on '2026-12-31' raises InvalidCode('expired'). If today is passed as datetime.date, comparing str < date raises TypeError. A non-zero-padded CSV date such as '2026-6-1' sorts incorrectly as a string." }, { "file": "shop/cart.py", "line": 22, "summary": "apply_code changes the tags lists the caller passed in, and the tagging is fixed at apply time, so items added later are not marked 'discounted' even though the discount applies to them.", "failure_scenario": "A caller passes the same tags list for several SKUs or reuses it across carts, and that list now contains 'discounted'. Items added after apply_code are included in the discounted total_cents() but have no 'discounted' tag." }, { "file": "shop/cart.py", "line": 21, "summary": "Storing a 'discounted' flag in each item's tags duplicates information that self.code already holds, which is the root cause of the shared-list and stale-tag bugs above.", "failure_scenario": "The tags can disagree with self.code: they are missing on items added after the code was applied and remain if the code is later replaced. The simpler design is to derive the discounted status from `self.code is not None` and not mutate tags." }, { "file": "tests/test_codes.py", "line": 35, "summary": "The new tests cover none of the risky paths: expired or not-yet-valid dates, the end-date boundary, a discount larger than the subtotal, a failed CSV load, codes containing quotes, or tag sharing between carts.", "failure_scenario": "Each defect listed above, including the injection, negative totals and silent load failures, passes the current suite, so a regression in any of them would not be caught." } ] ```