From 34d57c918ef599de195b364ff6df388bd880eadd Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Tue, 7 Jul 2026 00:44:11 +0000 Subject: [PATCH 1/2] [Refactor] Use native timers/promises in sleep Refactor the sleep utility function to use the modern setTimeout from node:timers/promises instead of a manual Promise wrapper. Added a unit test to verify the functionality and protect against regressions. --- packages/cli-kit/src/public/node/system.test.ts | 10 ++++++++++ packages/cli-kit/src/public/node/system.ts | 5 ++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/cli-kit/src/public/node/system.test.ts b/packages/cli-kit/src/public/node/system.test.ts index ed12516ba40..6c863f60dd4 100644 --- a/packages/cli-kit/src/public/node/system.test.ts +++ b/packages/cli-kit/src/public/node/system.test.ts @@ -393,3 +393,13 @@ describe('readStdinString', () => { await expect(got).rejects.toThrow('Stdin input exceeded the maximum allowed size.') }) }) + +describe('sleep', () => { + test('waits for the specified number of seconds', async () => { + vi.useFakeTimers() + const sleepPromise = system.sleep(1) + await vi.advanceTimersByTimeAsync(1000) + await expect(sleepPromise).resolves.toBeUndefined() + vi.useRealTimers() + }) +}) diff --git a/packages/cli-kit/src/public/node/system.ts b/packages/cli-kit/src/public/node/system.ts index 3f449f8ff34..aa997f8c5d8 100644 --- a/packages/cli-kit/src/public/node/system.ts +++ b/packages/cli-kit/src/public/node/system.ts @@ -13,6 +13,7 @@ import which from 'which' import {delimiter} from 'pathe' import {fstatSync} from 'fs' +import {setTimeout} from 'timers/promises' import type {Writable, Readable} from 'stream' /** @@ -319,9 +320,7 @@ function checkCommandSafety(command: string, _options: {cwd: string}): void { * @returns A Promise resolving after the number of seconds. */ export async function sleep(seconds: number): Promise { - return new Promise((resolve) => { - setTimeout(resolve, 1000 * seconds) - }) + await setTimeout(1000 * seconds) } /** From 96eda8f126e3e7211ef9f122fdb723970f08e381 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Tue, 7 Jul 2026 01:19:27 +0000 Subject: [PATCH 2/2] [Refactor] Use native timers/promises in sleep Refactor the sleep utility function to use the modern setTimeout from node:timers/promises instead of a manual Promise wrapper. Added a unit test to verify the functionality and protect against regressions. verified that CI failures are pre-existing and unrelated to this change by running tests locally.