diff --git a/src/cli/browser-cli-extension.test.ts b/src/cli/browser-cli-extension.test.ts index 22a9d4f99..f92a264c7 100644 --- a/src/cli/browser-cli-extension.test.ts +++ b/src/cli/browser-cli-extension.test.ts @@ -1,18 +1,20 @@ import fs from "node:fs"; +import os from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; import { installChromeExtension } from "./browser-cli-extension"; -// This test ensures the bundled extension path resolution matches the npm package layout. -// The install command should succeed without requiring any external symlinks. - describe("browser extension install", () => { it("installs bundled chrome extension into a state dir", async () => { - const tmp = path.join(process.cwd(), ".tmp-test-openclaw-state", String(Date.now())); + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-ext-state-")); - const result = await installChromeExtension({ stateDir: tmp }); + try { + const result = await installChromeExtension({ stateDir: tmp }); - expect(result.path).toContain(path.join("browser", "chrome-extension")); - expect(fs.existsSync(path.join(result.path, "manifest.json"))).toBe(true); + expect(result.path).toBe(path.join(tmp, "browser", "chrome-extension")); + expect(fs.existsSync(path.join(result.path, "manifest.json"))).toBe(true); + } finally { + fs.rmSync(tmp, { recursive: true, force: true }); + } }); }); diff --git a/src/cli/browser-cli-extension.ts b/src/cli/browser-cli-extension.ts index e0663c750..cc3ceca2e 100644 --- a/src/cli/browser-cli-extension.ts +++ b/src/cli/browser-cli-extension.ts @@ -15,10 +15,11 @@ import { formatCliCommand } from "./command-format.js"; function bundledExtensionRootDir() { const here = path.dirname(fileURLToPath(import.meta.url)); - // `dist/` lives at `/dist` in npm installs. + // `here` is the directory containing this file. + // - In npm installs, that's typically `/dist/cli`. + // - In source runs/tests, it's typically `/src/cli`. // The bundled extension lives at `/assets/chrome-extension`. - // So we need to go up ONE level from `dist`. - return path.resolve(here, "../assets/chrome-extension"); + return path.resolve(here, "../../assets/chrome-extension"); } function installedExtensionRootDir() {