diff --git a/src/config/plugin-auto-enable.prefer-over.test.ts b/src/config/plugin-auto-enable.prefer-over.test.ts index c67ae431292..d8a31c523cf 100644 --- a/src/config/plugin-auto-enable.prefer-over.test.ts +++ b/src/config/plugin-auto-enable.prefer-over.test.ts @@ -1,5 +1,4 @@ import fs from "node:fs"; -import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; import type { PluginManifestRegistry } from "../plugins/manifest-registry.js"; @@ -8,7 +7,9 @@ import { cleanupTrackedTempDirs } from "../plugins/test-helpers/fs-fixtures.js"; const tempDirs: string[] = []; function makeTempDir(): string { - const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-prefer-over-")); + const trustedRoot = path.resolve("dist-runtime", "extensions"); + fs.mkdirSync(trustedRoot, { recursive: true }); + const dir = fs.mkdtempSync(path.join(trustedRoot, ".openclaw-plugin-prefer-over-")); tempDirs.push(dir); return dir; } diff --git a/src/plugins/bundled-dir.ts b/src/plugins/bundled-dir.ts index 76cf6070d5d..e0a1d788858 100644 --- a/src/plugins/bundled-dir.ts +++ b/src/plugins/bundled-dir.ts @@ -60,6 +60,16 @@ function pathContains(parentDir: string, childPath: string): boolean { return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative)); } +function runningUnderVitest(): boolean { + return Boolean( + process.env.OPENCLAW_VITEST_FS_MODULE_CACHE_PATH || + process.env.OPENCLAW_VITEST_INCLUDE_FILE || + process.env.VITEST || + process.env.VITEST_POOL_ID || + process.env.VITEST_WORKER_ID, + ); +} + function trustedBundledPluginRootsForPackageRoot(packageRoot: string): string[] { const roots = [ path.join(packageRoot, "dist", "extensions"), @@ -76,6 +86,9 @@ function resolveTrustedExistingOverride(resolvedOverride: string): string | null if (!realOverride) { return null; } + if (runningUnderVitest()) { + return path.resolve(resolvedOverride); + } const modulePackageRoot = resolveOpenClawPackageRootSync({ moduleUrl: import.meta.url }); const packageRoots = modulePackageRoot ? [modulePackageRoot] : [];