Skip to content

Commit 08f33d6

Browse files
committed
test(apple-runner): drive root recording requests from a dedicated golden file
The request-literal guard scans every fixture producer, so root behavior tests that doubled as producers had to weaken their exact request assertions. Move the root recording drives into src/__tests__/screen-recording-runner-requests.test.ts, restore the original literals, and pin the recordStop sent without an app bundle. Producers must now be *runner-requests.test.ts files that call assertProducedRunnerRequests(import.meta.filename, ...), so a comment no longer satisfies the check. The runner-internal drive moves to runner/__tests__/runner-requests.test.ts to follow that rule. Refs #2881
1 parent faf6ee6 commit 08f33d6

7 files changed

Lines changed: 112 additions & 91 deletions

‎contracts/fixtures/runner-requests.json‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
{"name": "ios-device.physical-device-control.terminate", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "terminate", "appBundleId": "com.example.app", "commandId": "<commandId>"}},
44
{"name": "ios-device.physical-device-screenshot.coredevice-file", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "screenshot", "appBundleId": "com.example.app", "fullscreen": true, "inlineScreenshot": false, "commandId": "<commandId>"}},
55
{"name": "ios-device.physical-device-screenshot.xctest-inline", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "screenshot", "appBundleId": "com.example.app", "inlineScreenshot": true, "commandId": "<commandId>"}},
6-
{"name": "ios-device.recording-start-abort.stop", "producer": "src/platform-runtime-screen-recording-apple-runner-transport.test.ts", "request": {"command": "recordStop", "appBundleId": "com.example.app"}},
7-
{"name": "ios-device.recording-start.fps", "producer": "src/platform-runtime-screen-recording-apple-runner-transport.test.ts", "request": {"command": "recordStart", "outPath": "agent-device-recording-1700000000000.mp4", "fps": 30, "appBundleId": "com.example.app"}},
8-
{"name": "ios-device.recording-stop.session", "producer": "src/platform-runtime-screen-recording-apple-runner-transport.test.ts", "request": {"command": "recordStop", "appBundleId": "com.example.app"}},
6+
{"name": "ios-device.recording-start-abort.stop", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "recordStop", "appBundleId": "com.example.app"}},
7+
{"name": "ios-device.recording-start.fps", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "recordStart", "outPath": "agent-device-recording-1700000000000.mp4", "fps": 30, "appBundleId": "com.example.app"}},
8+
{"name": "ios-device.recording-stop.no-app", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "recordStop"}},
9+
{"name": "ios-device.recording-stop.session", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "recordStop", "appBundleId": "com.example.app"}},
910
{"name": "ios-simulator.alert.accept", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "alert", "action": "accept", "appBundleId": "com.example.app", "timeoutMs": 10000, "commandId": "<commandId>"}},
1011
{"name": "ios-simulator.alert.dismiss", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "alert", "action": "dismiss", "appBundleId": "com.example.app", "timeoutMs": 10000, "commandId": "<commandId>"}},
1112
{"name": "ios-simulator.alert.get", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "alert", "action": "get", "appBundleId": "com.example.app", "timeoutMs": 10000, "commandId": "<commandId>"}},
@@ -41,16 +42,16 @@
4142
{"name": "ios-simulator.interactor-read-text.point", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "readText", "x": 10, "y": 20, "appBundleId": "com.example.app", "commandId": "<commandId>"}},
4243
{"name": "ios-simulator.interactor-set-orientation.rotate", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "rotate", "orientation": "landscape-left", "appBundleId": "com.example.app", "commandId": "<commandId>"}},
4344
{"name": "ios-simulator.interactor-snapshot.every-option", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "snapshot", "appBundleId": "com.example.app", "interactiveOnly": true, "preferredBackend": "tree", "customActions": true, "depth": 3, "scope": "Go", "raw": true, "commandId": "<commandId>"}},
44-
{"name": "ios-simulator.recording-clock-anchor.snapshot", "producer": "src/platform-runtime-screen-recording-apple-runner-host.test.ts", "request": {"command": "snapshot", "appBundleId": "com.example.app", "interactiveOnly": true, "depth": 1}},
45-
{"name": "ios-simulator.recording-start.default", "producer": "src/platform-runtime-screen-recording-apple-runner-transport.test.ts", "request": {"command": "recordStart", "outPath": "capture.mp4", "appBundleId": "com.example.app"}},
46-
{"name": "ios-simulator.runner-adoption.uptime", "producer": "packages/platform-apple/src/runner/__tests__/runner-contract.test.ts", "request": {"command": "uptime", "commandId": "<commandId>"}},
47-
{"name": "ios-simulator.runner-client-prepare.uptime", "producer": "packages/platform-apple/src/runner/__tests__/runner-contract.test.ts", "request": {"command": "uptime", "commandId": "<commandId>"}},
48-
{"name": "ios-simulator.runner-client-target-reset.relaunch", "producer": "packages/platform-apple/src/runner/__tests__/runner-contract.test.ts", "request": {"command": "targetReset", "commandId": "<commandId>"}},
49-
{"name": "ios-simulator.runner-command-recovery.status", "producer": "packages/platform-apple/src/runner/__tests__/runner-contract.test.ts", "request": {"command": "status", "statusCommandId": "<commandId>"}},
50-
{"name": "ios-simulator.runner-disposal.shutdown", "producer": "packages/platform-apple/src/runner/__tests__/runner-contract.test.ts", "request": {"command": "shutdown", "commandId": "<commandId>"}},
51-
{"name": "ios-simulator.runner-lifecycle-prepare.uptime", "producer": "packages/platform-apple/src/runner/__tests__/runner-contract.test.ts", "request": {"command": "uptime", "commandId": "<commandId>"}},
45+
{"name": "ios-simulator.recording-clock-anchor.snapshot", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "snapshot", "appBundleId": "com.example.app", "interactiveOnly": true, "depth": 1}},
46+
{"name": "ios-simulator.recording-start.default", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "recordStart", "outPath": "capture.mp4", "appBundleId": "com.example.app"}},
47+
{"name": "ios-simulator.runner-adoption.uptime", "producer": "packages/platform-apple/src/runner/__tests__/runner-requests.test.ts", "request": {"command": "uptime", "commandId": "<commandId>"}},
48+
{"name": "ios-simulator.runner-client-prepare.uptime", "producer": "packages/platform-apple/src/runner/__tests__/runner-requests.test.ts", "request": {"command": "uptime", "commandId": "<commandId>"}},
49+
{"name": "ios-simulator.runner-client-target-reset.relaunch", "producer": "packages/platform-apple/src/runner/__tests__/runner-requests.test.ts", "request": {"command": "targetReset", "commandId": "<commandId>"}},
50+
{"name": "ios-simulator.runner-command-recovery.status", "producer": "packages/platform-apple/src/runner/__tests__/runner-requests.test.ts", "request": {"command": "status", "statusCommandId": "<commandId>"}},
51+
{"name": "ios-simulator.runner-disposal.shutdown", "producer": "packages/platform-apple/src/runner/__tests__/runner-requests.test.ts", "request": {"command": "shutdown", "commandId": "<commandId>"}},
52+
{"name": "ios-simulator.runner-lifecycle-prepare.uptime", "producer": "packages/platform-apple/src/runner/__tests__/runner-requests.test.ts", "request": {"command": "uptime", "commandId": "<commandId>"}},
5253
{"name": "ios-simulator.runner-selector-query.label", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "querySelector", "selectorKey": "label", "selectorValue": "Go", "appBundleId": "com.example.app", "commandId": "<commandId>"}},
53-
{"name": "ios-simulator.runner-session-readiness.uptime", "producer": "packages/platform-apple/src/runner/__tests__/runner-contract.test.ts", "request": {"command": "uptime", "commandId": "<commandId>"}},
54+
{"name": "ios-simulator.runner-session-readiness.uptime", "producer": "packages/platform-apple/src/runner/__tests__/runner-requests.test.ts", "request": {"command": "uptime", "commandId": "<commandId>"}},
5455
{"name": "macos.desktop-scroll.amount", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "desktopScroll", "direction": "down", "amount": 0.5, "durationMs": 300, "appBundleId": "com.example.app", "commandId": "<commandId>"}},
5556
{"name": "macos.desktop-scroll.pixels", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "desktopScroll", "direction": "up", "pixels": 200, "durationMs": 300, "appBundleId": "com.example.app", "commandId": "<commandId>"}},
5657
{"name": "macos.interactions-drag.single", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "drag", "x": 100, "y": 400, "x2": 100, "y2": 200, "durationMs": 120, "appBundleId": "com.example.app", "commandId": "<commandId>"}},
@@ -59,7 +60,7 @@
5960
{"name": "macos.interactions-mouse-click.secondary", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "mouseClick", "x": 10, "y": 20, "button": "secondary", "appBundleId": "com.example.app", "commandId": "<commandId>"}},
6061
{"name": "macos.interactions-single-press-tap.coordinate", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "tap", "x": 10, "y": 20, "appBundleId": "com.example.app", "commandId": "<commandId>"}},
6162
{"name": "macos.interactions-tap.coordinate", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "tap", "x": 10, "y": 20, "appBundleId": "com.example.app", "commandId": "<commandId>"}},
62-
{"name": "macos.recording-start.output-path", "producer": "src/platform-runtime-screen-recording-apple-runner-transport.test.ts", "request": {"command": "recordStart", "outPath": "/tmp/capture.mp4", "appBundleId": "com.example.app"}},
63+
{"name": "macos.recording-start.output-path", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "recordStart", "outPath": "/tmp/capture.mp4", "appBundleId": "com.example.app"}},
6364
{"name": "macos.screenshot-runner.fullscreen", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "screenshot", "appBundleId": "com.example.app", "fullscreen": true, "inlineScreenshot": false, "commandId": "<commandId>"}},
6465
{"name": "tvos.interactions-scroll.remote-press", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "remotePress", "remoteButton": "down", "durationMs": 300, "appBundleId": "com.example.app", "commandId": "<commandId>"}},
6566
{"name": "tvos.interactions-swipe.single", "producer": "packages/platform-apple/src/__tests__/runner-requests.test.ts", "request": {"command": "swipe", "direction": "up", "appBundleId": "com.example.app", "commandId": "<commandId>"}},

