Test: Six known bugs in one pull request Run: codex-rules-3 Tool: Codex CLI 0.145.0, model gpt-5.6-sol (codex review --base main, reasoning xhigh) Condition: Rules written in README Time: 61 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: 0 --- The review --- The implementation violates several documented behaviors and exposes an injectable database lookup. It can silently fail loading codes, reject valid boundary or lowercase codes, leak tags across carts, and produce negative totals. Full review comments: - [P1] Parameterize the discount-code lookup — shop/codes.py:33-33 When `code` is user-controlled, input such as `NOPE' OR 1=1 --` alters the query and returns an existing discount, allowing an unknown code to be accepted; a plain apostrophe can also raise `sqlite3.OperationalError` instead of `InvalidCode`. Bind the uppercased code as a query parameter. - [P1] Clamp discounted totals at zero — shop/codes.py:48-48 When a fixed discount exceeds the subtotal, this returns a negative total—for example, a 500-cent code on a 100-cent cart returns -400. This violates the documented guarantee that totals never go below zero and can propagate an invalid amount into checkout. - [P2] Propagate code-loading failures — shop/codes.py:27-28 When the CSV path is unreadable or its contents are malformed, this blanket handler returns normally, leaving callers unable to detect an empty or partially loaded database. This directly contradicts the documented behavior that an unreadable file is an error; the failure should be propagated, with rollback where appropriate. - [P2] Normalize loaded codes to uppercase — shop/codes.py:24-24 When a CSV contains a lowercase code such as `save10`, it is stored verbatim while `find_code` always searches for `SAVE10`, so neither casing can redeem the code. Normalize the value on insertion to satisfy the case-insensitive, uppercase-storage contract. - [P2] Include the end date in code validity — shop/codes.py:41-41 When `today` equals `ends`, this condition raises `InvalidCode`, although the documented validity interval includes both boundary dates. The upper comparison must be inclusive. - [P2] Allocate a fresh tag list for each line — shop/cart.py:9-9 When multiple `add` calls omit `tags`, every line and cart shares this default list. Applying a code can therefore tag unrelated carts and, for multiple default-tagged lines in one cart, append duplicate `discounted` entries to every line; create a new list for each call instead.