Repository navigation
test(apple): wait for the owner lookup's spawns by event, not a turn count #4244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,17 +218,20 @@ | |
| */ | ||
| function wedgedCoreSimulator( | ||
| answers: Readonly<Record<string, string>> = {}, | ||
| onSpawn?: (count: number) => void, | ||
| ): AppleToolProvider & { spawns: () => number } { | ||
| let spawns = 0; | ||
| const answered = (key: string): ExecResult | undefined => { | ||
| const stdout = answers[key]; | ||
| if (stdout === undefined) return undefined; | ||
| spawns += 1; | ||
| onSpawn?.(spawns); | ||
| return { stdout, stderr: '', exitCode: 0 } as ExecResult; | ||
| }; | ||
| const hang = async (options?: ExecOptions): Promise<ExecResult> => | ||
| await new Promise((_resolve, reject) => { | ||
| spawns += 1; | ||
| onSpawn?.(spawns); | ||
| if (options?.signal?.aborted) { | ||
| reject(options.signal.reason); | ||
| return; | ||
|
|
@@ -257,14 +260,6 @@ | |
| }; | ||
| } | ||
|
|
||
| /** Real I/O turns until the provider saw `count` spawns; bounded so a lookup that stops early fails here, not at the test timeout. */ | ||
| async function untilSpawned(coreSimulator: { spawns: () => number }, count: number): Promise<void> { | ||
| for (let turn = 0; turn < 1000 && coreSimulator.spawns() < count; turn += 1) { | ||
| await new Promise((resolve) => setImmediate(resolve)); | ||
| } | ||
| expect(coreSimulator.spawns()).toBe(count); | ||
| } | ||
|
|
||
| const LISTED_APP = JSON.stringify({ | ||
| 'com.example.app': { | ||
| ApplicationType: 'User', | ||
|
|
@@ -288,7 +283,13 @@ | |
| vi.mocked(emitDiagnostic).mockClear(); | ||
| try { | ||
| const { interactor, acceptAlert } = confirmationRunner(); | ||
| const coreSimulator = wedgedCoreSimulator(answers); | ||
| let signalLookupStarted: () => void; | ||
| const lookupStarted = new Promise<void>((resolve) => { | ||
| signalLookupStarted = resolve; | ||
| }); | ||
| const coreSimulator = wedgedCoreSimulator(answers, (count) => { | ||
| if (count === 2) signalLookupStarted(); | ||
| }); | ||
| let answered: unknown = 'pending'; | ||
| const answer = withAppleToolProvider(coreSimulator, async () => | ||
| answerSimulatorLaunchConfirmation( | ||
|
|
@@ -297,10 +298,16 @@ | |
| Promise.resolve(interactor), | ||
| new AbortController().signal, | ||
| undefined, | ||
| ).then((value) => (answered = value)), | ||
| ); | ||
|
|
||
| await untilSpawned(coreSimulator, 2); | ||
| await Promise.race([ | ||
| lookupStarted, | ||
| answer.then(() => { | ||
| throw new Error('Owner lookup completed before the second command started'); | ||
| }), | ||
| ]); | ||
|
Check warning on line 309 in packages/platform-apple/src/launch-confirmation.test.ts
|
||
|
Comment on lines
301
to
+309
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Minor · Lookup that never spawns the second command now hangs to the test timeout When the owner lookup never spawns the second command ( Suggested change Keep a bounded wait so the never-spawned case reports the spawn count: race lookupStarted against answer and a timeout that asserts coreSimulator.spawns(), so a CI flake fails with "expected 0 to be 2" rather than the harness timeout. DetailsAlso raised hereAlso raised at this location by persona Also raised at this location by persona persona: Reply Useful? Reply |
||
| expect(coreSimulator.spawns()).toBe(2); | ||
| await vi.advanceTimersByTimeAsync(URL_OWNER_LOOKUP_TIMEOUT_MS + 1); | ||
| expect(answered).toEqual({ outcome: 'unreadable', step: 'url-owner' }); | ||
| await answer; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This race has no bounded fallback when the lookup stalls before its second spawn. Because the lookup timeout is not armed until that spawn, a delayed filesystem operation can hold the test until Vitest’s global timeout instead of failing fast; retain a bounded pre-spawn fallback.
Prompt for AI agents