Public: anyone can read this; the crew can change it.

The Apple app can read the game door, lock it and open a write window, through one JSON route #18341

opened this

Merged 35m ago, live in production

I added /api/v1/games/ /door for the Apple app (src/http/api/gamedoor.ts). bun test test/game-door-api.test.ts passes (5 tests), tsc --noEmit is clean, and bun scripts/gate.ts raised only two points, which I answered or flagged below. I did not run the whole suite; the forge's check will.

Notes

opened this

I added /api/v1/games/<box>/door for the Apple app (src/http/api/game_door.ts). bun test test/game-door-api.test.ts passes (5 tests), tsc --noEmit is clean, and bun scripts/gate.ts raised only two points, which I answered or flagged below. I did not run the whole suite; the forge's check will. I did not exercise the route against a running preview.

  • Read: GET returns the door state and the page's words for it. It needs a read token.
  • Lock: POST {op:"lock"} calls lockDoor. It needs a write token, and a cookie post must be same-origin.
  • Open: POST {op:"open", challenge, id, clientDataJSON, authenticatorData, signature} calls openWindow only when passkeyProves accepts the answer. Otherwise it returns 403 "Opening a write window needs a passkey of yours, signed just now. The game door stays as it was."
  • Challenge (my addition): the app needs a challenge before it can sign one. POST {op:"challenge"} returns the challenge, allow and rpId, the same as the page's /door/options.
  • Access: the owner check is roleOn and mayDo(…, "owner"), so forge admins count as owners and anyone else gets 404. No new grant.
  • Reused: doorOf, doorWords, lockDoor, openWindow, proofChallenge, passkeyProves and PROOF_FIELDS. Nothing was edited in src/web/pages/games_door.ts.
  • Audit: the page writes no audit row for lock or open, so this route writes none either, which matches the page.
  • Route table: I regenerated src/http/lazy_lists.ts because the API router is a lazy family.
  • Tests: test/game-door-api.test.ts covers owner lock, non-owner 404 on GET and POST, a bad op (422), a cross-origin cookie post (403), open without proof (403), and open with a real ES256 proof. The proof test opens for WINDOW_MINUTES, lifts a lock, and shows a replayed challenge is refused.
  • Terminal door: none added. The terminal already locks the door with w. The commit says No door:, and I added a section to docs/features/game-box.md.
  • Gate: the pre-push rule wanted a "Try:" line, so I added one in an empty commit. It also flagged my test's user helper as 0.91 similar to the one in test/ask-settles.test.ts. I left that alone and the push went through.
  • Left out: setting the window length and lock-on-leave stay on the page and in the terminal.

Try it: make a write token at /settings/tokens for a box owner, then curl -H "authorization: Bearer $T" <preview>/api/v1/games/<box>/door. Then POST with {"op":"lock"}.

[{"go":"GET /api/v1/games/<box>/door with an owner's token","look":"JSON with state, minutes and words","expect":"200 for the owner, 404 for anyone else"},{"go":"POST {\"op\":\"open\"} with no passkey fields","look":"the error body","expect":"403 saying a passkey signed just now is needed"}]

Closes #18337

2 earlier comments
commented

I added /api/v1/games/<box>/door for the Apple app (src/http/api/game_door.ts). bun test test/game-door-api.test.ts passes (5 tests), tsc --noEmit is clean, and bun scripts/gate.ts raised only two points, which I answered or flagged below. I did not run the whole suite; the forge's check will. I did not exercise the route against a running preview.

  • Read: GET returns the door state and the page's words for it. It needs a read token.
  • Lock: POST {op:"lock"} calls lockDoor. It needs a write token, and a cookie post must be same-origin.
  • Open: POST {op:"open", challenge, id, clientDataJSON, authenticatorData, signature} calls openWindow only when passkeyProves accepts the answer. Otherwise it returns 403 "Opening a write window needs a passkey of yours, signed just now. The game door stays as it was."
  • Challenge (my addition): the app needs a challenge before it can sign one. POST {op:"challenge"} returns the challenge, allow and rpId, the same as the page's /door/options.
  • Access: the owner check is roleOn and mayDo(…, "owner"), so forge admins count as owners and anyone else gets 404. No new grant.
  • Reused: doorOf, doorWords, lockDoor, openWindow, proofChallenge, passkeyProves and PROOF_FIELDS. Nothing was edited in src/web/pages/games_door.ts.
  • Audit: the page writes no audit row for lock or open, so this route writes none either, which matches the page.
  • Route table: I regenerated src/http/lazy_lists.ts because the API router is a lazy family.
  • Tests: test/game-door-api.test.ts covers owner lock, non-owner 404 on GET and POST, a bad op (422), a cross-origin cookie post (403), open without proof (403), and open with a real ES256 proof. The proof test opens for WINDOW_MINUTES, lifts a lock, and shows a replayed challenge is refused.
  • Terminal door: none added. The terminal already locks the door with w. The commit says No door:, and I added a section to docs/features/game-box.md.
  • Gate: the pre-push rule wanted a "Try:" line, so I added one in an empty commit. It also flagged my test's user helper as 0.91 similar to the one in test/ask-settles.test.ts. I left that alone and the push went through.
  • Left out: setting the window length and lock-on-leave stay on the page and in the terminal.

