Skip to content

Commit f5855a7

Browse files
committed
test(daemon): align teardown fixtures with session metadata
1 parent e567648 commit f5855a7

3 files changed

Lines changed: 49 additions & 14 deletions

File tree

‎packages/daemon/src/sessions/__tests__/session-teardown-resource-order.test.ts‎

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { beforeEach, expect, test, vi } from 'vitest';
22
import { bindTestCommandHost, createTestHostEnvironment } from '@agent-device/test-kit';
3+
import { createDurableResourceEnvelope } from '@agent-device/capture-kit';
4+
import { localRuntimeOwner } from '@agent-device/contracts/platform-runtime';
5+
import { deviceIdentity } from '@agent-device/kernel/device';
36
import {
47
sessionCloseShutdownFixture,
58
type SessionState,
@@ -62,11 +65,50 @@ function sessionWithEveryResource(
6265
sessionStore: ReturnType<typeof makeSessionStore>,
6366
name: string,
6467
): SessionState {
68+
const session = makeIosSimulatorRecordingSession(sessionStore, name);
69+
const device = deviceIdentity(session.device);
70+
const unexpectedHandleUse = (): never => {
71+
throw new Error('Resource handles must be stopped through the mocked finisher seams');
72+
};
73+
const coordinates = {
74+
sessionId: name,
75+
device,
76+
owner: localRuntimeOwner(device.family),
77+
fence: { token: 'teardown-order', generation: 1 },
78+
lifecycle: 'open',
79+
descriptor: { version: 1, body: {} },
80+
} as const;
6581
return {
66-
...makeIosSimulatorRecordingSession(sessionStore, name),
67-
appLog: {} as SessionState['appLog'],
68-
audioProbe: {} as SessionState['audioProbe'],
69-
perfCapture: {} as SessionState['perfCapture'],
82+
...session,
83+
appLog: {
84+
handle: {
85+
inspect: unexpectedHandleUse,
86+
finish: unexpectedHandleUse,
87+
forceCleanup: unexpectedHandleUse,
88+
[Symbol.asyncDispose]: unexpectedHandleUse,
89+
},
90+
envelope: createDurableResourceEnvelope({ ...coordinates, resourceKind: 'app-log' }),
91+
},
92+
audioProbe: {
93+
handle: {
94+
inspect: unexpectedHandleUse,
95+
status: unexpectedHandleUse,
96+
finish: unexpectedHandleUse,
97+
forceCleanup: unexpectedHandleUse,
98+
[Symbol.asyncDispose]: unexpectedHandleUse,
99+
},
100+
envelope: createDurableResourceEnvelope({ ...coordinates, resourceKind: 'audio-probe' }),
101+
},
102+
perfCapture: {
103+
handle: {
104+
inspect: unexpectedHandleUse,
105+
setOutputPath: unexpectedHandleUse,
106+
finish: unexpectedHandleUse,
107+
forceCleanup: unexpectedHandleUse,
108+
[Symbol.asyncDispose]: unexpectedHandleUse,
109+
},
110+
envelope: createDurableResourceEnvelope({ ...coordinates, resourceKind: 'perf-capture' }),
111+
},
70112
};
71113
}
72114

‎packages/daemon/src/sessions/session-lifecycle/internal/__tests__/session-close-shutdown.fixtures.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ function makeIosSimulatorRecordingSession(
144144
name,
145145
options.device ?? {
146146
platform: 'apple',
147+
appleOs: 'ios',
147148
id: 'sim-udid-recording',
148149
name: 'iPhone 15',
149150
kind: 'simulator',

‎packages/daemon/src/sessions/session-teardown.ts‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,8 @@ async function stopSessionSnapshotHelper(
3939
await platformCleanup.stopSnapshotHelper(session.device);
4040
}
4141

42-
// Best-effort mirror of the platform close `session close` dispatches for a web session
43-
// (`shouldDispatchPlatformClose` in
44-
// `daemon/session-lifecycle/internal/session-close.ts`) so a daemon shutdown or expired-session
45-
// reap tells agent-browser to close its fleet immediately instead of leaving it
46-
// for agent-browser's own idle timer (`DEFAULT_AGENT_BROWSER_IDLE_TIMEOUT_MS`). Unlike its
47-
// siblings above, this has no second caller in the ordinary-close path (that path already
48-
// reaches the browser through `dispatchTargetedPlatformClose`), so it stays module-private.
42+
// Shutdown and expiry close the browser here instead of waiting for its idle timer.
43+
// Ordinary close reaches it through dispatchTargetedPlatformClose.
4944
async function stopSessionWebBrowser(params: {
5045
ref: SessionRef;
5146
sessionStore: SessionStore;
@@ -166,9 +161,6 @@ export async function teardownSessionResources(
166161
const platformCleanup = request.platformCleanup;
167162
const steps: SessionCleanupStep[] = [
168163
...sessionResourceStopSteps({ ...request, platformCleanup }),
169-
// Runs after the resource steps above (recording, app-log, audio, perf) so nothing is still
170-
// reading through the browser when it closes, mirroring the ordering `runSessionCloseTeardown`
171-
// uses for an ordinary `session close`: best-effort resources first, platform close after.
172164
{
173165
step: 'web_browser',
174166
run: () =>

0 commit comments

Comments
 (0)