Skip to content

Commit b097e22

Browse files
committed
test(daemon): decoy session under the bare name for the recording close test
The recording step no longer re-reads the stored session in the teardown; finishSessionScreenRecording already does that by address and returns when there is no recording, so the duplicate lookup was only a second place to mis-address. The recording test stores a second session with its own live recording under the bare name "default": if the step goes back to session.name, close finishes the decoy's recording instead of the addressed one and the test fails on both counts.
1 parent df280ce commit b097e22

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

‎src/daemon/session-lifecycle/internal/__tests__/session-close-cwd-scoped-resources.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,30 @@ test('close finishes the recording of a cwd-scoped session by store address', as
7575
const resourcePath = screenRecordingResourceStore.resolvePath(
7676
sessionStore.resolveSessionDir(ADDRESS),
7777
);
78+
// `--session default` addresses a *different* session stored under the bare name. Give it
79+
// its own live recording so a `currentSession` lookup by `session.name` would finish the
80+
// wrong one instead of falling back to `session` and staying green.
81+
const decoy = makeIosSimulatorRecordingSession(sessionStore, NAME, {
82+
device: { ...IOS_SIM, id: 'decoy-udid', name: 'iPhone 15' },
83+
});
84+
const decoyFinish = recordingFinishMock(decoy);
85+
sessionStore.set(NAME, decoy);
86+
const decoyResourcePath = screenRecordingResourceStore.resolvePath(
87+
sessionStore.resolveSessionDir(NAME),
88+
);
7889

7990
const response = await closeAtAddress(sessionStore);
8091

8192
expect(response?.ok).toBe(true);
8293
expect(finish).toHaveBeenCalledOnce();
8394
expectCompleted(screenRecordingResourceStore, resourcePath);
8495
expect(sessionStore.get(ADDRESS)).toBeUndefined();
96+
// The decoy is untouched: not finished, record still open, session still stored.
97+
expect(decoyFinish).not.toHaveBeenCalled();
98+
const decoyRecord = screenRecordingResourceStore.read(decoyResourcePath);
99+
expect(decoyRecord.status).toBe('decoded');
100+
if (decoyRecord.status === 'decoded') expect(decoyRecord.envelope.lifecycle).toBe('open');
101+
expect(sessionStore.get(NAME)).toBeDefined();
85102
});
86103

87104
test('close stops the app log of a cwd-scoped session by store address', async () => {

‎src/daemon/session-lifecycle/internal/session-close-lifecycle-teardown.ts‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,13 @@ async function stopBestEffortSessionResources(
135135
platformCleanup: PlatformResourceCleanup,
136136
): Promise<void> {
137137
const { address: sessionName, session } = ref;
138-
// Recording overlay finalization needs the Apple runner.
139-
const currentSession = sessionStore.get(sessionName) ?? session;
140-
if (currentSession.screenRecording) {
141-
await attemptCleanup('recording', () =>
142-
finishSessionScreenRecording({
143-
session: currentSession,
144-
sessionName,
145-
sessionStore,
146-
}),
147-
);
148-
}
138+
// Recording overlay finalization needs the Apple runner, so it runs first.
139+
// `finishSessionScreenRecording` re-reads the stored session by address and
140+
// returns when there is no recording; a second lookup here would only be a
141+
// place to mis-address it.
142+
await attemptCleanup('recording', () =>
143+
finishSessionScreenRecording({ session, sessionName, sessionStore }),
144+
);
149145
await attemptCleanup('app_log', () => stopSessionAppLog({ session, sessionName, sessionStore }));
150146
await attemptCleanup('audio_probe', () =>
151147
finishSessionAudioProbe({ session, sessionName, sessionStore }),

0 commit comments

Comments
 (0)