[PR #63] Built the Admin Code Issue, Revoke, and Delivery Confirmation Path
- What changed: Built the server path (the entry point that receives requests) where a head-office staff member, from the admin web, issues a code for a customer, revokes it, and marks it as delivered. Also added an invite waiting list and a per-customer code list.
- Decision: For a customer who is suspended or withdrawn, an invite is refused, following rule 45 in the instruction. The owner chose how to fix the failing test.
- Still unknown: Whether the response for marking an expired code as “delivered” is the intended order still needs the user to confirm.
This post records server task 13, shipped as one PR. The tests were written first, and the code was then changed until they passed.
What and why
A customer uses this code to accept an invite, recover an account, or add a login method. So a head-office staff member needs to create that code in the admin web, cancel it if needed, and mark it as delivered to the customer. This PR built the server side of that. Following test-driven development (writing a failing test first, then changing the code until it passes), 46 tests were written first. A Claude Haiku 5.5 session drafted those tests, and a Claude Sonnet 5.5 session did the implementation.
- Issuing: The code itself is returned in the response only once (201, meaning “created”). The server stores only a hash (a fingerprint that makes the original text unreadable).
- Revoking and marking as delivered: These return 204 (success with no body). Sending the same request twice still adds only one line to the audit log (
audit_logs, a history of who did what and when). - Issuing and logging: Both happen in one transaction (a unit that succeeds or fails as a whole). If the log entry fails, the code is not created either.
- Lists: Added an invite waiting list (only customers still waiting, filtered by status and search text, 20 per page) and a per-customer code list. Neither list shows the raw code or its hash.
Options chosen and rejected
- Inviting a suspended or withdrawn customer: Chose to refuse with 409
already_active(a conflict response meaning the account is already active). This follows rule 45 of the instruction. Another line in the test list saidnot_active, so the two lines disagreed. The test was changed to match the instruction. - Finding the most recent invite code: Sorted by expiry time (
expires_at). There was no creation-time column (created_at), and this task had a rule against database schema changes (migrations). Adding a column was rejected. - When a test failed: The admin login session ends after 12 hours. Extending the session was rejected, because it would break the security rule and the test from task 11. Instead, the owner chose to add one line to the test so the admin logs in again after the clock moves forward 8 days.
How it was checked
- The first implementation commit (
11fc87a) failed in CI (the automatic test run). The cause: the test moved the clock forward 8 days, which also expired the admin session. - A one-line test fix (
981a071) was pushed. Claude reviewed the diff (the changed content) to confirm no other file changed. CI passed on that commit. - Claude did not run this code directly. CI did.
- A read-only review session went through the code again. It reported that the code and hashes appear only in the issue response, that search values are passed to the query safely, and that simultaneous issues for the same customer are handled one at a time. This is the review session’s report, not a full re-check by Claude.
Lessons
- When the same rule is written two different ways on two lines of an instruction, writing the test is what exposed it. Write each rule in one place only.
- A test that moves the clock a long way forward can also trigger other conditions, such as login session expiry. When a test changes time, check what else that change affects.