[PR #68] Locked-Code Rejection and Auto-Revoking Old Codes
- What changed: Five small server fixes went into one PR: rejecting a locked code, showing locked invite codes, cutting search text by characters, revoking old codes when a new one is issued, and unifying the result value in the audit log.
- Decision: Only the fixes in the “mine” scope the owner set were included. Work outside that scope stayed out of this PR.
- Still unknown: Two search-cut tests cannot yet check a real 100-character search, because of a name length limit.
What we did and why
Claude put five fixes into the server.
- Locked codes: Marking a code that was wrong five times as “delivered” is rejected with 409 (
code_locked). - Locked invite codes: They show as
expiredin the customer list, the invite list, and the customer detail. Thelockedstatus in the admin code list stays as it was. - Search text: Cut by characters, up to 100. This keeps emoji from being split in half.
- Reissuing: Issuing a new code revokes only the earlier codes that are still active. Expired or locked codes are left alone. The audit record lists the IDs of the revoked codes.
- Audit result value: Six places that wrote
successin the operations record now writeok.
Approaches chosen and rejected
- Revoking old codes: Selecting the codes first and then updating them takes two statements. We chose one update statement that selects and returns the IDs. The customer row is already locked, so simultaneous reissues line up one after another.
- Locked invite codes: One function decides the status, and all three lists use it. If each list decided on its own, they could drift apart.
- Splitting commits: Several fixes touched the same files, so commits were grouped by change set instead of one per fix.
How we checked
- Started Docker and ran the full check (
npm run verify). - At first, 2 of 328 tests failed. The test created customers with names longer than the database’s 30-character limit, so it broke before the code change ran.
- Following the instruction, we changed those two tests: names were shortened to fit 30 characters, and the tests now expect “no matching customer.” After that, all 328 passed.
- However, this made the tests weaker. A 100-character search cannot match a customer with such a name, so the cut is checked only by confirming that a 101-character and a 100-character search give the same result.
Lessons
- Tests should use the real limits of the data (length, format). A test written without knowing the limit breaks before the code is even tested.
- When the same status rule lives in several lists, fixing one place leaves the others wrong. Keep the rule in one function and let every list call it.
- When a test is changed to pass, write down what was changed and how much weaker the test became, so the trade-off can be judged later.