[PR #196·197·202] Customer App C9: Three Things an API-Order Test Against the Real Server Found
Until now the customer app’s record and home screens were tested against fake responses. This post covers the plan’s C9 work: a test that uses the app’s request functions as they are, with no screens, to call the real server (PR 196). The test exposed three problems. One was fixed in the same PR, the server’s race condition was fixed separately (PR 197), and the undefined stage label was fixed after I decided it (PR 202). I requested all of it.
1. Writing the Test (PR 196)
- What was done: Four tests in a new file call a real test server through the app’s request functions (
src/api/endpoints.ts) to see whether records and the home screen actually fit together in order.- When an account owner uploads a photo and creates a record, a staff member of the same module sees it in the list but marked as not editable, and gets 403 when trying to edit it.
- Saving twice with the same request number (
clientRequestId) still makes one record. - Editing yesterday’s measurement changes only the average on the home screen, and the measurement time stays the same.
- When the admin enters today as the start date along with a planned end date, the home stage is “start day”.
- Split of roles: Codex (GPT-5.6 Luna) wrote the tests, and a Claude implementation session (Claude Sonnet 5.5) did the implementation. The implementation side did not edit the test files. Claude Code on my Windows computer (Claude Opus 5.5) directed the work and did the final review.
- Attaching photos in Node: The way the app attaches files on a phone does not work in Node, so a separate test-only helper builds the form.
- Each test makes a new module. This keeps the record count, the latest measurement and the schedule stage from being shaken by other tests’ data. Sharing an existing module was dropped because other tests’ records would mix in.
2. What the Test Exposed
- The app was misreading the save response. The server answers a record save with
{ record, replay }, but the app expected a single record directly. Against the real server, the save screen would open without a record number. The screen tests’ fake response returned a single record directly, so this had been missed.- A commit with only the tests first showed 3 screen tests failing for this reason.
- The implementation session changed the app’s save function in one place to take out only
record. The screen code is unchanged. The fake responses in two screen test files were matched to the server’s shape as the job of Codex, which wrote the tests.
- Two integration test files ran at the same time and interfered. The test tool (jest) runs test files in parallel, and the existing integration tests and the new file share one server and one database. So each run failed differently.
- The moment one side added new terms, the other side’s invitation acceptance failed asking for consent.
- The two files made phone numbers the same way, so they collided.
- The first logins of a seeded admin (an admin put in beforehand) arrived at the same time and one was rejected. This was not the test but a race condition in the server (a problem where the result depends on the order when two requests arrive together).
- After blocking these one at a time on the test side, the directing Claude added “run test files one at a time” (
maxWorkers: 1) to the integration test settings to remove the root cause. The work order said not to edit that settings file, and the directing session decided to change it anyway, so it was listed in the PR as an item for me to confirm. - Two harmless test-side guards were kept (record consent when needed, and separate phone number ranges). Retrying the admin login was removed because it would hide the server bug.
- The start-day stage was undefined when there is no planned end date. Without a planned end date, the server returns “in progress” even on the start day. The design document’s stage table has a separate “start day”, and says that without a planned end date only “D+days” is shown. So the label for this case was blank. Test 4 therefore includes a planned end date, and the server was left alone while I was asked. Having the test expect “in progress” was dropped because it might go against the design.
3. Fixing the Admin First-Login Race (PR 197)
- The sequence: A seeded admin whose Google account number is still empty logs in for the first time in two tabs at almost the same moment. Both requests look up by Google account number and find nothing → request A looks up by email, fills in the number and finishes → when request B looks up by email, the number is already filled, so it treated the admin as “used by another account” and returned 403.
- The fix: If the admin found by email has the same number as the Google account now logging in, continue with that admin. If it differs, reject as before. Claude (Claude Opus 5.5) fixed this in a side session started by the C9 session.
- Alternative dropped: wrapping the email lookup in a transaction (handling several database operations as one bundle) with a row lock. It gives the same result, but the code gets longer, and a one-line comparison was enough.
- The test: A “two first logins at once” test already existed, but depending on timing it passed and did not catch this bug. The new test wraps the lookup function to fix the order: after both requests finish the number lookup, B waits until A finishes filling it in. Before the fix it failed with
[200, 403]; after the fix both are 200. - An exception to the split: Tests and implementation are normally done by different sides, but this time one session did both on the instruction of the session that started it. This was also written in the PR for me to confirm.
4. Showing Start Day Even Without a Planned End Date (PR 202)
- The decision: I decided “as the design document says”. So Claude (Claude Opus 5.5) changed the server to return the “start day” stage when the start date is today, even without a planned end date. It reuses the existing rule “if the days elapsed are 0 or less, it is the start day”.
- The app home too: Looking at the app home, Claude found that on the start day it always set progress to 0% and drew the gauge. On a start day without a planned end date, a 0% gauge would have appeared, unlike the design. With a planned end date it stays 0% as before; without one, it uses the server’s value (none) and hides the gauge.
- Alternative dropped: having the app always use the server’s progress value. It is simpler, but it would break the input of an existing app test and require changing that test, which was judged beyond this work, so the existing behavior was kept.
How It Was Checked
- PR 196: 40 tests in 4 screen test files, the app type check and lint (0 errors) passed. 11 real-server integration tests passed, four times in a row on the final commit.
codex exec review(GPT-5.6 Luna) reported “no correctness problems worth fixing”. - PR 197: All 25 admin login tests passed, and the full check passed.
- PR 202: Failing tests came first: the server schedule calculation (start date today with no planned end date → start day; next day → in progress, day 1) and the app home display (start day,
D + 00, no gauge). They passed after the fix, and the integration test gained the case “admin enters only today’s start date, with no planned end date”. The full check (admin web 310, app 384, server 594) and 12 integration tests passed. - Overlapping checks: PR 202’s first full check overlapped with another one started by the automatic verification hook, and 5 app screen tests unrelated to this change went over the 5-second limit and failed. Run alone, they all passed.
What Was Not Confirmed
- Uploading a photo from an actual phone and the home screen there cannot be checked by Node tests, so they were not seen.
- When the work folder sat under a folder whose name starts with a dot, the root integration test command could not find the test files. So the tests were run from the app folder with the same settings and only the file-matching rule changed. The cause looks like the test tool’s file-matching rule, but it was not confirmed.
The Three PRs at a Glance
| PR | What was done | Key point |
|---|---|---|
| 196 | 4 order tests calling the real server through app functions | Found and fixed the misread save response; test files run one at a time |
| 197 | Simultaneous admin first logins | Continue if the Google account number matches; a test with a fixed order |
| 202 | Start day without a planned end date | Server returns “start day”, app hides the gauge |
Who Did What
- I: requested the C9 work and decided the start-day stage “as the design document says”.
- Claude (Claude Code on my Windows computer): Claude Opus 5.5 directed C9 and did the final review, and fixed PR 197 and 202 in side sessions. A Claude Sonnet 5.5 implementation session did the implementation for PR 196.
- Codex (GPT-5.6 Luna): wrote and fixed the PR 196 tests, and took part in the final review with
codex exec review. - One mistake by Claude: The directing Claude missed that an undo command (
git revert) had failed on an option error, and the commit amend right after (--amend) changed the wrong commit. It was a local commit not yet pushed, so it went back to the earlier commit and re-applied only the needed commit.
Lessons
- Fake responses alone cannot tell whether the server and the app agree. If the fake response is built the way the app expects, both are wrong together. The test against the real server was the first to show the mismatch.
- When integration tests share one server, they come to depend on the order between test files. When adding a new integration test file, first check that the settings run files one at a time.
- “Send it twice at once” is not a race-condition test. Fix the order directly so it reliably fails before the fix.
- Running two full checks at once pushes screen tests over their time limits. When running one in the background, wait for it to finish before ending the reply.