From 27207bfedb3de4d4e1bd03476deed06099688b87 Mon Sep 17 00:00:00 2001 From: Yichen Jiang Date: Fri, 18 Sep 2026 20:28:15 +0800 Subject: [PATCH] test(plugin-manager): stop an install before its first run deterministically The cancelled-between-attempts case raced a zero-delay timer against the file restore between two registries; under parallel load the restore won, the second attempt started, and the once-only mock let it reach the real pnpm. The stop now lands while the registries are read, before any run, which is the same guard and cannot race. --- .../boot/plugin-manager/tests/manager.spec.ts | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/boot/plugin-manager/tests/manager.spec.ts b/packages/boot/plugin-manager/tests/manager.spec.ts index b3469026fd..70bd913e34 100644 --- a/packages/boot/plugin-manager/tests/manager.spec.ts +++ b/packages/boot/plugin-manager/tests/manager.spec.ts @@ -972,21 +972,21 @@ it('stops at a failure no registry changes, at a host the spec itself is fetched expect(install).toHaveBeenCalledTimes(5) }) -it('reports a stop that lands between two attempts as cancelled', async () => { - const { manager, dir } = await fixture() +it('reports a stop that lands before a run starts, while the registries are read, as cancelled', async () => { + const { manager } = await fixture() const requestId = 'f2340b6d-40bb-46b7-8b94-217bdf5010bd' as PluginInstallRequestId - const install = vi.spyOn(operations, 'runProfilePnpm').mockImplementationOnce(async () => { - // The first attempt fails; the stop lands while its files go back, before the next registry is asked. - setTimeout(() => { void manager.cancelInstall(requestId) }, 0) - writeFileSync(join(dir, 'pnpm-lock.yaml'), 'partial lockfile\n') - return { exitCode: 1, output: 'ERR_PNPM_META_FETCH_FAIL GET https://registry/x: ETIMEDOUT', truncated: false, logPath: join(dir, 'pnpm.log') } + // The stop lands while the plan is being read: the run after it must not start on a dead signal. + const read = vi.spyOn(operations, 'readProfileRegistry').mockImplementation(async () => { + void manager.cancelInstall(requestId) + await Promise.resolve() + return OFFICIAL }) - onTestFinished(() => { install.mockRestore() }) + const install = vi.spyOn(operations, 'runProfilePnpm') + onTestFinished(() => { read.mockRestore(); install.mockRestore() }) const result = await manager.installBundle('dsh-x', { requestId }) - expect(result).toMatchObject({ application: 'cancelled', registries: [null] }) + expect(result).toMatchObject({ application: 'cancelled', registries: [] }) expect(result.error).toBeUndefined() - expect(install).toHaveBeenCalledTimes(1) - expect(existsSync(join(dir, 'pnpm-lock.yaml'))).toBe(false) + expect(install).not.toHaveBeenCalled() }) it('answers the configured registries in pnpm\'s comparison form with what pnpm names, and refuses one that is not an http(s) URL at load', async () => {