Skip to content

Commit b491ede

Browse files
committed
fix(record): surface iOS runner stop failures
1 parent 6e1e90d commit b491ede

3 files changed

Lines changed: 192 additions & 156 deletions

File tree

‎src/daemon/handlers/__tests__/record-trace.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ test('record start does not stop recording owned by another session during desyn
802802
expect(sessionStore.get(ownerSessionName)?.recording?.platform).toBe('ios-device-runner');
803803
});
804804

805-
test('record stop clears iOS runner recording state when runner stop fails', async () => {
805+
test('record stop reports iOS runner stop failure after copying and clears recording state', async () => {
806806
const sessionStore = makeSessionStore();
807807
const sessionName = 'ios-device-stop-fail';
808808
sessionStore.set(sessionName, {
@@ -835,8 +835,9 @@ test('record stop clears iOS runner recording state when runner stop fails', asy
835835
positionals: ['stop'],
836836
});
837837

838-
expect(response?.ok).toBe(true);
839-
expect((response as any).data?.recording).toBe('stopped');
838+
expect(response?.ok).toBe(false);
839+
expect((response as any).error?.code).toBe('COMMAND_FAILED');
840+
expect((response as any).error?.message).toMatch(/runner reported recordStop did not succeed/);
840841
expect(runCmdCalls.length).toBe(1);
841842
expect(sessionStore.get(sessionName)?.recording).toBeUndefined();
842843
});

‎src/daemon/handlers/record-trace-ios.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function stopRunnerRecordingBestEffort(params: {
6565
device: SessionState['device'];
6666
logPath?: string;
6767
deps: RecordTraceDeps;
68-
}): Promise<void> {
68+
}): Promise<boolean> {
6969
const { req, activeSession, device, logPath, deps } = params;
7070
const appBundleId = normalizeAppBundleId(activeSession);
7171

@@ -75,6 +75,7 @@ async function stopRunnerRecordingBestEffort(params: {
7575
{ command: 'recordStop', appBundleId },
7676
getIosRunnerOptions(req, logPath, activeSession),
7777
);
78+
return true;
7879
} catch (error) {
7980
emitDiagnostic({
8081
level: 'warn',
@@ -87,6 +88,7 @@ async function stopRunnerRecordingBestEffort(params: {
8788
error: formatRecordTraceError(error),
8889
},
8990
});
91+
return false;
9092
}
9193
}
9294

@@ -318,7 +320,13 @@ export async function stopIosDeviceRecording(params: {
318320
recording: Extract<NonNullable<SessionState['recording']>, { platform: 'ios-device-runner' }>;
319321
}): Promise<DaemonResponse | null> {
320322
const { req, activeSession, device, logPath, deps, recording } = params;
321-
await stopRunnerRecordingBestEffort({ req, activeSession, device, logPath, deps });
323+
const runnerStopOk = await stopRunnerRecordingBestEffort({
324+
req,
325+
activeSession,
326+
device,
327+
logPath,
328+
deps,
329+
});
322330

323331
let copyResult = { stdout: '', stderr: '', exitCode: 1 };
324332
for (const bundleId of IOS_RUNNER_CONTAINER_BUNDLE_IDS) {
@@ -363,6 +371,12 @@ export async function stopIosDeviceRecording(params: {
363371
`failed to stop recording: ${recording.outPath} was not finalized into a playable video`,
364372
);
365373
}
374+
if (!runnerStopOk) {
375+
return errorResponse(
376+
'COMMAND_FAILED',
377+
'failed to stop recording: the iOS runner reported recordStop did not succeed',
378+
);
379+
}
366380

367381
const trimStartMs = resolveIosRecordingTrimStartMs(recording);
368382
if (trimStartMs > 0) {

0 commit comments

Comments
 (0)