test(interactive-mode): fixed flaky title-prewarm assertion race
CI run 30534203707 job 90843506186 failed: 'prewarms the configured local worker on startup for an unnamed session' expected tinyTitleClient.prewarm to have been called, but it wasn't. InteractiveMode.init() queues the prewarm call behind setImmediate so the spawn syscall never lands ahead of the first render frame. The test asserted immediately after 'await mode.init()' resolved; if init()'s remaining awaits settle on already-resolved promises (microtasks only), the event loop never reaches the check phase before the assertion runs, so the immediate can still be pending. Flushes one setImmediate tick before asserting, matching the flushMicrotasks pattern already used in rpc-input-frame.test.ts and the tui package's render-scheduler tests. Did not reproduce the failure locally (5/5 passes before and after, run in isolation) — consistent with a timing race that only surfaces under CI's parallel chunked load. The fix removes the race regardless of whether it reproduces locally: the assertion no longer depends on scheduling luck.
This commit is contained in:
@@ -87,6 +87,12 @@ describe("InteractiveMode tiny-title prewarm", () => {
|
||||
const prewarm = vi.spyOn(tinyTitleClient, "prewarm").mockImplementation(() => {});
|
||||
|
||||
await mode.init();
|
||||
// The prewarm call is deferred behind a setImmediate queued during
|
||||
// init() (see interactive-mode.ts); init()'s own awaits are promise
|
||||
// microtasks that can resolve without yielding to the immediate
|
||||
// queue, so the prewarm may not have fired yet when init() settles.
|
||||
// Flush one immediate tick before asserting.
|
||||
await new Promise<void>(resolve => setImmediate(resolve));
|
||||
|
||||
expect(prewarm).toHaveBeenCalledWith("lfm2-350m");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user