Skip to content

Commit 87f212b

Browse files
committed
test: align lock policy probes with ios snapshot guard
1 parent 3930691 commit 87f212b

1 file changed

Lines changed: 57 additions & 40 deletions

File tree

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

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ function makeIosSession(name: string): SessionState {
3939
};
4040
}
4141

42+
function makeAndroidSession(name: string, id = 'emulator-5554'): SessionState {
43+
return {
44+
name,
45+
createdAt: Date.now(),
46+
actions: [],
47+
device: {
48+
platform: 'android',
49+
target: 'mobile',
50+
id,
51+
name: id === 'emulator-5554' ? 'Pixel 9 Pro XL' : 'Pixel 8',
52+
kind: 'emulator',
53+
booted: true,
54+
},
55+
};
56+
}
57+
4258
beforeEach(() => {
4359
mockDispatch.mockReset();
4460
mockDispatch.mockResolvedValue({ nodes: [] });
@@ -112,7 +128,7 @@ test('direct daemon requests cannot bypass reject lock policy for existing sessi
112128
}
113129
});
114130

115-
test('fresh named sessions with matching explicit udid bind and serialize on the selected device', async () => {
131+
test('fresh named sessions with matching explicit serial bind and serialize on the selected device', async () => {
116132
const sessionStore = makeSessionStore('agent-device-router-lock-');
117133
const dispatchGate = installGatedDispatch();
118134

@@ -121,54 +137,54 @@ test('fresh named sessions with matching explicit udid bind and serialize on the
121137
token: 'test-token',
122138
sessionStore,
123139
leaseRegistry: new LeaseRegistry(),
124-
deviceInventoryProvider: async () => [makeIosSession('inventory').device],
140+
deviceInventoryProvider: async () => [makeAndroidSession('inventory').device],
125141
trackDownloadableArtifact: () => 'artifact-id',
126142
});
127143

128144
const first = handler({
129145
token: 'test-token',
130-
session: 'qa-ios-a',
146+
session: 'qa-android-a',
131147
command: 'snapshot',
132148
positionals: [],
133149
flags: {
134-
udid: 'SIM-001',
150+
serial: 'emulator-5554',
135151
},
136152
meta: {
137153
requestId: 'req-fresh-lock-a',
138154
lockPolicy: 'reject',
139-
lockPlatform: 'ios',
155+
lockPlatform: 'android',
140156
},
141157
});
142158

143159
await vi.waitFor(() => {
144-
expect(dispatchGate.order).toEqual(['start-snapshot-SIM-001']);
160+
expect(dispatchGate.order).toEqual(['start-snapshot-emulator-5554']);
145161
});
146162

147163
const second = handler({
148164
token: 'test-token',
149-
session: 'qa-ios-b',
165+
session: 'qa-android-b',
150166
command: 'snapshot',
151167
positionals: [],
152168
flags: {
153-
udid: 'SIM-001',
169+
serial: 'emulator-5554',
154170
},
155171
meta: {
156172
requestId: 'req-fresh-lock-b',
157173
lockPolicy: 'reject',
158-
lockPlatform: 'ios',
174+
lockPlatform: 'android',
159175
},
160176
});
161177

162178
await new Promise((resolve) => setTimeout(resolve, 20));
163-
expect(dispatchGate.order).toEqual(['start-snapshot-SIM-001']);
179+
expect(dispatchGate.order).toEqual(['start-snapshot-emulator-5554']);
164180

165181
dispatchGate.releaseNext();
166182

167183
await vi.waitFor(() => {
168184
expect(dispatchGate.order).toEqual([
169-
'start-snapshot-SIM-001',
170-
'end-snapshot-SIM-001',
171-
'start-snapshot-SIM-001',
185+
'start-snapshot-emulator-5554',
186+
'end-snapshot-emulator-5554',
187+
'start-snapshot-emulator-5554',
172188
]);
173189
});
174190

@@ -179,17 +195,15 @@ test('fresh named sessions with matching explicit udid bind and serialize on the
179195
expect(firstResponse.ok).toBe(true);
180196
expect(secondResponse.ok).toBe(true);
181197
expect(dispatchGate.getMaxActive()).toBe(1);
182-
expect(sessionStore.get('qa-ios-a')?.device.id).toBe('SIM-001');
183-
expect(sessionStore.get('qa-ios-b')?.device.id).toBe('SIM-001');
198+
expect(sessionStore.get('qa-android-a')?.device.id).toBe('emulator-5554');
199+
expect(sessionStore.get('qa-android-b')?.device.id).toBe('emulator-5554');
184200
});
185201

186202
test('fresh named sessions with the same name serialize first binding before rejecting another device', async () => {
187203
const sessionStore = makeSessionStore('agent-device-router-lock-');
188-
const firstDevice = makeIosSession('inventory').device;
204+
const firstDevice = makeAndroidSession('inventory').device;
189205
const secondDevice: SessionState['device'] = {
190-
...firstDevice,
191-
id: 'SIM-002',
192-
name: 'iPhone 17',
206+
...makeAndroidSession('inventory-2', 'emulator-5556').device,
193207
};
194208
const dispatchGate = installGatedDispatch();
195209

@@ -204,40 +218,40 @@ test('fresh named sessions with the same name serialize first binding before rej
204218

205219
const first = handler({
206220
token: 'test-token',
207-
session: 'qa-ios',
221+
session: 'qa-android',
208222
command: 'snapshot',
209223
positionals: [],
210224
flags: {
211-
udid: 'SIM-001',
225+
serial: 'emulator-5554',
212226
},
213227
meta: {
214228
requestId: 'req-fresh-same-session-a',
215229
lockPolicy: 'reject',
216-
lockPlatform: 'ios',
230+
lockPlatform: 'android',
217231
},
218232
});
219233

220234
await vi.waitFor(() => {
221-
expect(dispatchGate.order).toEqual(['start-snapshot-SIM-001']);
235+
expect(dispatchGate.order).toEqual(['start-snapshot-emulator-5554']);
222236
});
223237

224238
const second = handler({
225239
token: 'test-token',
226-
session: 'qa-ios',
240+
session: 'qa-android',
227241
command: 'snapshot',
228242
positionals: [],
229243
flags: {
230-
udid: 'SIM-002',
244+
serial: 'emulator-5556',
231245
},
232246
meta: {
233247
requestId: 'req-fresh-same-session-b',
234248
lockPolicy: 'reject',
235-
lockPlatform: 'ios',
249+
lockPlatform: 'android',
236250
},
237251
});
238252

239253
await new Promise((resolve) => setTimeout(resolve, 20));
240-
expect(dispatchGate.order).toEqual(['start-snapshot-SIM-001']);
254+
expect(dispatchGate.order).toEqual(['start-snapshot-emulator-5554']);
241255

242256
dispatchGate.releaseNext();
243257

@@ -247,12 +261,15 @@ test('fresh named sessions with the same name serialize first binding before rej
247261
expect(secondResponse.ok).toBe(false);
248262
if (!secondResponse.ok) {
249263
expect(secondResponse.error.code).toBe('INVALID_ARGS');
250-
expect(secondResponse.error.message).toMatch(/--udid=SIM-002/i);
264+
expect(secondResponse.error.message).toMatch(/--serial=emulator-5556/i);
251265
}
252-
expect(dispatchGate.order).toEqual(['start-snapshot-SIM-001', 'end-snapshot-SIM-001']);
266+
expect(dispatchGate.order).toEqual([
267+
'start-snapshot-emulator-5554',
268+
'end-snapshot-emulator-5554',
269+
]);
253270
expect(dispatchGate.getMaxActive()).toBe(1);
254271
expect(mockDispatch).toHaveBeenCalledTimes(1);
255-
expect(sessionStore.get('qa-ios')?.device.id).toBe('SIM-001');
272+
expect(sessionStore.get('qa-android')?.device.id).toBe('emulator-5554');
256273
});
257274

258275
test('fresh named sessions with only lock platform default serialize on the selected device', async () => {
@@ -264,7 +281,7 @@ test('fresh named sessions with only lock platform default serialize on the sele
264281
token: 'test-token',
265282
sessionStore,
266283
leaseRegistry: new LeaseRegistry(),
267-
deviceInventoryProvider: async () => [makeIosSession('inventory').device],
284+
deviceInventoryProvider: async () => [makeAndroidSession('inventory').device],
268285
trackDownloadableArtifact: () => 'artifact-id',
269286
});
270287

@@ -277,12 +294,12 @@ test('fresh named sessions with only lock platform default serialize on the sele
277294
meta: {
278295
requestId: 'req-fresh-default-lock-a',
279296
lockPolicy: 'reject',
280-
lockPlatform: 'ios',
297+
lockPlatform: 'android',
281298
},
282299
});
283300

284301
await vi.waitFor(() => {
285-
expect(dispatchGate.order).toEqual(['start-snapshot-SIM-001']);
302+
expect(dispatchGate.order).toEqual(['start-snapshot-emulator-5554']);
286303
});
287304

288305
const second = handler({
@@ -294,20 +311,20 @@ test('fresh named sessions with only lock platform default serialize on the sele
294311
meta: {
295312
requestId: 'req-fresh-default-lock-b',
296313
lockPolicy: 'reject',
297-
lockPlatform: 'ios',
314+
lockPlatform: 'android',
298315
},
299316
});
300317

301318
await new Promise((resolve) => setTimeout(resolve, 20));
302-
expect(dispatchGate.order).toEqual(['start-snapshot-SIM-001']);
319+
expect(dispatchGate.order).toEqual(['start-snapshot-emulator-5554']);
303320

304321
dispatchGate.releaseNext();
305322

306323
await vi.waitFor(() => {
307324
expect(dispatchGate.order).toEqual([
308-
'start-snapshot-SIM-001',
309-
'end-snapshot-SIM-001',
310-
'start-snapshot-SIM-001',
325+
'start-snapshot-emulator-5554',
326+
'end-snapshot-emulator-5554',
327+
'start-snapshot-emulator-5554',
311328
]);
312329
});
313330

@@ -318,8 +335,8 @@ test('fresh named sessions with only lock platform default serialize on the sele
318335
expect(firstResponse.ok).toBe(true);
319336
expect(secondResponse.ok).toBe(true);
320337
expect(dispatchGate.getMaxActive()).toBe(1);
321-
expect(sessionStore.get('qa-default-a')?.device.id).toBe('SIM-001');
322-
expect(sessionStore.get('qa-default-b')?.device.id).toBe('SIM-001');
338+
expect(sessionStore.get('qa-default-a')?.device.id).toBe('emulator-5554');
339+
expect(sessionStore.get('qa-default-b')?.device.id).toBe('emulator-5554');
323340
});
324341

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

0 commit comments

Comments
 (0)