From 8570ed13fd5534de0af1096a0dbbed024b5a227b Mon Sep 17 00:00:00 2001 From: Artem Rootman <4586640+artemrootman@users.noreply.github.com> Date: Sun, 5 Apr 2026 18:25:43 +0000 Subject: [PATCH] fix: stabilize flaky ChangeExtractorService invalidation test The test races stale and fresh worker calls to verify that invalidation prevents stale results from populating the cache. On slow CI, the fresh worker mock could be reached before the stale deferred was resolved, causing the version guard to mismatch. Flush microtasks after starting freshPromise so it advances past internal awaits and reaches the worker mock before we resolve the stale deferred. --- test/main/services/team/ChangeExtractorService.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/main/services/team/ChangeExtractorService.test.ts b/test/main/services/team/ChangeExtractorService.test.ts index ea9fecbc..728f1575 100644 --- a/test/main/services/team/ChangeExtractorService.test.ts +++ b/test/main/services/team/ChangeExtractorService.test.ts @@ -651,6 +651,14 @@ describe('ChangeExtractorService', () => { const stalePromise = service.getTaskChanges(TEAM_NAME, TASK_ID, SUMMARY_OPTIONS); await service.invalidateTaskChangeSummaries(TEAM_NAME, [TASK_ID], { deletePersisted: true }); const freshPromise = service.getTaskChanges(TEAM_NAME, TASK_ID, SUMMARY_OPTIONS); + // Flush microtasks so freshPromise advances past its internal awaits + // and reaches the worker mock before we resolve the stale deferred. + // Without this, CI timing can cause the stale resolution to race with + // the fresh worker call, making the test flaky. + await vi.advanceTimersByTimeAsync?.(0).catch(() => undefined); + await Promise.resolve(); + await Promise.resolve(); + await Promise.resolve(); first.resolve(makeTaskChangeResult()); const stale = await stalePromise; const fresh = await freshPromise;