Repository navigation
Make six implicit state machines explicit (#9) - #10
Conversation
KeyStore.approverMode() derives 'unpaired' | 'phone' | 'phone-empty' from the stored latch and approver count; approverModeRules() replaces the three hand-written conditions in server.ts. Nothing new is written to disk. Table test walks every mode against every event. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJaP4fvvUwCMdb6ZKz8q8s
HandoffState (awaiting_approval | waiting_for_phone | controlled | ended) replaces controller, ended, endedAt, claimed and abort; nextHandoffState is the only transition. lastEnded keeps a small record instead of the whole handoff, so an ended handoff no longer pins its page and session. signIn.ended now runs exactly once per handoff with a sign-in offer: an end while the card waits runs it after the approval settles, so a late grant is still dropped. The one test that pinned the old double call now expects one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJaP4fvvUwCMdb6ZKz8q8s
Mailbox<T> (put / has / take, read at most once inside its window) replaces the hand-rolled claimed flags for handoff results and passkey ceremony results. Both 60-second windows and the 32-entry ceremony cap are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJaP4fvvUwCMdb6ZKz8q8s
PairingState replaces the four-value state and the nullable challenge, token and kind; nextPairingState is the only transition and pairingStatus the one map to the strings the page and iOS app read (unchanged). A finish now takes the pairing (verifying) before its first await, so two finishes on one code can no longer both reach the signer: the second gets the existing 409. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJaP4fvvUwCMdb6ZKz8q8s
CardState (queued | signing | approved | denied | timed_out) replaces the nullable statement and the done flag; nextCardState is the only transition. Keeps today's behaviour (option A, latest tap wins), now pinned by a test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJaP4fvvUwCMdb6ZKz8q8s
CoreGrant and the signer's internal Grant are now 'window' | 'single' unions (core: phase held | armed; signer: spentBy) instead of optional singleUse / armed / usedBy / handoffId. The broker's Authorized is by-grant | by-approval, so registration can no longer receive a grant and its internal_error guard goes away. No signer protocol change. grants.test.ts builds grants in the new shape; its assertions are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJaP4fvvUwCMdb6ZKz8q8s
GitHub's current Ubuntu runner ships uutils coreutils, where /usr/bin/env is a symlink. install-config rightly refuses a linked tool, but the two service-config tests guarded with statSync, which follows the link, and so ran the positive pin case on a path the product must refuse. Guard with lstatSync().isFile() like inv1-tool-trust.test.ts already does. No assertion changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJaP4fvvUwCMdb6ZKz8q8s
|
CI Ported fix in b27b2c9: the tests now guard with Generated by Claude Code |
|
macOS Generated by Claude Code |
johnpippett
left a comment
There was a problem hiding this comment.
Review of b27b2c9 against issue #9. The six refactors hold up and I found no outright regression. Typecheck, lint, the three source checks and the nine touched unit test files (203 tests) pass on this head; e2e and isolation were not run for this review.
Fix before merge (4 inline comments):
phone.ts:1057: "latest tap wins" does not hold on the webdecidepath, and an expired statement can consume the card.handoff.test.ts:655: an existing expectation was edited; needs the owner's explicit yes.handoff.ts:554: the once-onlysignIn.endeddepends on the approval promise settling; if it does not, a single-use grant is never dropped.service-config.test.ts:271: the test returns early on Linux CI and asserts nothing. Unrelated to #9.
Smaller (6 inline comments): a test that asserts nothing, a stale IMPLEMENTATION_NOTES entry, a mailbox round trip plus a leftover flag, transition detection by object identity, and two cleanup notes.
Issue #9 asked for one pull request per machine; this is all six in one. Fine to keep as is if the owner prefers, but the unrelated service-config test change should come out.
Generated by Claude Code
…sals - approver: decide and nativeDecide read the card's statement after their last await and verify signature and expiry against it; a finished card answers 404. New approval-card-web.test.ts pins both orders and a challenge landing mid-decision (fails on the old web path). - approver: nextCardState and nextPairingState return null for a refused event instead of relying on object identity; the pairing token lives only in the paired state. - core: end() is the one place that discharges signIn.ended; from awaiting_approval it chains onto the stored approval promise. Tests for an approve that ignores the abort and for handoffs without an offer. Drop stateOf/isEnded, the dead entry guard and the unread ended.at. - core: a ceremony already claimed in flight is not put in the mailbox. - signer: drop the never-read handoffId from the single-use grant. - cli(test): probe for a root-owned regular system file instead of skipping when /usr/bin/env is a symlink, so the pin assertions always run. - notes: bring the SM-1, SM-4, SM-5, SM-6 and SM-2 entries up to date. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJaP4fvvUwCMdb6ZKz8q8s
|
macOS This is a client-side gesture on the phone page. The test asserts that neither Generated by Claude Code |
The phone page posts each live-view input without the click awaiting it, and the handoff applies inputs one after another. The test clicked Enter, then the scroll, then Done straight away, so on a slow runner the handoff could end while the scroll was still queued, and the audited count read scrolls: 0 (macOS CI, run 43151607654). Wait for each input's response first. The assertions are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJaP4fvvUwCMdb6ZKz8q8s
|
The macOS re-run on 53a9957 failed differently. Root cause is a race in the test, not this diff. The live view's Fix in 8864dd8: the test now waits for each On Generated by Claude Code |
What and why
Closes #9. All six implicit state machines are now explicit, one commit per machine in the issue's order (SM-3, SM-1, SM-6, SM-4, SM-5, SM-2). The issue asks for one PR per machine. This session can only push one branch, so they're in one PR. Each commit stands alone (each passes the static checks and its package's tests), so they can be cherry-picked into six PRs if you'd rather review them that way.
Every machine follows the recipe: one tagged union, transitions in one pure
next…Statefunction (or an accessor plus a rules function for SM-3), an exhaustiveswitchwith aneverdefault, events that don't fit leaving the state unchanged, side effects in the caller, and a table test that walks every state against every event. Each one has an entry in the newIMPLEMENTATION_NOTES.mdsection "Explicit state machines (issue 9)".ApproverModesigner/src/approver-mode.ts,KeyStore.approverMode()signer/test/approver-mode.test.ts(realSignerHandler, 3 modes × 6 events)HandoffState,nextHandoffStatecore/src/handoff.tscore/test/handoff-states.test.tsMailbox<T>core/src/mailbox.ts(handoff results + ceremony results)core/test/mailbox.test.tsPairingState,nextPairingState,pairingStatusapprover/src/pairing-state.tsapprover/test/pairing-states.test.tsCardState,nextCardStateapprover/src/approval-card.tsapprover/test/approval-card.test.tsCoreGrant/ signerGrantaswindow | singlecore/src/grants.ts,core/src/broker.ts,signer/src/server.tscore/test/grant-states.test.tsBehaviour changes (all ones the issue asked for)
lastEndedkeeps{handoffId, outcome}, not the wholeHandoff, so an ended handoff no longer pins its Playwright page and session (tested).signIn.endedruns exactly once: if the handoff ends while the card is still waiting, the card is aborted and the hook runs after the approval promise settles, so a grant from a late approval still gets dropped (tested for every end reason, plus "approval lands after end").verifyingbefore its firstawait. Two finishes on one code can no longer both reach the signer; the second gets the existing 409. There's a race test, and it fails on the old code. The status strings are unchanged.Where the issue's spec contradicted itself (please check)
handoff.test.ts: "ending while the owner decides" expectedsignIn.endedto be called twice. Step 4 of SM-1 says exactly once, and the same section says this file must pass unchanged. I followed step 4 and changed that one expectation to a single call. It's the only existing expectation I edited.grants.test.ts: its helper builds grants withsingleUse/armedviaPartial<CoreGrant>. That can't typecheck against the target union, and a window grant can't bearmedany more. I changed how the test builds grants; all its assertions are unchanged.failedkeeps itsdevice. The issue's sketch had none, but both status endpoints answer by device kind and have to keep answering a failed pairing the same way.Owner decisions taken by default
native-api.test.ts› "SM-5 option A" (A asks, B asks, A's signature refused, B's accepted).held/armed. No protocol change, no new request, same checks.I couldn't read
../keyflap-site/notes/DECISIONS.md: the private repo isn't in this session. I changed no policy, approvals, high-risk list or CLI behaviour.Checklist
pnpm checkpasses (andpnpm test:isolationif service mode is touched). See "Test results": everything that can run here is green, and isolation is still owed.pass-cli, never third-party sites or real vaults.docs/IMPLEMENTATION_NOTES.md.Test results (cloud container, root)
pnpm check:static): pass at every commit.pnpm test(all projects, unit + e2e): 2269 passed, 15 failed. All 15 fail the same way on basemainin this container, so none come from this diff:keystore.test.ts› "a migration that cannot be written…" (root ignores chmod) and 8 cases ininstall/test/simple-install-shell.test.ts.claudeCLI on PATH, and root): 4 incli/test/dev-console.e2e.test.tsand 2 incli/test/setup.e2e.test.ts. I reproduced all 6 on a worktree of34f2b4d.doctor.shfailed only its two port-owner checks, becausessisn't installed. Port ownership was confirmed through/proc/net/tcpinstead.pnpm test:isolation: not run to completion. The systemd container starts, butinstall.shrefuses with "--browsers-dir has no Chromium 1248", and the pinned build can't be downloaded from this network. It needs a machine that can fetch the pin. This affects the signer PRs (SM-3, SM-2).service-configtests broke on GitHub's current Ubuntu image (/usr/bin/envis now a uutils symlink). Details in the PR comment.🤖 Generated with Claude Code
https://claude.ai/code/session_01KJaP4fvvUwCMdb6ZKz8q8s