From b15451c95679f202e4737154b44898fd4b538aaa Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 21 Sep 2026 00:44:50 +0000 Subject: [PATCH] Make getPackageManager environment fallback test deterministic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test asserted `getPackageManager` returns 'pnpm' for a directory with no package.json. Nothing in the fixture produces that result — it came from the ambient `npm_config_user_agent` of whichever package manager launched vitest. The test passes under `pnpm test` and fails under any other runner, and it never exercised the `unknown -> npm` fallback it appeared to be covering. Replace it with two tests that stub the user agent explicitly: one for an unrecognized user agent, one for an empty one. Both assert the 'npm' fallback, and both fail if that branch is removed. Co-Authored-By: Claude Opus 4.8 --- .../public/node/node-package-manager.test.ts | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/cli-kit/src/public/node/node-package-manager.test.ts b/packages/cli-kit/src/public/node/node-package-manager.test.ts index 2e5221a75a9..5b4559fcc5a 100644 --- a/packages/cli-kit/src/public/node/node-package-manager.test.ts +++ b/packages/cli-kit/src/public/node/node-package-manager.test.ts @@ -948,12 +948,31 @@ describe('getPackageManager', () => { }) }) - test("tries to guess the package manager from the environment if it can't find a package.json", async () => { + test('falls back to npm when no package.json is found and the user agent is unrecognized', async () => { await inTemporaryDirectory(async (tmpDir) => { - // When/Then — no package.json, falls back to user agent - const packageManager = await getPackageManager(tmpDir) - // pnpm is used locally and in CI - expect(packageManager).toEqual('pnpm') + // Given — no package.json in tmpDir, and a user agent naming no known package manager + vi.stubEnv('npm_config_user_agent', 'some-other-tool/1.0.0') + + try { + // When/Then + await expect(getPackageManager(tmpDir)).resolves.toEqual('npm') + } finally { + vi.unstubAllEnvs() + } + }) + }) + + test('falls back to npm when no package.json is found and no user agent is set', async () => { + await inTemporaryDirectory(async (tmpDir) => { + // Given — no package.json in tmpDir, and no user agent to infer from + vi.stubEnv('npm_config_user_agent', '') + + try { + // When/Then + await expect(getPackageManager(tmpDir)).resolves.toEqual('npm') + } finally { + vi.unstubAllEnvs() + } }) }) })