diff --git a/tests/dashboard.test.ts b/tests/dashboard.test.ts index 9879c8a1..76107e6b 100644 --- a/tests/dashboard.test.ts +++ b/tests/dashboard.test.ts @@ -665,7 +665,12 @@ describe('InteractiveDashboard refresh', () => { }) it('keeps Optimize mounted without a loading frame when auto-refresh fires', async () => { - vi.useFakeTimers() + // The Optimize scan (`o`) does real fs I/O (readdir/stat) that only + // resolves on a real event-loop turn. Leave setImmediate/nextTick/Date + // real (Date stays real so the wait loop below can use a genuine + // wall-clock deadline) and fake only what the 60s auto-refresh + // interval needs. + vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval'] }) const stdin = new PassThrough() as PassThrough & NodeJS.ReadStream const stdout = new PassThrough() as PassThrough & NodeJS.WriteStream stdin.isTTY = true @@ -712,7 +717,15 @@ describe('InteractiveDashboard refresh', () => { expect(activityHeader.indexOf('turns') + 'turns'.length).toBe(activityRow.indexOf('12') + '12'.length) expect(activityHeader.indexOf('1-shot') + '1-shot'.length).toBe(activityRow.indexOf('50%') + '50%'.length) stdin.write('o') - for (let i = 0; i < 20 && !frames.some(frame => frame.includes('Token estimates are approximate.')); i++) { + // The scan does real fs work, so wait on real event-loop turns + // (setImmediate is left un-faked above) rather than counting fake-timer + // hops, bounded by a real wall-clock deadline. + const realDeadline = Date.now() + 10_000 + while (!frames.some(frame => frame.includes('Token estimates are approximate.'))) { + if (Date.now() > realDeadline) { + throw new Error('Timed out waiting for the Optimize scan to render "Token estimates are approximate."') + } + await new Promise(resolve => setImmediate(resolve)) await vi.advanceTimersByTimeAsync(50) } const beforeRefresh = frames.filter(frame => frame.trim()).at(-1) ?? '' @@ -731,5 +744,5 @@ describe('InteractiveDashboard refresh', () => { expect(frame).not.toContain('Loading Today') expect(frame).not.toContain('Scanning Today') - }) + }, 30_000) })