Skip to content

Commit b7c66b8

Browse files
committed
refactor: split the test-suite command out of the replay handler
Keeps handleSessionReplayCommands a routing decision and shares the replay/test request field vocabulary between the CLI flag surface and the client request envelope.
1 parent d6c2828 commit b7c66b8

9 files changed

Lines changed: 522 additions & 485 deletions

File tree

‎packages/contracts/src/cli-flags.ts‎

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import type {
2020
} from './remote-config-fields.ts';
2121
import type { ScreenshotRequestFlags } from './screenshot.ts';
2222
import type { RecordingScope } from './recording-scope.ts';
23-
import type { ReplayScriptSourceBundle } from './replay.ts';
23+
import type { ReplayRequestFields } from './replay-request-fields.ts';
2424

2525
export type CliFlags = CloudProviderProfileFields &
2626
RemoteConfigMetroOptions &
27-
ScreenshotRequestFlags & {
27+
ScreenshotRequestFlags &
28+
ReplayRequestFields & {
2829
json: boolean;
2930
config?: string;
3031
remoteConfig?: string;
@@ -140,30 +141,9 @@ export type CliFlags = CloudProviderProfileFields &
140141
record?: boolean;
141142
retainPaths?: boolean;
142143
retentionMs?: number;
143-
replayUpdate?: boolean;
144144
replayMaestro?: boolean;
145-
replayEnv?: string[];
146-
replayShellEnv?: Record<string, string>;
147-
/**
148-
* #1802: the caller-read script text `replay` executes. The daemon never
149-
* opens a caller path, so this is the ONLY source a replay run reads.
150-
*/
151-
replayScriptSource?: ReplayScriptSourceBundle;
152-
/** #1802: `test`'s caller-side discovery result — one bundle per discovered source, in run order. */
153-
replayScriptSources?: ReplayScriptSourceBundle[];
154-
replayFrom?: number;
155-
replayPlanDigest?: string;
156-
/** Replay: leave the session active by suppressing an authored terminal close in native .ad. */
157-
replayKeepSession?: boolean;
158-
failFast?: boolean;
159-
timeoutMs?: number;
160-
retries?: number;
161-
recordVideo?: boolean;
162-
artifactsDir?: string;
163145
reporter?: string[];
164146
reportJunit?: string;
165-
shardAll?: number;
166-
shardSplit?: number;
167147
steps?: string;
168148
stepsFile?: string;
169149
findFirst?: boolean;

‎packages/contracts/src/client-request.ts‎

Lines changed: 43 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,67 +15,51 @@ import type {
1515
SessionRuntimeHints,
1616
} from '@agent-device/kernel/contracts';
1717
import type { DaemonBatchStep } from './batch-step.ts';
18-
import type { ReplayScriptSourceBundle } from './replay.ts';
18+
import type { ReplayRequestFields } from './replay-request-fields.ts';
1919
import type { AgentDeviceClientConfig, AgentDeviceSelectionOptions } from './client-connection.ts';
2020

21-
export type CommandExecutionOptions = Partial<ScreenshotRequestFlags> & {
22-
positionals?: string[];
23-
kind?: string;
24-
out?: string;
25-
artifact?: string;
26-
dsym?: string;
27-
searchPath?: string;
28-
interactiveOnly?: boolean;
29-
depth?: number;
30-
scope?: string;
31-
raw?: boolean;
32-
customActions?: boolean;
33-
forceFull?: boolean;
34-
count?: number;
35-
fps?: number;
36-
recordingScope?: RecordingScope;
37-
quality?: RecordingExportQuality;
38-
hideTouches?: boolean;
39-
intervalMs?: number;
40-
delayMs?: number;
41-
durationMs?: number;
42-
holdMs?: number;
43-
jitterPx?: number;
44-
pixels?: number;
45-
doubleTap?: boolean;
46-
verify?: boolean;
47-
settle?: boolean;
48-
settleQuietMs?: number;
49-
clickButton?: ClickButton;
50-
pauseMs?: number;
51-
pattern?: SwipePattern;
52-
headless?: boolean;
53-
restart?: boolean;
54-
replayUpdate?: boolean;
55-
replayBackend?: string;
56-
replayEnv?: string[];
57-
replayShellEnv?: Record<string, string>;
58-
/** #1802: caller-read script text for `replay`; the daemon never opens a caller path. */
59-
replayScriptSource?: ReplayScriptSourceBundle;
60-
/** #1802: caller-side `test` discovery result — one bundle per discovered source, in run order. */
61-
replayScriptSources?: ReplayScriptSourceBundle[];
62-
replayFrom?: number;
63-
replayPlanDigest?: string;
64-
replayKeepSession?: boolean;
65-
failFast?: boolean;
66-
timeoutMs?: number;
67-
retries?: number;
68-
recordVideo?: boolean;
69-
artifactsDir?: string;
70-
shardAll?: number;
71-
shardSplit?: number;
72-
findFirst?: boolean;
73-
findLast?: boolean;
74-
networkInclude?: NetworkIncludeMode;
75-
batchOnError?: 'stop';
76-
batchMaxSteps?: number;
77-
batchSteps?: DaemonBatchStep[];
78-
};
21+
export type CommandExecutionOptions = Partial<ScreenshotRequestFlags> &
22+
ReplayRequestFields & {
23+
positionals?: string[];
24+
kind?: string;
25+
out?: string;
26+
artifact?: string;
27+
dsym?: string;
28+
searchPath?: string;
29+
interactiveOnly?: boolean;
30+
depth?: number;
31+
scope?: string;
32+
raw?: boolean;
33+
customActions?: boolean;
34+
forceFull?: boolean;
35+
count?: number;
36+
fps?: number;
37+
recordingScope?: RecordingScope;
38+
quality?: RecordingExportQuality;
39+
hideTouches?: boolean;
40+
intervalMs?: number;
41+
delayMs?: number;
42+
durationMs?: number;
43+
holdMs?: number;
44+
jitterPx?: number;
45+
pixels?: number;
46+
doubleTap?: boolean;
47+
verify?: boolean;
48+
settle?: boolean;
49+
settleQuietMs?: number;
50+
clickButton?: ClickButton;
51+
pauseMs?: number;
52+
pattern?: SwipePattern;
53+
headless?: boolean;
54+
restart?: boolean;
55+
replayBackend?: string;
56+
findFirst?: boolean;
57+
findLast?: boolean;
58+
networkInclude?: NetworkIncludeMode;
59+
batchOnError?: 'stop';
60+
batchMaxSteps?: number;
61+
batchSteps?: DaemonBatchStep[];
62+
};
7963

8064
export type InternalRequestOptions = AgentDeviceClientConfig &
8165
AgentDeviceSelectionOptions &
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { ReplayScriptSourceBundle } from './replay.ts';
2+
3+
/**
4+
* The replay/test request vocabulary, declared once.
5+
*
6+
* `CliFlags` and `CommandExecutionOptions` are two views of the same request — the flags a CLI
7+
* invocation parses and the options a programmatic call passes — and every replay/suite field
8+
* appears in both. Stating them here keeps the two views from drifting field by field; each view
9+
* adds only what is genuinely its own (`replayMaestro` and the reporter flags are CLI-side,
10+
* `replayBackend` is the resolved engine the client sends).
11+
*/
12+
export type ReplayRequestFields = {
13+
replayUpdate?: boolean;
14+
replayEnv?: string[];
15+
replayShellEnv?: Record<string, string>;
16+
/**
17+
* #1802: the caller-read script text `replay` executes. The daemon never opens a caller path,
18+
* so this is the ONLY source a replay run reads.
19+
*/
20+
replayScriptSource?: ReplayScriptSourceBundle;
21+
/** #1802: `test`'s caller-side discovery result — one bundle per discovered source, in run order. */
22+
replayScriptSources?: ReplayScriptSourceBundle[];
23+
replayFrom?: number;
24+
replayPlanDigest?: string;
25+
/** Replay: leave the session active by suppressing an authored terminal close in native .ad. */
26+
replayKeepSession?: boolean;
27+
failFast?: boolean;
28+
timeoutMs?: number;
29+
retries?: number;
30+
recordVideo?: boolean;
31+
artifactsDir?: string;
32+
shardAll?: number;
33+
shardSplit?: number;
34+
};

‎src/__tests__/test-utils/replay-script-source.ts‎

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,41 @@ export const noMaestroIncludeSources: MaestroSourceReader = (resolvedPath) => {
3535
* Test harnesses that stand in for "a request as it arrives at the daemon" call this so their
3636
* cases keep expressing what they are about; a request that already carries its own sources (or
3737
* deliberately carries none, to pin the daemon's refusal) is returned untouched.
38+
*
39+
* Collection that cannot succeed — a case driving `replay` at a path that deliberately does not
40+
* exist — leaves the request alone rather than throwing: the real client raises that failure at
41+
* the CLI boundary (pinned in `cli-client-commands.test.ts`), and a daemon-level harness must
42+
* still deliver the request so the daemon's own response is what the case observes.
3843
*/
3944
export function withClientReplayScriptSources(req: DaemonRequest): DaemonRequest {
4045
if (req.command !== 'replay' && req.command !== 'test') return req;
4146
const inputs = req.positionals ?? [];
42-
if (inputs.length === 0) return req;
47+
const entryPath = inputs[0];
48+
if (entryPath === undefined) return req;
4349
const cwd = req.meta?.cwd ?? process.cwd();
4450
const replayBackend = req.flags?.replayBackend;
45-
const entryPath = inputs[0];
46-
if (req.command === 'replay') {
47-
if (req.flags?.replayScriptSource || entryPath === undefined) return req;
48-
return {
49-
...req,
50-
flags: {
51-
...(req.flags ?? {}),
51+
try {
52+
if (req.command === 'replay') {
53+
if (req.flags?.replayScriptSource) return req;
54+
return withFlags(req, {
5255
replayScriptSource: buildReplayScriptSourceBundle({
5356
inputPath: entryPath,
5457
cwd,
5558
replayBackend,
5659
}),
57-
},
58-
};
59-
}
60-
if (req.flags?.replayScriptSources) return req;
61-
return {
62-
...req,
63-
flags: {
64-
...(req.flags ?? {}),
60+
});
61+
}
62+
if (req.flags?.replayScriptSources) return req;
63+
return withFlags(req, {
6564
replayScriptSources: discoverReplaySourcePaths({ inputs, cwd, replayBackend }).map(
6665
(inputPath) => buildReplayScriptSourceBundle({ inputPath, cwd, replayBackend }),
6766
),
68-
},
69-
};
67+
});
68+
} catch {
69+
return req;
70+
}
71+
}
72+
73+
function withFlags(req: DaemonRequest, flags: Partial<DaemonRequest['flags']>): DaemonRequest {
74+
return { ...req, flags: { ...(req.flags ?? {}), ...flags } };
7075
}

‎src/daemon/handlers/__tests__/session-replay-cancellation.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
markRequestCanceled,
77
registerRequestAbort,
88
} from '../../../request/cancel.ts';
9-
import { bindReplayTestAttemptCancellation } from '../session-replay.ts';
9+
import { bindReplayTestAttemptCancellation } from '../session-test-suite-command.ts';
1010

1111
// The daemon half of the replay-test cancellation seam (#1478 P3b). The scheduler only says
1212
// "cancel" and "release"; everything here — registry entries, the parent-abort relay, and

‎src/daemon/handlers/__tests__/session-replay.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { SessionStore } from '../../session-store.ts';
66
import { LeaseRegistry } from '../../lease-registry.ts';
77
import type { DaemonRequest, DaemonResponse } from '../../types.ts';
88
import { makeIosSession } from '../../../__tests__/test-utils/index.ts';
9-
import { buildNestedReplayFlags, handleSessionReplayCommands } from '../session-replay.ts';
9+
import { handleSessionReplayCommands } from '../session-replay.ts';
10+
import { buildNestedReplayFlags } from '../session-test-suite-command.ts';
1011
import { REPLAY_ONLY_TEST_FLAG_REJECTIONS } from '../session-replay-test-policy.ts';
1112
import { replayCommandFamily } from '../../../commands/replay/index.ts';
1213
import { mkdtempForTestSync } from '../../../__tests__/test-utils/tmp-dir.ts';

0 commit comments

Comments
 (0)