Skip to content

Commit bafbb75

Browse files
committed
test(apple): wait for owner lookup before advancing its deadline
1 parent a6a2a7c commit bafbb75

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

‎packages/platform-apple/src/launch-confirmation.test.ts‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,20 @@ test.each([
218218
*/
219219
function wedgedCoreSimulator(
220220
answers: Readonly<Record<string, string>> = {},
221+
onSpawn?: (count: number) => void,
221222
): AppleToolProvider & { spawns: () => number } {
222223
let spawns = 0;
223224
const answered = (key: string): ExecResult | undefined => {
224225
const stdout = answers[key];
225226
if (stdout === undefined) return undefined;
226227
spawns += 1;
228+
onSpawn?.(spawns);
227229
return { stdout, stderr: '', exitCode: 0 } as ExecResult;
228230
};
229231
const hang = async (options?: ExecOptions): Promise<ExecResult> =>
230232
await new Promise((_resolve, reject) => {
231233
spawns += 1;
234+
onSpawn?.(spawns);
232235
if (options?.signal?.aborted) {
233236
reject(options.signal.reason);
234237
return;
@@ -257,14 +260,6 @@ function wedgedCoreSimulator(
257260
};
258261
}
259262

260-
/** Real I/O turns until the provider saw `count` spawns; bounded so a lookup that stops early fails here, not at the test timeout. */
261-
async function untilSpawned(coreSimulator: { spawns: () => number }, count: number): Promise<void> {
262-
for (let turn = 0; turn < 1000 && coreSimulator.spawns() < count; turn += 1) {
263-
await new Promise((resolve) => setImmediate(resolve));
264-
}
265-
expect(coreSimulator.spawns()).toBe(count);
266-
}
267-
268263
const LISTED_APP = JSON.stringify({
269264
'com.example.app': {
270265
ApplicationType: 'User',
@@ -288,7 +283,13 @@ test.each([
288283
vi.mocked(emitDiagnostic).mockClear();
289284
try {
290285
const { interactor, acceptAlert } = confirmationRunner();
291-
const coreSimulator = wedgedCoreSimulator(answers);
286+
let signalLookupStarted: () => void;
287+
const lookupStarted = new Promise<void>((resolve) => {
288+
signalLookupStarted = resolve;
289+
});
290+
const coreSimulator = wedgedCoreSimulator(answers, (count) => {
291+
if (count === 2) signalLookupStarted();
292+
});
292293
let answered: unknown = 'pending';
293294
const answer = withAppleToolProvider(coreSimulator, async () =>
294295
answerSimulatorLaunchConfirmation(
@@ -300,7 +301,13 @@ test.each([
300301
).then((value) => (answered = value)),
301302
);
302303

303-
await untilSpawned(coreSimulator, 2);
304+
await Promise.race([
305+
lookupStarted,
306+
answer.then(() => {
307+
throw new Error('Owner lookup completed before the second command started');
308+
}),
309+
]);
310+
expect(coreSimulator.spawns()).toBe(2);
304311
await vi.advanceTimersByTimeAsync(URL_OWNER_LOOKUP_TIMEOUT_MS + 1);
305312
expect(answered).toEqual({ outcome: 'unreadable', step: 'url-owner' });
306313
await answer;

0 commit comments

Comments
 (0)