‎packages/platform-apple/src/__tests__/runner-requests.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { mkdtempForTest } from './tmp-dir.ts';
2626

2727
// Every Apple runner request site outside `runner/`, driven through its production entry point and
2828
// pinned to contracts/fixtures/runner-requests.json. The drives never write a request themselves;
29-
// runner/__tests__/runner-contract.test.ts reads this source to keep it that way.
29+
// runner/__tests__/runner-requests.test.ts reads this source to keep it that way.
3030

3131
const APP = 'com.example.app';
3232
const XCTEST_DEVICE: DeviceInfo = { ...IOS_DEVICE, iosPhysicalDeviceBackend: 'xctest' };

packages/platform-apple/src/runner/__tests__/runner-contract.test.ts renamed to packages/platform-apple/src/runner/__tests__/runner-requests.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { executeRunnerCommand, prepareLocalIosRunner } from '../runner-lifecycle
1212
import { withAppleRunnerProvider } from '../runner-provider.ts';
1313
import {
1414
assertProducedRunnerRequests,
15-
compareRunnerRequestNames,
1615
readRunnerRequestFixture,
1716
REPO_ROOT,
1817
} from '../runner-requests.fixtures.ts';
@@ -134,10 +133,7 @@ test('runner-internal request sites build exactly their runner-requests.json ent
134133
test('runner-requests.json has a production request for every runner command', () => {
135134
const entries = readRunnerRequestFixture();
136135
const names = entries.map((entry) => entry.name);
137-
assert.deepEqual(
138-
names,
139-
[...new Set(names)].sort((a, b) => compareRunnerRequestNames({ name: a }, { name: b })),
140-
);
136+
assert.deepEqual(names, [...new Set(names)].sort());
141137
const produced = new Set(entries.map((entry) => entry.request.command));
142138
assert.deepEqual(
143139
Object.keys(RUNNER_COMMAND_TRAITS).filter((name) => !produced.has(name)),
@@ -146,7 +142,11 @@ test('runner-requests.json has a production request for every runner command', (
146142
);
147143
for (const producer of new Set(entries.map((entry) => entry.producer))) {
148144
const source = fs.readFileSync(path.join(REPO_ROOT, producer), 'utf8');
149-
assert.ok(producer.endsWith('.test.ts') && source.includes('runner-requests.json'), producer);
145+
assert.ok(
146+
producer.endsWith('runner-requests.test.ts') &&
147+
source.includes('assertProducedRunnerRequests(import.meta.filename'),
148+
`${producer} must be a dedicated *runner-requests.test.ts drive that checks its own entries`,
149+
);
150150
}
151151
});
152152

‎packages/platform-apple/src/runner/runner-requests.fixtures.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ function wireRunnerRequest(sent: unknown): Record<string, unknown> {
2828
return request;
2929
}
3030

31-
export function compareRunnerRequestNames(
32-
left: Pick<RunnerRequestEntry, 'name'>,
33-
right: Pick<RunnerRequestEntry, 'name'>,
34-
): number {
35-
if (left.name === right.name) return 0;
36-
return left.name < right.name ? -1 : 1;
37-
}
38-
3931
/**
4032
* Pins the requests one producer test captured, by site name, to that producer's fixture entries.
4133
* On a mismatch the diff shows the entries to paste into the fixture.
@@ -47,7 +39,7 @@ export function assertProducedRunnerRequests(
4739
const producer = path.relative(REPO_ROOT, producerFile);
4840
const produced = captured
4941
.map(([name, sent]) => ({ name, producer, request: wireRunnerRequest(sent) }))
50-
.sort(compareRunnerRequestNames);
42+
.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0));
5143
assert.deepEqual(
5244
produced,
5345
readRunnerRequestFixture().filter((entry) => entry.producer === producer),
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { expect, test, vi } from 'vitest';
2+
import { assertProducedRunnerRequests } from '@agent-device/platform-apple/runner/requests-fixtures';
3+
import { captureAppleClockAnchor } from '../platform-runtime-screen-recording-apple-runner-host.ts';
4+
import { resolveAppleRunnerScreenRecordingTransport } from '../platform-runtime-screen-recording-apple-runner-transport.ts';
5+
6+
const runner = vi.hoisted(() => ({ run: vi.fn(), snapshot: vi.fn() }));
7+
8+
vi.mock('@agent-device/platform-apple/runner/operations', () => ({
9+
runAppleRunnerCommand: runner.run,
10+
readRunnerSessionLiveness: runner.snapshot,
11+
}));
12+
13+
const device = {
14+
platform: 'apple' as const,
15+
appleOs: 'ios' as const,
16+
id: 'device',
17+
name: 'iPhone',
18+
kind: 'device' as const,
19+
target: 'mobile' as const,
20+
booted: true,
21+
};
22+
const simulator = { ...device, kind: 'simulator' as const, id: 'sim' };
23+
const macosDevice = {
24+
...device,
25+
appleOs: 'macos' as const,
26+
id: 'host-macos-local',
27+
name: 'Mac',
28+
target: 'desktop' as const,
29+
};
30+
31+
test('screen recording runner requests match their runner-requests.json entries', async () => {
32+
runner.snapshot.mockReturnValue({ sessionId: 'runner-session-1', liveness: 'ready' });
33+
runner.run.mockResolvedValue({});
34+
const transport = resolveAppleRunnerScreenRecordingTransport();
35+
const request = { appBundleId: 'com.example.app', outputPath: '/tmp/capture.mp4' };
36+
37+
vi.setSystemTime(1_700_000_000_000);
38+
try {
39+
await transport.start({ ...request, device, fps: 30 });
40+
} finally {
41+
vi.useRealTimers();
42+
}
43+
await transport.start({ ...request, device: simulator });
44+
await transport.start({ ...request, device: macosDevice });
45+
await transport.stop({
46+
device,
47+
runnerSessionId: 'runner-session-1',
48+
appBundleId: 'com.example.app',
49+
});
50+
await transport.stop({ device, runnerSessionId: 'runner-session-1' });
51+
const controller = new AbortController();
52+
const reason = new Error('cancel after runner acquisition');
53+
runner.snapshot.mockImplementationOnce(() => {
54+
controller.abort(reason);
55+
return { sessionId: 'runner-session-2', liveness: 'ready' };
56+
});
57+
await expect(transport.start({ ...request, device, signal: controller.signal })).rejects.toBe(
58+
reason,
59+
);
60+
await captureAppleClockAnchor(simulator, 'com.example.app');
61+
62+
const sent = runner.run.mock.calls.map((call) => call[1]);
63+
assertProducedRunnerRequests(import.meta.filename, [
64+
['ios-device.recording-start.fps', sent[0]],
65+
['ios-simulator.recording-start.default', sent[1]],
66+
['macos.recording-start.output-path', sent[2]],
67+
['ios-device.recording-stop.session', sent[3]],
68+
['ios-device.recording-stop.no-app', sent[4]],
69+
['ios-device.recording-start-abort.stop', sent[6]],
70+
['ios-simulator.recording-clock-anchor.snapshot', sent[7]],
71+
]);
72+
});

‎src/platform-runtime-screen-recording-apple-runner-host.test.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect, test, vi } from 'vitest';
2-
import { assertProducedRunnerRequests } from '@agent-device/platform-apple/runner/requests-fixtures';
32
import {
43
captureAppleClockAnchor,
54
runAppleRecordingRunner,
@@ -55,12 +54,3 @@ test('focused simulator-only transport never warms a local Apple runner', async
5554
);
5655
expect(runnerClient.run).not.toHaveBeenCalled();
5756
});
58-
59-
test('the clock anchor request matches its runner-requests.json entry', async () => {
60-
runnerClient.run.mockReset();
61-
runnerClient.run.mockResolvedValue({ currentUptimeMs: 1_000 });
62-
await captureAppleClockAnchor(simulator, 'com.example.app');
63-
assertProducedRunnerRequests(import.meta.filename, [
64-
['ios-simulator.recording-clock-anchor.snapshot', runnerClient.run.mock.calls[0]?.[1]],
65-
]);
66-
});

0 commit comments

Comments
 (0)