From 13f2353bd0e41908b6d09aad45e1c9485761dc1d Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Tue, 14 Apr 2026 11:39:26 +0000 Subject: [PATCH] Fix flaky runWithRateLimit test by using fake timers The 'throttles the task when the cache is populated recently' test was flaky because it used real time with a 1-second timeout window. Under CI load, the time between filling the rate limit cache and checking it could exceed 1 second, causing the old occurrences to be swept out and the rate limit to no longer be exceeded. Fix by using vi.useFakeTimers() to freeze time during the test, matching the pattern already used by the 'cache is populated but outdated' test in the same describe block. The existing afterEach hook already calls vi.useRealTimers() for cleanup. Also applied the same fix to the 'rate limit isn't used up' test to prevent the same class of flake. --- packages/cli-kit/src/private/node/conf-store.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/cli-kit/src/private/node/conf-store.test.ts b/packages/cli-kit/src/private/node/conf-store.test.ts index 0faf6a13780..af8d48b9585 100644 --- a/packages/cli-kit/src/private/node/conf-store.test.ts +++ b/packages/cli-kit/src/private/node/conf-store.test.ts @@ -474,6 +474,7 @@ describe('runWithRateLimit', () => { test('throttles the task when the cache is populated recently', async () => { await inTemporaryDirectory(async (cwd) => { // Given + vi.useFakeTimers() const config = new LocalStorage({cwd}) for (let i = 0; i < limit; i++) { // eslint-disable-next-line no-await-in-loop @@ -511,6 +512,7 @@ describe('runWithRateLimit', () => { test("runs the task as usual when the cache is populated recently but the rate limit isn't used up", async () => { await inTemporaryDirectory(async (cwd) => { // Given + vi.useFakeTimers() const config = new LocalStorage({cwd}) // Run the task once, but the rate limit is 2 await runWithRateLimit(