test(coding-agent): flush immediate before asserting tiny-title prewarm

Re-applies the race fix from 7b21716754 that 563f00fe31 dropped as
'unrelated': InteractiveMode.init() defers the prewarm behind setImmediate,
and init()'s own awaits are microtasks that can resolve without yielding to
the immediate queue, so asserting right after await init() races under CI's
chunked load. Flush one immediate tick before asserting.
This commit is contained in:
Slava Zavadsky
2026-08-08 13:50:10 -04:00
parent 45e12e5bb7
commit 9dc734ce2c
@@ -87,6 +87,14 @@ 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.
const immediateFlushed = Promise.withResolvers<void>();
setImmediate(immediateFlushed.resolve);
await immediateFlushed.promise;
expect(prewarm).toHaveBeenCalledWith("lfm2-350m");
});