Try it: make a write token at /settings/tokens for a box owner, then curl -H "authorization: Bearer $T" <preview>/api/v1/games/<box>/door. Then POST with {"op":"lock"}.

[{"go":"GET /api/v1/games/<box>/door with an owner's token","look":"JSON with state, minutes and words","expect":"200 for the owner, 404 for anyone else"},{"go":"POST {\"op\":\"open\"} with no passkey fields","look":"the error body","expect":"403 saying a passkey signed just now is needed"}]
commented

The Apple app can now read the game door, lock it and open a write window through /api/v1/games/<box>/door. The check failed on the new route because the page-budget test wants every route it can't fill with a fixture listed in its own file. I added test/budgets/unfixtured/api-v1-games-box-door.json, and test/pages-budget.test.ts and test/page-budget-files.test.ts pass again. I haven't re-run the full check; the forge will on this push.

  • Read: GET returns the door state and the page's words for it. It needs a read token.
  • Lock: POST {op:"lock"} locks the door. It needs a write token, and a cookie post must be same-origin.
  • Open: POST {op:"open", challenge, id, clientDataJSON, authenticatorData, signature} opens a window of the box's length only when one of the owner's passkeys signed the challenge just now. Otherwise it returns 403 in plain words and the door stays as it was.
  • Challenge: I added POST {op:"challenge"}, which returns the challenge, allow and rpId. The app needs it to get something to sign. This goes beyond the issue's list.
  • Access: only the box's owner can use it (forge admins own every box); anyone else gets 404. No new grant.
  • Audit: the web page writes no audit row for lock or open, so this route writes none either.
  • Reused: doorOf, doorWords, lockDoor, openWindow, proofChallenge, passkeyProves and PROOF_FIELDS. src/web/pages/games_door.ts is untouched.
  • Left out: setting the window length and lock-on-leave stay on the page and in the terminal. There is no new terminal screen, because w on the box screen already locks the door. The how-to is in docs/features/game-box.md.

Try it: make a write token at /settings/tokens for a box owner, then curl -H "authorization: Bearer $T" <preview>/api/v1/games/<box>/door. Then POST {"op":"lock"}.

[{"go":"GET /api/v1/games/<box>/door with an owner's token","look":"JSON with state, minutes and words","expect":"200 for the owner, 404 for anyone else"},{"go":"POST {\"op\":\"open\"} with no passkey fields","look":"the error body","expect":"403 saying a passkey signed just now is needed"}]
commented

The Apple app can now read, lock and open the game door through one JSON route, /api/v1/games/:box/door. This push fixes the two failures that were mine. The check's third failure, the "N+1" test, passed on my rerun and I changed nothing for it, so I can't say what caused it.

What the check was failing on

  • OpenAPI: the new route had no row. I added getApiV1GamesBoxDoor.ts and postApiV1GamesBoxDoor.ts under src/contract/openapi/routes/ and regenerated the index.
  • Security floor: the test's list of routes the seed can't fill didn't name the route. I added /api/v1/games/:box/door with its reason: it needs a game box owned by the signed-in person, and the seed has none.
  • N+1: the "a pull's crew activity does not cost more as its agent runs grow" test passed on my rerun.

Checks run locally

  • The security-floor, surfaces-adversarial, openapi-covers-routes, openapi-routes and game-door-api tests pass (642 pass, 0 fail).
  • tsc is clean.
  • gate --fix changed nothing. It did print one similarity hint: mk in test/game-door-api.test.ts looks like person in test/ask-settles.test.ts. I left it.

Left out: the page and terminal sides of the door already existed. The commit says No door: and the how-to is already in game-box.md.

To try it: curl -H 'authorization: Bearer <write token of a box owner>' <preview>/api/v1/games/<box>/door, then POST {"op":"lock"}.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs