Skip to content

Commit bfd1669

Browse files
committed
fix(ios): serve a simulator recording whose recorder died with its daemon
A simctl reattach answered `missing` as soon as the recorder process was gone, which is the ordinary state after daemon loss, so a retried `record stop` threw `resource-missing` forever even with the recorder's video on disk. The simctl descriptor now carries the caller-facing export coordinates, so a proven-gone recorder whose file still passes the container sniff reattaches as a handle that runs the same stop-and-export sequence the live recording would have run, and discloses the touch overlay whose events did not survive the daemon. A manifest written without those coordinates is answered exactly as it was before, because it cannot name an export it never recorded.
1 parent 45e4c59 commit bfd1669

4 files changed

Lines changed: 506 additions & 51 deletions

File tree

‎packages/platform-apple/src/recording/recovery.test.ts‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { expect, test, vi } from 'vitest';
22
import { localRuntimeOwner } from '@agent-device/contracts/platform-runtime';
3+
import { recordingFileStore } from '@agent-device/capture-kit/recording-artifact-fixtures';
4+
import { nativeRecordingPath } from '@agent-device/capture-kit/recording-stop-sequence';
35
import { createAppleScreenRecordingOperations } from './runtime.ts';
46
import {
57
appleRecordingHost,
68
coreDevice,
79
processIdentity,
810
recordingInput,
11+
recordingOutputPath,
912
simulator,
13+
simulatorRecorderStart,
1014
} from './runtime.fixtures.ts';
1115

1216
test('daemon-loss cleanup distinguishes live, dead, replaced, and corrupt simulator identity', async () => {
@@ -68,6 +72,125 @@ test('daemon-loss cleanup distinguishes live, dead, replaced, and corrupt simula
6872
expect(inspectProcess).not.toHaveBeenCalled();
6973
});
7074

75+
type SimulatorHostOptions = Parameters<typeof appleRecordingHost>[0];
76+
77+
function simulatorHost(
78+
files: ReturnType<typeof recordingFileStore>,
79+
extra: SimulatorHostOptions = {},
80+
) {
81+
return appleRecordingHost({
82+
...extra,
83+
files,
84+
apple: {
85+
...simulatorRecorderStart(),
86+
inspectProcess: async () => 'missing' as const,
87+
...extra.apple,
88+
},
89+
});
90+
}
91+
92+
function recoveryOperations(host: ReturnType<typeof appleRecordingHost>) {
93+
return createAppleScreenRecordingOperations({
94+
host,
95+
device: simulator,
96+
owner: localRuntimeOwner('apple'),
97+
signal: new AbortController().signal,
98+
});
99+
}
100+
101+
async function startSimulatorRecording(
102+
files: ReturnType<typeof recordingFileStore>,
103+
overrides: Parameters<typeof recordingInput>[0] = {},
104+
) {
105+
return await recoveryOperations(simulatorHost(files)).screenRecordingStart(
106+
recordingInput(overrides),
107+
);
108+
}
109+
110+
test('a simulator recording whose recorder died with its daemon exports through the retried stop', async () => {
111+
const files = recordingFileStore();
112+
const started = await startSimulatorRecording(files);
113+
const nativePath = nativeRecordingPath(recordingOutputPath());
114+
115+
const reattached = await recoveryOperations(simulatorHost(files)).screenRecordingReattach({
116+
envelope: started.envelope,
117+
});
118+
expect(reattached).toMatchObject({ status: 'active' });
119+
if (reattached.status !== 'active') throw new Error('expected an exportable recording');
120+
121+
await expect(reattached.handle.finish()).resolves.toMatchObject({
122+
status: 'completed',
123+
result: {
124+
backend: 'simctl recordVideo',
125+
outPath: recordingOutputPath(),
126+
scope: 'device',
127+
stopObservation: { recorder: 'confirmed' },
128+
nativePathDisposition: 'retired',
129+
},
130+
});
131+
expect(files.exists(recordingOutputPath())).toBe(true);
132+
expect(files.exists(nativePath)).toBe(false);
133+
});
134+
135+
test('a recovered export discloses the touch overlay whose events died with the daemon', async () => {
136+
const files = recordingFileStore();
137+
const started = await startSimulatorRecording(files, { showTouches: true });
138+
139+
const reattached = await recoveryOperations(simulatorHost(files)).screenRecordingReattach({
140+
envelope: started.envelope,
141+
});
142+
if (reattached.status !== 'active') throw new Error('expected an exportable recording');
143+
const finished = await reattached.handle.finish();
144+
if (finished.status !== 'completed') throw new Error('expected a completed export');
145+
expect(finished.result.overlayWarning).toContain('overlay unavailable');
146+
});
147+
148+
test('a simulator recording left by a manifest without export coordinates is still a loss', async () => {
149+
const files = recordingFileStore();
150+
const started = await startSimulatorRecording(files);
151+
const { recording: _dropped, ...bodyWithoutCoordinates } = started.envelope.descriptor.body;
152+
153+
await expect(
154+
recoveryOperations(simulatorHost(files)).screenRecordingReattach({
155+
envelope: {
156+
...started.envelope,
157+
descriptor: { ...started.envelope.descriptor, body: bodyWithoutCoordinates },
158+
},
159+
}),
160+
).resolves.toEqual({ status: 'missing' });
161+
});
162+
163+
test('a gone recorder with no readable video left behind is answered as a loss', async () => {
164+
const started = await startSimulatorRecording(recordingFileStore());
165+
166+
await expect(
167+
recoveryOperations(simulatorHost(recordingFileStore())).screenRecordingReattach({
168+
envelope: started.envelope,
169+
}),
170+
).resolves.toEqual({ status: 'missing' });
171+
});
172+
173+
test('unreadable export coordinates refuse reattach before the recorder is probed', async () => {
174+
const files = recordingFileStore();
175+
const started = await startSimulatorRecording(files);
176+
const inspectProcess = vi.fn(async () => 'missing' as const);
177+
178+
await expect(
179+
recoveryOperations(simulatorHost(files, { apple: { inspectProcess } })).screenRecordingReattach(
180+
{
181+
envelope: {
182+
...started.envelope,
183+
descriptor: {
184+
...started.envelope.descriptor,
185+
body: { ...started.envelope.descriptor.body, recording: { outPath: 42 } },
186+
},
187+
},
188+
},
189+
),
190+
).resolves.toMatchObject({ status: 'unreattachable', reason: 'descriptor-invalid' });
191+
expect(inspectProcess).not.toHaveBeenCalled();
192+
});
193+
71194
test('runner recovery never stops a replacement session owner', async () => {
72195
const operations = createAppleScreenRecordingOperations({
73196
host: appleRecordingHost(),

0 commit comments

Comments
 (0)