refactor: split the test-suite command out of the replay handler - #1826
Conversation
Size Report
Startup median (7 runs, lower is better):
Top changed chunks:
|
6ed9091 to
c7e3e5e
Compare
|
The production move itself is behavior-preserving, but this is not ready yet. AGENTS.md requires tests to mirror source topology when a module splits: |
handleSessionReplayCommands becomes the routing decision alone; the test suite's harness-flag admission, request translation and scheduler run move to session-test-suite-command.ts beside the replay runtime they already sit next to. Pure move: no behavior change.
c7e3e5e to
d3ec226
Compare
Tests now follow the split; retargeted to
|
| Was | Now | Tests |
|---|---|---|
session-replay.test.ts (560 lines, mixed) |
session-test-suite-command-nested-flags.test.ts |
5 |
session-test-suite-command-flag-policy.test.ts |
6 | |
session-test-suite-command-video.test.ts |
1 | |
session-replay-cancellation.test.ts |
session-test-suite-command-cancellation.test.ts (renamed) |
5 |
One deviation from your wording, deliberate and worth your call: session-replay.test.ts is deleted, not trimmed to router tests. All 12 of its tests were suite-owned — buildNestedReplayFlags projection, the raw replay-only flag rejections, and the video-finalization case — so there was nothing router-shaped to leave behind. The surviving 34-line router's delegation is already exercised by every harness-driven handler suite that goes through handleSessionCommands. I did not write new router tests because that would have made this PR stop being a pure move and stop being checkable as one; if you would rather have a dedicated router/delegation test, I will add it in a follow-up (or here, if you prefer).
Proven as a pure move, not asserted: 17 tests before, 17 after, and I diffed the before/after sets of test titles — identical, so nothing was dropped, renamed, or silently skipped by the runner. Bodies were copied by line range; only the per-file import headers are new. pnpm format && pnpm check:affected --run green.
Stacking section fixed. #1810 merged (60f6356b0), so this is rebased onto main and targets main directly — the body no longer claims a stack, and the PR is out of draft. Note GitHub had already auto-retargeted it when the base branch was deleted on merge; I verified my local rebase produced a tree identical to GitHub's auto-rebased head before force-pushing, so no content moved in the process.
Head is d3ec22674, diff is 6 files / +687 −629 — the module move plus the test files that follow it.
|
Re-reviewed One topology gap remains: Also update the stale Stacking section: #1810 has merged, this PR targets |
session-replay.ts is a router now, so it gets a focused test of its own (AGENTS.md 1:1 source/test topology): replay reaches the script-source runtime, test reaches the suite command with the whole parameter set, and an unrelated command is declined. Both destinations are mocked so a wrong edge shows up as the wrong marker; each case was proven red by mutating the routing it pins.
Router test added; Stacking section actually removed this timeBoth fixed in Router test.
Both destinations are mocked, so a mis-wired edge shows up as the wrong marker instead of a device-level failure. Each case was proven non-vacuous against the mutation it actually pins, not just "it passes":
The router was restored byte-for-byte afterwards ( Stacking section. Apologies — my earlier edit genuinely did not land, and I reported it as done. The cause: I passed Head is |
|
iOS Smoke at a3388f8 failed in the Swift runner's own XCTest ( |
|
Summary
A pure move, split out of #1810 (now merged) so that PR could stay the fix.
handleSessionReplayCommandshad grown into two unrelated halves: a three-line routing decision, and the wholetest-suite orchestration — harness-flag admission, request translation, per-attempt video recording, shard resolution and the scheduler run. This moves the second half tosession-test-suite-command.ts, besidesession-replay-runtime.tswhere thereplayhalf already lives, and leavessession-replay.tsas the router it reads as.src/daemon/handlers/session-replay.ts: 413 → 34 linessrc/daemon/handlers/session-test-suite-command.ts: new, 410 linesNo behavior change and no logic edits: the moved code is byte-identical apart from the
testbranch becoming a function body (dedented, with itsparamsdestructured at the top instead of inherited from the enclosing scope).buildNestedReplayFlagsandbindReplayTestAttemptCancellationmove with it.Tests follow the split
AGENTS.md: "test files mirror source topology 1:1; when a source module splits, split its test file in the same PR." The tests move with the code they own:
session-replay.test.ts(560 lines, mixed)session-test-suite-command-nested-flags.test.tssession-test-suite-command-flag-policy.test.tssession-test-suite-command-video.test.tssession-replay-cancellation.test.tssession-test-suite-command-cancellation.test.ts(renamed)That move is checked as a move: 17 tests before, 17 after, with the before/after sets of test titles diffed and identical, so nothing was dropped, renamed, or skipped past the runner. Bodies were copied by line range; only per-file import headers are new.
Every one of those 12 tests was suite-owned, so the router was left with no test file of its own.
session-replay.test.tsis therefore rewritten as the router's focused test rather than deleted, closing the 1:1 gap:replayreaches the script-source runtime (and the suite command is not called)testreaches the suite command with the whole parameter set — narrowing here is what would silently drop video recording, sharding and device bindingnull, so another handler family can claim itBoth destinations are mocked, so a mis-wired edge surfaces as the wrong marker rather than a device-level failure. Each case was proven non-vacuous by mutating exactly the routing it pins: swapping the two delegations fails the first two, and making the fallthrough claim the request fails the third.
Validation
pnpm format && pnpm check:affected --rungreen. Rebased ontomainafter #1810 merged (60f6356b0); this targetsmaindirectly and is out of draft.