test(cli): use unique temp dir for extension install

main
Kelvin Calcano 2026-02-04 12:15:01 -04:00 committed by Peter Steinberger
parent 0621d0e9e8
commit 1008c28f5a
2 changed files with 13 additions and 10 deletions

View File

@ -1,18 +1,20 @@
import fs from "node:fs"; import fs from "node:fs";
import os from "node:os";
import path from "node:path"; import path from "node:path";
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { installChromeExtension } from "./browser-cli-extension"; 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", () => { describe("browser extension install", () => {
it("installs bundled chrome extension into a state dir", async () => { 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-"));
try {
const result = await installChromeExtension({ stateDir: tmp }); const result = await installChromeExtension({ stateDir: tmp });
expect(result.path).toContain(path.join("browser", "chrome-extension")); expect(result.path).toBe(path.join(tmp, "browser", "chrome-extension"));
expect(fs.existsSync(path.join(result.path, "manifest.json"))).toBe(true); expect(fs.existsSync(path.join(result.path, "manifest.json"))).toBe(true);
} finally {
fs.rmSync(tmp, { recursive: true, force: true });
}
}); });
}); });

View File

@ -15,10 +15,11 @@ import { formatCliCommand } from "./command-format.js";
function bundledExtensionRootDir() { function bundledExtensionRootDir() {
const here = path.dirname(fileURLToPath(import.meta.url)); const here = path.dirname(fileURLToPath(import.meta.url));
// `dist/` lives at `<packageRoot>/dist` in npm installs. // `here` is the directory containing this file.
// - In npm installs, that's typically `<packageRoot>/dist/cli`.
// - In source runs/tests, it's typically `<packageRoot>/src/cli`.
// The bundled extension lives at `<packageRoot>/assets/chrome-extension`. // The bundled extension lives at `<packageRoot>/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() { function installedExtensionRootDir() {