Skip to content

Commit 29a4a3c

Browse files
thymikeeclaude
andauthored
test(daemon): split the three over-budget daemon test files along their source modules (#2417)
* test(daemon): split the three over-budget daemon test files along their source modules snapshot-handler.test.ts, session-replay-repair-transaction.test.ts, and find.test.ts sat over the 1,000-line test-file-size-ratchet tripwire with no headroom (#2346 follow-up). Each mirrors a single source module through an integration-style suite, so each splits by concern rather than by a second source file: - snapshot-handler.test.ts keeps core snapshot/diff routing and policy; snapshot-handler-freshness.test.ts takes annotations, Android timeout evidence, and staleness/visibility warnings; snapshot-handler-capture-retry takes captureSnapshot's pending-outcome and stabilization retries; snapshot-handler-wait.test.ts takes the wait command. The shared handler wrapper moved into the existing snapshot-handler.fixtures.ts sibling. - find.test.ts keeps core click/focus/type dispatch; find-ambiguous-match, find-read-only, and find-production-route take the AMBIGUOUS_MATCH/list behavior, read-only find (wait/exists), and the #1654 real-interaction-leaf route respectively. The shared click-scenario runner moved into the existing find-touch-runtime-fixture.ts sibling. - session-replay-repair-transaction.test.ts keeps the core arm/resume/reap lifecycle; -force takes the #1258 --force/--overwrite preflight; and -close-ordering takes the BLOCKER 2/3 platform-close sequencing. The shared setup/handleCloseCommand/makeCompleteRepairSession helpers moved into the existing session-replay-repair.fixtures.ts sibling. Every moved test keeps its name and body unchanged; verified by diffing each test's body against the pre-split file. No assertion changed and no test was dropped, merged, or added. Two other daemon test files (session-replay-divergence.test.ts, session-replay-runtime-maestro.test.ts) are also over the ratchet tripwire, but were already over it before #2346 and are unrelated to this follow-up — left for a separate issue rather than folded in here. Closes #2353 Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TEA7xjo6a3bJNkb6FLcRK9 * fix(daemon): isolate the repair-transaction fixtures from the shared repair-loop fixture Adversarial review caught that widening session-replay-repair.fixtures.ts with the transaction-specific setup()/handleCloseCommand()/ makeCompleteRepairSession() helpers pulled application-lifecycle-runtime- harness.ts's node:timers/promises mock into three sibling test files (session-replay-repair-loop, -empty-tail, -acceptance) that only needed the fixture's existing makeRecordingReplayInvoke and never declared that mock themselves. Move those helpers into a new session-replay-repair- transaction.fixtures.ts sibling instead, so session-replay-repair.fixtures.ts goes back to its original content and only the three session-replay-repair-transaction*.test.ts files pull in the close-lifecycle harness. Also tightens two stale comments the split left behind: find-handler- fixture.ts no longer motivates itself by find.test.ts's now-resolved size tripwire, and find-production-route.test.ts no longer calls the stub-based tests "above" now that they live in a different file. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TEA7xjo6a3bJNkb6FLcRK9 --------- Co-authored-by: Claude <[email protected]>
1 parent fef0b12 commit 29a4a3c

15 files changed

Lines changed: 2899 additions & 2440 deletions
Lines changed: 376 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,376 @@
1+
import { test, expect, vi, afterEach, beforeEach } from 'vitest';
2+
import { legacyDispatchCapture } from '../../__tests__/legacy-snapshot-capture-fixture.ts';
3+
import {
4+
getRuntimeBindings,
5+
mockTapPoint,
6+
resetGetRuntimeFixture,
7+
} from '../../__tests__/interaction-get-runtime-fixture.ts';
8+
import { captureSnapshot } from '../../snapshot-capture.ts';
9+
import { setActiveProviderDeviceRuntimes } from '../../../provider-device-runtime.ts';
10+
import { buildInteractionSurfaceSignature } from '../../interaction-outcome-policy.ts';
11+
import { buildNodes } from '../../../__tests__/test-utils/snapshot-builders.ts';
12+
import { resetSnapshotRuntimeFixture } from '../../__tests__/snapshot-runtime-fixture.ts';
13+
import {
14+
androidCapture,
15+
androidDevice,
16+
androidTextRows,
17+
inboxBaselineNodes,
18+
iosSimulatorDevice,
19+
makeAndroidFreshnessSession,
20+
makeSession,
21+
} from './snapshot-handler.fixtures.ts';
22+
23+
vi.mock('../../snapshot-interactor-capture.ts', async () => {
24+
const fixture = await import('../../__tests__/legacy-snapshot-capture-fixture.ts');
25+
return { captureSnapshotWithInteractor: fixture.captureSnapshotThroughLegacyDispatchFixture };
26+
});
27+
vi.mock('@agent-device/platform-apple/runner/operations', async (importOriginal) => {
28+
const actual =
29+
await importOriginal<typeof import('@agent-device/platform-apple/runner/operations')>();
30+
return { ...actual, runAppleRunnerCommand: vi.fn(async () => ({})) };
31+
});
32+
33+
// The real implementation shells out to simctl to probe for a hint-worthy
34+
// unambiguous environment; that live-probe logic is covered by
35+
// ios-app-session-hint.test.ts. Stubbed here so this suite stays hermetic and
36+
// fast — defaults to "no enrichment", matching the current-behavior fallback.
37+
vi.mock('../../ios-app-session-hint.ts', () => ({
38+
buildIosOpenCommandHint: vi.fn(async () => undefined),
39+
}));
40+
41+
import { runAppleRunnerCommand } from '@agent-device/platform-apple/runner/operations';
42+
import { buildIosOpenCommandHint } from '../../ios-app-session-hint.ts';
43+
44+
const mockRunnerCommand = vi.mocked(runAppleRunnerCommand);
45+
const mockBuildIosOpenCommandHint = vi.mocked(buildIosOpenCommandHint);
46+
47+
afterEach(() => {
48+
setActiveProviderDeviceRuntimes([]);
49+
});
50+
51+
beforeEach(() => {
52+
resetSnapshotRuntimeFixture();
53+
legacyDispatchCapture.mockReset();
54+
legacyDispatchCapture.mockResolvedValue({});
55+
resetGetRuntimeFixture();
56+
mockRunnerCommand.mockReset();
57+
mockRunnerCommand.mockResolvedValue({});
58+
mockBuildIosOpenCommandHint.mockReset();
59+
mockBuildIosOpenCommandHint.mockResolvedValue(undefined);
60+
});
61+
62+
test('captureSnapshot lazily retries pending no-change touch before returning fresh state', async () => {
63+
const sessionName = 'ios-lazy-outcome-retry';
64+
const session = makeSession(sessionName, iosSimulatorDevice);
65+
const baselineNodes = [
66+
{
67+
ref: 'e1',
68+
index: 0,
69+
depth: 0,
70+
type: 'Button',
71+
label: 'Open feed',
72+
identifier: 'open-feed',
73+
hittable: true,
74+
rect: { x: 20, y: 120, width: 160, height: 48 },
75+
},
76+
];
77+
session.snapshot = {
78+
nodes: baselineNodes,
79+
createdAt: Date.now(),
80+
backend: 'xctest',
81+
};
82+
session.pendingInteractionOutcome = {
83+
action: 'click',
84+
command: 'press',
85+
positionals: ['100', '144'],
86+
flags: { platform: 'ios' },
87+
markedAt: Date.now(),
88+
attemptsRemaining: 2,
89+
preSignature: [
90+
{
91+
key: 'open-feed|Open feed||Button||enabled|unselected|hittable|#0',
92+
x: 20,
93+
y: 120,
94+
width: 160,
95+
height: 48,
96+
discriminating: true,
97+
},
98+
],
99+
};
100+
101+
let pressed = false;
102+
mockTapPoint.mockImplementation(async () => {
103+
pressed = true;
104+
return { clicked: true };
105+
});
106+
legacyDispatchCapture.mockImplementation(async () => {
107+
return {
108+
nodes: !pressed
109+
? baselineNodes
110+
: [
111+
{
112+
index: 0,
113+
depth: 0,
114+
type: 'Button',
115+
label: 'Back',
116+
identifier: 'back',
117+
hittable: true,
118+
rect: { x: 20, y: 60, width: 90, height: 44 },
119+
},
120+
{
121+
index: 1,
122+
depth: 0,
123+
type: 'StaticText',
124+
label: 'Feed',
125+
rect: { x: 20, y: 140, width: 160, height: 48 },
126+
},
127+
],
128+
backend: 'xctest',
129+
};
130+
});
131+
132+
const result = await captureSnapshot({
133+
device: iosSimulatorDevice,
134+
session,
135+
flags: { snapshotInteractiveOnly: true },
136+
logPath: '/tmp/daemon.log',
137+
...getRuntimeBindings(),
138+
});
139+
140+
expect(result.snapshot.nodes).toEqual(
141+
expect.arrayContaining([expect.objectContaining({ label: 'Feed' })]),
142+
);
143+
// R58: the retry re-fires through the bound `tapPoint`, on the recorded coordinate pair.
144+
expect(mockTapPoint).toHaveBeenCalledTimes(1);
145+
expect(mockTapPoint.mock.calls[0]?.[0]?.point).toEqual({ x: 100, y: 144 });
146+
expect(session.pendingInteractionOutcome).toBeUndefined();
147+
});
148+
149+
test('captureSnapshot does not retry when a tap change appears after a short delay', async () => {
150+
const sessionName = 'android-delayed-outcome-without-retry';
151+
const session = makeSession(sessionName, androidDevice);
152+
const baselineNodes = [
153+
{
154+
ref: 'e1',
155+
index: 0,
156+
depth: 0,
157+
type: 'android.widget.Button',
158+
label: 'Open drawer',
159+
hittable: true,
160+
rect: { x: 20, y: 120, width: 160, height: 48 },
161+
},
162+
];
163+
const changedNodes = [
164+
{
165+
index: 0,
166+
depth: 0,
167+
type: 'android.widget.TextView',
168+
label: 'Albums',
169+
rect: { x: 32, y: 240, width: 180, height: 52 },
170+
},
171+
];
172+
session.pendingInteractionOutcome = {
173+
action: 'click',
174+
command: 'press',
175+
positionals: ['100', '144'],
176+
flags: { platform: 'android' },
177+
markedAt: Date.now(),
178+
attemptsRemaining: 2,
179+
preSignature: buildInteractionSurfaceSignature(baselineNodes),
180+
};
181+
182+
let snapshotCalls = 0;
183+
legacyDispatchCapture.mockImplementation(async (_device, command) => {
184+
expect(command).toBe('snapshot');
185+
snapshotCalls += 1;
186+
return {
187+
nodes: snapshotCalls === 1 ? baselineNodes : changedNodes,
188+
backend: 'android',
189+
};
190+
});
191+
192+
const result = await captureSnapshot({
193+
device: androidDevice,
194+
session,
195+
flags: { snapshotInteractiveOnly: true },
196+
logPath: '/tmp/daemon.log',
197+
});
198+
199+
expect(result.snapshot.nodes).toEqual(
200+
expect.arrayContaining([expect.objectContaining({ label: 'Albums' })]),
201+
);
202+
expect(legacyDispatchCapture.mock.calls.map((call) => call[1])).toEqual(['snapshot', 'snapshot']);
203+
expect(session.pendingInteractionOutcome).toBeUndefined();
204+
});
205+
206+
test('captureSnapshot retries pending tap outcome before post-gesture stabilization', async () => {
207+
const sessionName = 'android-maestro-tap-outcome-before-stabilization';
208+
const session = makeSession(sessionName, androidDevice);
209+
const baselineNodes = [
210+
{
211+
ref: 'e1',
212+
index: 0,
213+
depth: 0,
214+
type: 'android.widget.Button',
215+
label: 'Navigate to Third',
216+
hittable: true,
217+
rect: { x: 302, y: 1301, width: 476, height: 110 },
218+
},
219+
];
220+
session.snapshot = {
221+
nodes: baselineNodes,
222+
createdAt: Date.now(),
223+
backend: 'android',
224+
};
225+
session.pendingInteractionOutcome = {
226+
action: 'click',
227+
command: 'press',
228+
positionals: ['540', '1356'],
229+
flags: { platform: 'android' },
230+
markedAt: Date.now(),
231+
attemptsRemaining: 2,
232+
preSignature: [
233+
{
234+
key: '|Navigate to Third||android.widget.Button||enabled|unselected|hittable|#0',
235+
x: 302,
236+
y: 1301,
237+
width: 476,
238+
height: 110,
239+
discriminating: true,
240+
},
241+
],
242+
};
243+
session.postGestureStabilization = {
244+
action: 'click',
245+
positionals: [],
246+
markedAt: Date.now(),
247+
};
248+
249+
let pressed = false;
250+
mockTapPoint.mockImplementation(async () => {
251+
pressed = true;
252+
return { clicked: true };
253+
});
254+
legacyDispatchCapture.mockImplementation(async () => {
255+
return {
256+
nodes: !pressed
257+
? baselineNodes
258+
: [
259+
{
260+
index: 0,
261+
depth: 0,
262+
type: 'android.widget.TextView',
263+
label: 'Tab Third (3)',
264+
rect: { x: 390, y: 884, width: 300, height: 55 },
265+
},
266+
],
267+
backend: 'android',
268+
};
269+
});
270+
271+
const result = await captureSnapshot({
272+
device: androidDevice,
273+
session,
274+
flags: { snapshotInteractiveOnly: true },
275+
logPath: '/tmp/daemon.log',
276+
...getRuntimeBindings(),
277+
});
278+
279+
expect(result.snapshot.nodes).toEqual(
280+
expect.arrayContaining([expect.objectContaining({ label: 'Tab Third (3)' })]),
281+
);
282+
// R58: the retry re-fires through the bound `tapPoint`, on the recorded coordinate pair.
283+
expect(mockTapPoint).toHaveBeenCalledTimes(1);
284+
expect(mockTapPoint.mock.calls[0]?.[0]?.point).toEqual({ x: 540, y: 1356 });
285+
expect(session.pendingInteractionOutcome).toBeUndefined();
286+
expect(session.postGestureStabilization).toBeUndefined();
287+
});
288+
289+
test('captureSnapshot composes post-gesture stabilization with Android freshness capture', async () => {
290+
const sessionName = 'android-post-gesture-freshness';
291+
const baselineNodes = inboxBaselineNodes(18);
292+
const changedNodes = buildNodes(
293+
androidTextRows(18, (row) => (row === 1 ? 'album-0' : `Album row ${row}`)),
294+
);
295+
const session = makeAndroidFreshnessSession(sessionName, 'click', baselineNodes);
296+
session.postGestureStabilization = {
297+
action: 'click',
298+
positionals: [],
299+
markedAt: Date.now(),
300+
};
301+
302+
legacyDispatchCapture
303+
.mockResolvedValueOnce(androidCapture(baselineNodes, { rawNodeCount: 18, maxDepth: 1 }))
304+
.mockResolvedValueOnce(androidCapture(changedNodes, { rawNodeCount: 18, maxDepth: 1 }))
305+
.mockResolvedValueOnce(androidCapture(changedNodes, { rawNodeCount: 18, maxDepth: 1 }));
306+
307+
const result = await captureSnapshot({
308+
device: androidDevice,
309+
session,
310+
flags: { snapshotInteractiveOnly: true },
311+
logPath: '/tmp/daemon.log',
312+
});
313+
314+
expect(result.snapshot.nodes).toEqual(
315+
expect.arrayContaining([expect.objectContaining({ label: 'album-0' })]),
316+
);
317+
expect(legacyDispatchCapture.mock.calls.map((call) => call[1])).toEqual([
318+
'snapshot',
319+
'snapshot',
320+
'snapshot',
321+
]);
322+
expect(session.androidSnapshotFreshness).toBeUndefined();
323+
expect(session.postGestureStabilization).toBeUndefined();
324+
});
325+
326+
test('captureSnapshot composes pending outcome retry with Android freshness capture', async () => {
327+
const sessionName = 'android-lazy-outcome-freshness';
328+
const baselineNodes = inboxBaselineNodes(18);
329+
const session = makeAndroidFreshnessSession(sessionName, 'click', baselineNodes);
330+
session.pendingInteractionOutcome = {
331+
action: 'click',
332+
command: 'press',
333+
positionals: ['180', '330'],
334+
flags: { platform: 'android' },
335+
markedAt: Date.now(),
336+
attemptsRemaining: 2,
337+
preSignature: buildInteractionSurfaceSignature(baselineNodes),
338+
};
339+
340+
legacyDispatchCapture
341+
.mockResolvedValueOnce(androidCapture([], { rawNodeCount: 18, maxDepth: 1 }))
342+
.mockResolvedValueOnce(
343+
androidCapture(
344+
[
345+
{
346+
index: 0,
347+
depth: 0,
348+
type: 'android.widget.Button',
349+
label: 'Create document',
350+
hittable: true,
351+
},
352+
],
353+
{ rawNodeCount: 1, maxDepth: 0 },
354+
),
355+
);
356+
357+
const result = await captureSnapshot({
358+
device: androidDevice,
359+
session,
360+
flags: { snapshotInteractiveOnly: true },
361+
logPath: '/tmp/daemon.log',
362+
});
363+
364+
expect(result.snapshot.nodes).toEqual(
365+
expect.arrayContaining([expect.objectContaining({ label: 'Create document' })]),
366+
);
367+
expect(result.freshness).toEqual({
368+
action: 'click',
369+
retryCount: 1,
370+
staleAfterRetries: false,
371+
reason: undefined,
372+
});
373+
expect(legacyDispatchCapture.mock.calls.map((call) => call[1])).toEqual(['snapshot', 'snapshot']);
374+
expect(session.pendingInteractionOutcome).toBeUndefined();
375+
expect(session.androidSnapshotFreshness).toBeUndefined();
376+
});

0 commit comments

Comments
 (0)