Skip to content

Commit 91bc56d

Browse files
thymikeeclaude
andcommitted
test(daemon): expect a fresh session to be refused on a held device
Two fresh named sessions no longer share one device: the second waits for the holder's request, then gets DEVICE_IN_USE (callstack#4228). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c6edcbb commit 91bc56d

2 files changed

Lines changed: 29 additions & 30 deletions

File tree

‎packages/daemon/src/server/__tests__/request-router-lock-policy.test.ts‎

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ test('direct daemon requests cannot bypass reject lock policy for existing sessi
161161
}
162162
});
163163

164-
test('fresh named sessions with matching explicit serial bind and serialize on the selected device', async () => {
164+
test('a fresh named session with a matching explicit serial waits for the holder, then is refused', async () => {
165165
const sessionStore = makeSessionStore('agent-device-router-lock-');
166166
const dispatchGate = installGatedDispatch();
167167

@@ -218,23 +218,22 @@ test('fresh named sessions with matching explicit serial bind and serialize on t
218218

219219
dispatchGate.releaseNext();
220220

221-
await vi.waitFor(() => {
222-
expect(dispatchGate.order).toEqual([
223-
'start-snapshot-emulator-5554',
224-
'end-snapshot-emulator-5554',
225-
'start-snapshot-emulator-5554',
226-
]);
227-
});
228-
229-
dispatchGate.releaseNext();
230-
231221
const [firstResponse, secondResponse] = await Promise.all([first, second]);
232222

233223
expect(firstResponse.ok).toBe(true);
234-
expect(secondResponse.ok).toBe(true);
235-
expect(dispatchGate.getMaxActive()).toBe(1);
224+
expect(secondResponse).toMatchObject({
225+
ok: false,
226+
error: {
227+
code: 'DEVICE_IN_USE',
228+
details: { session: 'qa-android-a', deviceId: 'emulator-5554' },
229+
},
230+
});
231+
expect(dispatchGate.order).toEqual([
232+
'start-snapshot-emulator-5554',
233+
'end-snapshot-emulator-5554',
234+
]);
236235
expect(sessionStore.get('qa-android-a')?.device.id).toBe('emulator-5554');
237-
expect(sessionStore.get('qa-android-b')?.device.id).toBe('emulator-5554');
236+
expect(sessionStore.get('qa-android-b')).toBeUndefined();
238237
});
239238

240239
test('fresh named sessions with the same name serialize first binding before rejecting another device', async () => {
@@ -316,7 +315,7 @@ test('fresh named sessions with the same name serialize first binding before rej
316315
expect(sessionStore.get('qa-android')?.device.id).toBe('emulator-5554');
317316
});
318317

319-
test('fresh named sessions with only lock platform default serialize on the selected device', async () => {
318+
test('a fresh named session with only a lock platform default waits for the holder, then is refused', async () => {
320319
const sessionStore = makeSessionStore('agent-device-router-lock-');
321320
const dispatchGate = installGatedDispatch();
322321

@@ -369,23 +368,22 @@ test('fresh named sessions with only lock platform default serialize on the sele
369368

370369
dispatchGate.releaseNext();
371370

372-
await vi.waitFor(() => {
373-
expect(dispatchGate.order).toEqual([
374-
'start-snapshot-emulator-5554',
375-
'end-snapshot-emulator-5554',
376-
'start-snapshot-emulator-5554',
377-
]);
378-
});
379-
380-
dispatchGate.releaseNext();
381-
382371
const [firstResponse, secondResponse] = await Promise.all([first, second]);
383372

384373
expect(firstResponse.ok).toBe(true);
385-
expect(secondResponse.ok).toBe(true);
386-
expect(dispatchGate.getMaxActive()).toBe(1);
374+
expect(secondResponse).toMatchObject({
375+
ok: false,
376+
error: {
377+
code: 'DEVICE_IN_USE',
378+
details: { session: 'qa-default-a', deviceId: 'emulator-5554' },
379+
},
380+
});
381+
expect(dispatchGate.order).toEqual([
382+
'start-snapshot-emulator-5554',
383+
'end-snapshot-emulator-5554',
384+
]);
387385
expect(sessionStore.get('qa-default-a')?.device.id).toBe('emulator-5554');
388-
expect(sessionStore.get('qa-default-b')?.device.id).toBe('emulator-5554');
386+
expect(sessionStore.get('qa-default-b')).toBeUndefined();
389387
});
390388

391389
test('fresh named sessions reject incompatible selector combinations before binding', async () => {

‎packages/daemon/src/server/__tests__/request-router-record-runtime-lock.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ vi.mock('../../core/device/device-ready.ts', () => ({
3737
ensureDeviceReady: vi.fn(async () => {}),
3838
}));
3939

40-
test('fresh default-device recording starts serialize before durable admission', async () => {
40+
test('a fresh session record start waits for the holder, then is refused before binding', async () => {
4141
let releaseFirstStart: () => void = () => {};
4242
const firstStartBlocked = new Promise<void>((resolve) => {
4343
releaseFirstStart = resolve;
@@ -68,8 +68,9 @@ test('fresh default-device recording starts serialize before durable admission',
6868
await expect(first).resolves.toMatchObject({ ok: true, data: { recording: 'started' } });
6969
await expect(second).resolves.toMatchObject({
7070
ok: false,
71-
error: { code: 'COMMAND_FAILED', details: { reason: 'cleanup-unconfirmed' } },
71+
error: { code: 'DEVICE_IN_USE', details: { session: 'session-a', deviceId: DEVICE.id } },
7272
});
73+
expect(runtime.bind).toHaveBeenCalledOnce();
7374
expect(runtime.start).toHaveBeenCalledOnce();
7475
});
7576

0 commit comments

Comments
 (0)