Module 04 / Lesson 04
Catch fake saves and surface real errors
Never trust a green checkmark or a loading spinner until you have verified the database write and security boundaries.
You click "Publish Update". A green toast notification pops up saying "Published successfully!" But when you open a private browser window, nothing has changed. The AI had simply written a fake timer (setTimeout) that showed a toast without actually persisting data to the database. Or worse: anyone on the internet could edit your company’s incidents because row-level security was missing.
Read the narration transcript
Find what the success toast actually proves
I click Publish. The button spins, and a green message says the update was published.
I open the handler. It waits, then returns success without a saved update. This was a useful design placeholder. It does not belong on the route customers use.
Audit a success message before you trust it
Search for a fake delay, an unfinished handler, or a catch block that returns success anyway. In this draft, the spinner stops after a timer and the app reports a save it never attempted.
Have the server check the message with Zod, then save through the existing publish path. A confirmed database write can say Published. A queued notification can say Queued.
When a test dependency hangs, give the operation a time limit and report the uncertain outcome. If it was queued, check its status before asking the operator to repeat it.
Show an honest state at each step
While the work is pending, tell the operator. Disable repeated clicks in the form if that fits the flow.
When the operation returns the confirmed identifier, show the success result. If a different system only accepted a notification into a queue, that's what its message should say.
If the write fails, keep the draft. Restore the button and give the operator a next step. Server-side duplicate handling is a separate check.
Exercise the important outcomes in the fixture
Save an authentic sample and reload to see the stored result.
Then try an invalid message and a controlled failure. Check the visible message, the saved state, and the draft. Bring those outcomes into the release-critical browser test in the next module.
The everyday problem
Click Publish incident update. The button spins and a green toast says Published. Your teammate opens the incident page and the new text is missing. During review you discover the handler mostly waits a moment and returns success so the designer could see the animation. The placeholder behavior stayed behind when the screen moved toward release.
Use the success message as a contract. In the status app it means that the server accepted a valid update from an authorized operator, saved it, and returned the update the interface can point to. If the system can only report that a request is queued, say queued. A message can be polished and still say the wrong thing.
Why the agent got it wrong
An agent focused on how a form looks can stub the backend to demonstrate a response. That can help during a prototype. It creates a problem when the mock is used by the shipping route. A swallowed error is another version of the same problem. The caller receives the same success value whether the write completes or throws.
TypeScript types describe what your code expects. Incoming form values and external data are runtime inputs. A TypeScript assertion alone does not check them. Validate the input at the server boundary, and keep expected validation errors distinct from unexpected operational errors. That gives the interface something useful to report.
The tool and technique
Trace the actual path with the narrowest useful search. Open the submit handler for the incident form, follow its call to the action, and inspect what the action returns. The presence of an artificial delay or a mock is a hint, not proof of a bug. A fixture can deliberately model a slow request without affecting real application code.
Use a validated, typed result. Zod is one option for runtime validation. For the status app the action reads incoming values, checks the message, calls the existing authorized publish operation, and reports either a saved ID or a stable error code. The caller maps that outcome to feedback. An expected failure should preserve the draft and tell the user what they can do next.
Trace success to a real result
Use Zod or the project’s validation library to check values when they arrive. A browser timeout or a demo promise can make a screen look busy without saving anything. Review every return from the server handler and map it to what the operator sees.
rg -n "setTimeout|TODO|success: true" src/app/incidents src/components
Invalid message → explain what to fix; preserve the draft.
Database unavailable → show a retryable error; preserve the draft.
Confirmed write → show Published with the saved update ID.
Delivery queued → report Queued until delivery is confirmed.
Timeout → show that confirmation is missing and preserve the draft.
# src/lib/notifications.ts (server-side delivery excerpt)
const body = JSON.stringify(approvedUpdate)
const signature = createHmac("sha256", signingKey).update(body).digest("hex")
const response = await fetch(configuredHttpsEndpoint, {
method: "POST", redirect: "error", body,
headers: { "content-type": "application/json", "x-signature": signature },
signal: AbortSignal.timeout(5000),
})
if (!response.ok) return { state: "delivery_failed" }Use a configured, approved destination and keep the key server-side. In the test fixture, make the notification endpoint return an error or time out. The incident can still be Published while notification delivery remains unconfirmed. Compare the stored update after a reload and use a stable event identifier when checking for duplicates.
On screen in the status app
Compare the illustrative snippets below. The first returns success after a delay. The second validates the form and waits for the existing authorized operation. In this example the operation returns a discriminated result, which is a small response with a clear success or failure field. The frontend has enough information to render the actual outcome instead of assuming from the passage of time.
Exercise three outcomes in a local test fixture. A valid update returns a saved ID and renders after refresh. A blank message produces a validation error by the relevant field. A controlled failed save shows a retryable error and keeps the text. Save a report that names the test fixture and observable result.
src/app/incidents/[id]/publish-action.ts
Before
await new Promise((resolve) => setTimeout(resolve, 300))
return { ok: true }After
const input = incidentUpdateSchema.safeParse(formValues)
if (!input.success) return { ok: false, code: 'invalid_message' }
const result = await publishForAuthorizedOperator(input.data)
if (!result.ok) return { ok: false, code: result.code }
return { ok: true, id: result.update.id }What to watch for
A pending control helps prevent a second click from this interface, but does not guarantee at-most-once behavior when there are retries, two tabs, or multiple users. If duplicates are consequential, verify the app’s server-side duplicate policy separately. The feature can report accepted, queued, saved, and delivered at different times. Give each state a name that matches the evidence you actually have.
A timeout is a boundary on how long the interface waits for confirmation. It can happen after another system already accepted the request. For an asynchronous notification, show Queued while you wait and use a stable request identifier to check what happened before offering a repeat. A failed write preserves the operator’s text and explains the next step.
How you know it worked
Run a successful publish and reload the status page. Then run the validation failure and the controlled write failure. Check both the response and the state on screen. The only success message should follow the confirmed save. Check that the draft survives the rejected write and that the pending control unlocks after the attempt completes.
Read the diff with these three outcomes in mind. If it marks every branch successful or caught errors vanish into logs, request a specific change. In Module 5, you’ll turn the release-critical path into a repeatable browser check so that later edits can’t quietly change what Publish means.