Skip to content

test(e2e): run advisory questions end to end on a controllable clock - #205

Merged
gregpriday merged 4 commits into
developfrom
feature/issue-192-run-an-advisory-question-end-to-end-with
Nov 19, 2026
Merged

gregpriday merged 4 commits into
developfrom
feature/issue-192-run-an-advisory-question-end-to-end-with

Conversation

@gregpriday

Copy link
Copy Markdown
Contributor

Adds a controllable clock across the relay, the bridge and the phone, and an end-to-end suite that takes advisory questions through the standalone path (agent → MCP → relay → phone → the asking pane) past their deadlines without waiting for them.

Resolves #192

The clock

  • Relay: worker/tests/e2e-clock-worker.ts is an e2e-only entry that wrangler dev runs in place of the config's main (the shipped bundle is built from main and never includes it). It wraps the production Worker and DecisionRoom behind a shifted Date.now, translates the room's native alarms between the moved and the real clock, and answers POST /__e2e/clock (an absolute offset) by running the room's alarm, as the runtime would once the time arrived. Alarm passes run one at a time. A restored offset re-arms a stale alarm, and HTTP responses carry the moved time in Date, the header a client learns its skew from.
  • Bridge and MCP: TestClock.now is passed as now to RelayClient, DecisionsBridge and startDecisionsMcpServer.
  • Phone: Playwright's clock, installed on the phone's browser context before it loads.
  • TestClock.advance(ms) moves all three in steps of at most 60 s (half the relay's request skew allowance). Each step moves the test process first, then the relay, then the phone, so the bridge is never behind the relay when an expiry reaches it (an expiry received well before its deadline is refused for good). A move that fails partway refuses every later one. Settling the bridge stays with the test, so the follow-up (Cover advisory faults and restarts in the end-to-end suite #193) can move time while a participant is offline.

The outcomes (e2e/tests/advisory-loop.test.ts)

  • Timely answer: ten minutes into a fifteen-minute window the person picks the option that isn't the plan. It reaches the asking pane as the person's answer, and the deadline passing afterwards changes nothing.
  • Ignored advice: before the deadline the phone shows Reply by, the time left (counting down as the clock moves) and the agent's plan. After it, the phone shows the relay-confirmed closed state. The pane receives the advisory-unanswered notice, byte for byte ADVISORY_TIMEOUT_NOTICE_FIXTURE.due with this run's ID, alias, injection ID, question and deadline substituted. get_decision matches ADVISORY_TIMEOUT_DECISION_FIXTURE (fallback_due: true, the stated planned_fallback).
  • Declined advice: dismissed on the phone, it reports cancelled with closed_reason: declined and a single status: declined notice. Its deadline passing later makes nothing due.
  • Expired approval: a gated design sign-off from a pane the host bound to the gate. The relay holds it signed human-required and blocking, and the phone shows "Human decision required". When it expires the pane receives status: expired with authorised: no. Every get_decision view on the way reports fallback_due: false, including one read while the pane is busy and the expiry is still waiting to be typed.
  • The relay's own alarm: every relay read lazily expires overdue questions, which would hide a broken scheduler. With the phone off the relay and nobody settling, one deadline passes with the move (typed before the second deadline) and another five seconds later in real time (the runtime's alarm, set on the moved clock). Both expiries reach the bridge over its socket alone.

The pane sink, the SDK connection, pairing and the inbox helpers move from mcp-loop.test.ts to e2e/tests/mcp-agent.ts so both suites share them. startRelay takes an optional script, and until an optional poll interval.

Testing

  • Own: e2e/tests/advisory-loop.test.ts, 5/5 on every run (repeated runs, about 10 s each).
  • Adjacent: e2e/tests/mcp-loop.test.ts and e2e/tests/sync-replay.test.ts, 11/11.
  • Impact: 15 of 144 test files (worker tests beside the new entry), 139 tests green.
  • Mutations, each confirmed to fail the suite: the relay without alarm translation (fails at the second, real-time expiry), a move without its alarm call (fails at the first expiry), the bridge off the clock (skew refusals), and the phone off the clock (its sync stalls).
  • Rerun on the current develop after rebuilding the app: own and adjacent 14/14.
  • Prettier on the changed files. No type check ran locally: the repository has no typecheck:changed, so the CI pnpm typecheck covers the new files (the entry is under worker/tests, which the worker tsconfig includes).

- Run the relay as an e2e-only entry with a shifted clock, translated alarms and a route that moves it
- Move the relay, the bridge and the phone together in steps inside the skew allowance
- Cover a timely answer, an ignored advisory, a decline and an expired gated approval
- Prove the relay's own alarm closes questions with nobody reading them
- Share the MCP agent, pane sink and pairing helpers with the MCP loop suite
…what was signed

- Serialize the room's alarm passes, re-arm a stale alarm on restore, and refuse a move that leaves jobs due
- Date clocked HTTP responses on the moved clock, so a client never learns a wall-clock skew
- Refuse moves after one fails partway, and attach phones between moves
- Bind the approval's gate to its pane, check the signed record, and sample fallback_due on every view
- Keep the phone off the relay in the alarm test and require the first expiry before the second deadline
- Check the notice substitutions exactly once, poll get_decision within MCP's rate limit
…he alarm test's margin

- Hold the approval's pane busy so get_decision is read while the expiry waits to be typed
- Ask the alarm test's questions for the shortest windows, five seconds apart, and order them by injection time
- Re-arm the alarm whenever a room restores a moved clock, and date the control route's responses too
@gregpriday
gregpriday merged commit 0d57eac into develop Nov 19, 2026
2 checks passed
@gregpriday
gregpriday deleted the feature/issue-192-run-an-advisory-question-end-to-end-with branch November 19, 2026 13:59
@gregpriday gregpriday mentioned this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run an advisory question end to end with a controllable clock

1 participant