fix(approvals): stop a non-object context rendering one cell per character - #63
Merged
ralyodio merged 1 commit intoJul 30, 2026
Conversation
…acter The approve page builds its context grid with Object.entries(JSON.parse(a.context)). POST /api/approvals stores context as JSON.stringify(req.body.context) verbatim, so it is whatever the caller sent, not necessarily a label/value map. A string context indexes per character: context:"deploy failed on prod" rendered 21 grid cells labelled 0 to 20, one letter each. A number or boolean context yields no entries at all, so the value silently vanished from the page. Only a real object is a map. Anything else now renders as a single "context" cell. Objects and arrays are untouched. Regression test: apps/pwa/test/approvals-context.test.mjs boots the real router against a throwaway libsql database and asserts the grid for object, string, number, boolean, array and absent contexts. Two of the five fail without the fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
GET /approve/:idbuilds the context grid with:POST /api/approvalsstores the context asJSON.stringify(req.body.context)verbatim, so what comes back out is whatever the caller sent. It is not necessarily a label/value map, andObject.entries()on a non-object is meaningless.Reproduced against the real router on
main(dfcb8c1), a throwaway libsql db, no fault injection:contextposted{"env":"prod","sha":"a1b2c3"}env=prod,sha=a1b2c3(correct)"deploy failed on prod"0=d,1=e,2=p,3=l,4=o,5=y,6=, … one per character42true["a","b"]0=a,1=bA one-line message plus a plain-string context is the obvious thing to reach for from an API client, and
apps/pwa/README.mddocumentsPOST /api/approvalsas the ingest endpoint. The operator gets a page full of single-letter tiles instead of the note that was sent.The fix
apps/pwa/src/routes/approvals.mjsonly, two lines of logic:Only a real object is a map; anything else becomes a single
contextcell.Deliberately preserved:
${cells ? ... : ""}guard already handles it).esc().The
raw !== nullguard is also why the route can't be made to throw here:Object.entries(null)is aTypeError, and every route in this app is an async handler, which Express 4 does not route to the error handler.Tests
New
apps/pwa/test/approvals-context.test.mjs— 5 tests, following the existingapprovals-notify.test.mjspattern (realapprovalsRouter, throwaway libsql file db, skip-guard so the rootnpm teststays green withoutnpm installinapps/pwa).Stash-verified with
git stash push -- apps/pwa/src/:Full root suite
npm test: 202 tests / 202 pass / 0 fail (baseline onmainwas 197).