Skip to content

Commit 9cf294b

Browse files
committed
test: simplify selector replay regression
1 parent e93c795 commit 9cf294b

5 files changed

Lines changed: 68 additions & 217 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import path from 'node:path';
2+
import { beforeEach, expect, test, vi } from 'vitest';
3+
4+
import { makeIosSession } from '../../../__tests__/test-utils/session-factories.ts';
5+
import { mkdtempForTestSync } from '../../../__tests__/test-utils/tmp-dir.ts';
6+
import { dispatchCommand } from '../../../core/dispatch.ts';
7+
import { SessionStore } from '../../session-store.ts';
8+
import { runReplayScriptFile } from '../session-replay-runtime.ts';
9+
import { baseReplayRequest, writeReplayFile } from './session-replay-runtime.fixtures.ts';
10+
11+
vi.mock('../../../core/dispatch.ts', async (importOriginal) => {
12+
const actual = await importOriginal<typeof import('../../../core/dispatch.ts')>();
13+
return { ...actual, dispatchCommand: vi.fn(), resolveTargetDevice: vi.fn() };
14+
});
15+
16+
const mockDispatchCommand = vi.mocked(dispatchCommand);
17+
18+
beforeEach(() => {
19+
mockDispatchCommand.mockReset();
20+
mockDispatchCommand.mockRejectedValue(new Error('no device runner available'));
21+
});
22+
23+
test('replay executes selector reads before reporting a covered-target divergence', async () => {
24+
const root = mkdtempForTestSync('agent-device-replay-selector-routes-');
25+
const sessionName = 'default';
26+
const sessionStore = new SessionStore(path.join(root, 'sessions'));
27+
sessionStore.set(sessionName, makeIosSession(sessionName));
28+
const filePath = writeReplayFile(root, [
29+
'open "Demo"',
30+
'get text "id=\\"field-name\\""',
31+
'get attrs "id=\\"field-name\\""',
32+
'is visible "id=\\"field-name\\""',
33+
'find id "field-name" get attrs',
34+
'click "id=\\"field-name\\""',
35+
]);
36+
const invoked: string[] = [];
37+
38+
const response = await runReplayScriptFile({
39+
req: baseReplayRequest({ positionals: [filePath] }),
40+
sessionName,
41+
logPath: path.join(root, 'daemon.log'),
42+
sessionStore,
43+
invoke: async (request) => {
44+
invoked.push(request.command);
45+
if (request.command !== 'click') return { ok: true, data: {} };
46+
return {
47+
ok: false,
48+
error: {
49+
code: 'COMMAND_FAILED',
50+
message: 'Target is covered by another visible element',
51+
},
52+
};
53+
},
54+
});
55+
56+
expect(invoked).toEqual(['open', 'get', 'get', 'is', 'find', 'click']);
57+
expect(response.ok).toBe(false);
58+
if (response.ok) return;
59+
expect(response.error.code).toBe('REPLAY_DIVERGENCE');
60+
expect(response.error.details?.divergence).toMatchObject({
61+
kind: 'action-failure',
62+
step: { index: 6 },
63+
cause: {
64+
code: 'COMMAND_FAILED',
65+
message: 'Target is covered by another visible element',
66+
},
67+
});
68+
});

test/integration/android-emulator-e2e/live-replay-scenarios.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
replayAttemptTimeoutMs,
1616
} from '../live-device-e2e/replay-evidence.ts';
1717
import { runLiveReplayTestSuite } from '../live-device-e2e/replay-suite.ts';
18-
import { assertSelectorRouteReplay } from '../live-device-e2e/selector-route-replay.ts';
1918

2019
const C = PUBLIC_COMMANDS;
2120

@@ -98,39 +97,4 @@ export async function assertFixtureReplays(context: LiveContext): Promise<void>
9897
'helper-backed-gesture-recovery',
9998
'gesture fixture observed two-pointer pan, fling, pinch, rotate, and transform outcomes',
10099
);
101-
102-
await assertSelectorRouteReplay(
103-
context,
104-
path.resolve(
105-
'test/integration/replays/android/fixture/02-selector-routes-covered-diagnosis.ad',
106-
),
107-
runStep,
108-
{
109-
postReplayCleanup: [
110-
{
111-
step: 'open Android cleanup session after focused selector-route replay',
112-
args: [
113-
'open',
114-
'settings',
115-
'--platform',
116-
'android',
117-
'--serial',
118-
context.serial,
119-
'--session',
120-
`${context.session}-cleanup`,
121-
'--no-test-ime',
122-
'--json',
123-
],
124-
},
125-
{
126-
step: 'restore portrait after focused selector-route replay',
127-
args: ['orientation', 'portrait', '--session', `${context.session}-cleanup`, '--json'],
128-
},
129-
{
130-
step: 'close Android cleanup session after focused selector-route replay',
131-
args: ['close', '--session', `${context.session}-cleanup`, '--json'],
132-
},
133-
],
134-
},
135-
);
136100
}

test/integration/ios-simulator-e2e/live-replay-scenarios.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
replayAttemptTimeoutMs,
1616
} from '../live-device-e2e/replay-evidence.ts';
1717
import { runLiveReplayTestSuite } from '../live-device-e2e/replay-suite.ts';
18-
import { assertSelectorRouteReplay } from '../live-device-e2e/selector-route-replay.ts';
1918

2019
const C = PUBLIC_COMMANDS;
2120

@@ -76,41 +75,4 @@ export async function assertFixtureReplays(context: LiveContext): Promise<void>
7675
'gesture fixture counters prove pan/fling/pinch/rotate/transform',
7776
);
7877
verifyCommand(context, C.test, 'fixture scripts pass as a suite and emit non-empty JUnit');
79-
80-
await assertSelectorRouteReplay(
81-
context,
82-
path.resolve('test/integration/replays/ios/fixture/03-selector-routes-covered-diagnosis.ad'),
83-
runStep,
84-
{
85-
postReplayCleanup: [
86-
{
87-
step: 'open iOS cleanup session after focused selector-route replay',
88-
args: [
89-
'open',
90-
context.appId,
91-
'--platform',
92-
'ios',
93-
'--udid',
94-
context.udid,
95-
'--session',
96-
`${context.session}-cleanup`,
97-
'--state-dir',
98-
context.stateDir,
99-
'--json',
100-
],
101-
},
102-
{
103-
step: 'close iOS cleanup session after focused selector-route replay',
104-
args: [
105-
'close',
106-
'--session',
107-
`${context.session}-cleanup`,
108-
'--state-dir',
109-
context.stateDir,
110-
'--json',
111-
],
112-
},
113-
],
114-
},
115-
);
11678
}

test/integration/live-device-e2e/selector-route-replay.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

test/integration/selector-route-replay-coverage.test.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)