From 48c3784ca6742d75bd166824ad23683527ce3ef8 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 7 Oct 2026 20:02:15 +0800 Subject: [PATCH] Run the clipboard watch test on fake timers The clipboard watch ends at a Date.now() deadline (40 ms in this test). Under heavy load the event loop can stall long enough for the deadline to pass before the token poll, so the flow falls back to the paste prompt and the test sees the paste token instead of the clipboard one. Fake timers make the window virtual; the assertions are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) --- packages/void/test/unit/email-cli-domain.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/void/test/unit/email-cli-domain.test.ts b/packages/void/test/unit/email-cli-domain.test.ts index 008cfa1f1..9f21f7568 100644 --- a/packages/void/test/unit/email-cli-domain.test.ts +++ b/packages/void/test/unit/email-cli-domain.test.ts @@ -60,6 +60,7 @@ beforeEach(() => { }); afterEach(() => { + vi.useRealTimers(); vi.restoreAllMocks(); vi.unstubAllGlobals(); }); @@ -425,7 +426,12 @@ describe('emailDomainAdd', () => { .mockReturnValueOnce('ghp_ignored') .mockReturnValue(CFUT_TOKEN); const deps = addDeps({ readClipboard }); - await emailDomainAdd(api, 'prj_1', 'acme.com', undefined, deps); + // Fake time keeps the 40 ms watch window from closing on a slow machine + // before the third read; the token arrives on the second 1 ms poll. + vi.useFakeTimers(); + const added = emailDomainAdd(api, 'prj_1', 'acme.com', undefined, deps); + await vi.advanceTimersByTimeAsync(deps.watchTimeoutMs!); + await added; expect(deps.verifyToken).toHaveBeenCalledTimes(1); expect(deps.verifyToken).toHaveBeenCalledWith(CFUT_TOKEN); expect(deps.clearClipboard).toHaveBeenCalledTimes(1);