From 442a2107b5d151fb40cf6d5d9a2d5d6fb0bf9f2c Mon Sep 17 00:00:00 2001 From: Shakker Date: Fri, 5 Jun 2026 01:02:11 +0100 Subject: [PATCH] test: scope bun install detection env --- src/infra/detect-package-manager.test.ts | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/infra/detect-package-manager.test.ts b/src/infra/detect-package-manager.test.ts index 84f9f7b5d038..4f8c26d2fa84 100644 --- a/src/infra/detect-package-manager.test.ts +++ b/src/infra/detect-package-manager.test.ts @@ -3,6 +3,7 @@ import fs from "node:fs/promises"; import path from "node:path"; import { describe, expect, it } from "vitest"; import { withTempDir } from "../test-helpers/temp-dir.js"; +import { withEnvAsync } from "../test-utils/env.js"; import { detectPackageManager } from "./detect-package-manager.js"; async function withPackageManagerRoot( @@ -122,26 +123,13 @@ describe("detectPackageManager", () => { it("keeps bun-owned global package roots that ship npm-shrinkwrap", async () => { await withTempDir({ prefix: "openclaw-detect-pm-bun-" }, async (base) => { - const oldBunInstall = process.env.BUN_INSTALL; - process.env.BUN_INSTALL = path.join(base, "bun-home"); - try { - const packageRoot = path.join( - process.env.BUN_INSTALL, - "install", - "global", - "node_modules", - "openclaw", - ); + const bunInstall = path.join(base, "bun-home"); + await withEnvAsync({ BUN_INSTALL: bunInstall }, async () => { + const packageRoot = path.join(bunInstall, "install", "global", "node_modules", "openclaw"); await writePublishedOpenClawRoot(packageRoot); await expect(detectPackageManager(packageRoot)).resolves.toBe("bun"); - } finally { - if (oldBunInstall == null) { - delete process.env.BUN_INSTALL; - } else { - process.env.BUN_INSTALL = oldBunInstall; - } - } + }); }); });