diff --git a/src/channels/plugins/bundled-root-caches.test.ts b/src/channels/plugins/bundled-root-caches.test.ts index c13b33eb26e..38cb69b460f 100644 --- a/src/channels/plugins/bundled-root-caches.test.ts +++ b/src/channels/plugins/bundled-root-caches.test.ts @@ -4,6 +4,15 @@ import path from "node:path"; import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures"; import { afterEach, describe, expect, it, vi } from "vitest"; +vi.mock("../../plugins/bundled-dir.js", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + resolveBundledPluginsDir: (env: NodeJS.ProcessEnv = process.env) => + env.OPENCLAW_BUNDLED_PLUGINS_DIR ?? actual.resolveBundledPluginsDir(env), + }; +}); + const tempDirs: string[] = []; const originalBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR; diff --git a/src/channels/plugins/bundled.shape-guard.test.ts b/src/channels/plugins/bundled.shape-guard.test.ts index 8633ddc03e0..e0353e6983f 100644 --- a/src/channels/plugins/bundled.shape-guard.test.ts +++ b/src/channels/plugins/bundled.shape-guard.test.ts @@ -5,6 +5,15 @@ import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures"; import { afterEach, describe, expect, it, vi } from "vitest"; import { loadPluginManifestRegistry } from "../../plugins/manifest-registry.js"; +vi.mock("../../plugins/bundled-dir.js", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + resolveBundledPluginsDir: (env: NodeJS.ProcessEnv = process.env) => + env.OPENCLAW_BUNDLED_PLUGINS_DIR ?? actual.resolveBundledPluginsDir(env), + }; +}); + const bundledChannelEntrypointPaths = ["index.ts", "channel-entry.ts", "setup-entry.ts"] as const; type BundledEntrySource = { built?: string; source?: string }; diff --git a/src/channels/plugins/read-only.test.ts b/src/channels/plugins/read-only.test.ts index f1404fe8a2f..3e68de3269a 100644 --- a/src/channels/plugins/read-only.test.ts +++ b/src/channels/plugins/read-only.test.ts @@ -1,6 +1,6 @@ import fs from "node:fs"; import path from "node:path"; -import { afterAll, afterEach, describe, expect, it } from "vitest"; +import { afterAll, afterEach, describe, expect, it, vi } from "vitest"; import { cleanupPluginLoaderFixturesForTest, EMPTY_PLUGIN_SCHEMA, @@ -10,6 +10,15 @@ import { } from "../../plugins/loader.test-fixtures.js"; import { listReadOnlyChannelPluginsForConfig } from "./read-only.js"; +vi.mock("../../plugins/bundled-dir.js", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + resolveBundledPluginsDir: (env: NodeJS.ProcessEnv = process.env) => + env.OPENCLAW_BUNDLED_PLUGINS_DIR ?? actual.resolveBundledPluginsDir(env), + }; +}); + function writeExternalSetupChannelPlugin( options: { setupEntry?: boolean; diff --git a/src/plugins/bundled-dir.ts b/src/plugins/bundled-dir.ts index e0a1d788858..76cf6070d5d 100644 --- a/src/plugins/bundled-dir.ts +++ b/src/plugins/bundled-dir.ts @@ -60,16 +60,6 @@ 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"), @@ -86,9 +76,6 @@ 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] : []; diff --git a/src/plugins/discovery.test.ts b/src/plugins/discovery.test.ts index 55650e3b797..d686c09881d 100644 --- a/src/plugins/discovery.test.ts +++ b/src/plugins/discovery.test.ts @@ -10,6 +10,15 @@ import { mkdirSafeDir, } from "./test-helpers/fs-fixtures.js"; +vi.mock("./bundled-dir.js", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + resolveBundledPluginsDir: (env: NodeJS.ProcessEnv = process.env) => + env.OPENCLAW_BUNDLED_PLUGINS_DIR ?? actual.resolveBundledPluginsDir(env), + }; +}); + const tempDirs: string[] = []; function makeTempDir() { @@ -58,6 +67,7 @@ function buildDiscoveryEnv(stateDir: string): NodeJS.ProcessEnv { return { OPENCLAW_STATE_DIR: stateDir, OPENCLAW_HOME: undefined, + OPENCLAW_DISABLE_BUNDLED_PLUGINS: "1", OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins", }; } @@ -483,6 +493,7 @@ describe("discoverOpenClawPlugins", () => { const { candidates, diagnostics } = discoverOpenClawPlugins({ env: { ...buildDiscoveryEnv(stateDir), + OPENCLAW_DISABLE_BUNDLED_PLUGINS: undefined, OPENCLAW_BUNDLED_PLUGINS_DIR: bundledDir, }, }); @@ -504,6 +515,7 @@ describe("discoverOpenClawPlugins", () => { extraPaths: [bundledPluginDir], env: { ...buildDiscoveryEnv(stateDir), + OPENCLAW_DISABLE_BUNDLED_PLUGINS: undefined, OPENCLAW_BUNDLED_PLUGINS_DIR: bundledRoot, }, }); @@ -537,6 +549,7 @@ describe("discoverOpenClawPlugins", () => { extraPaths: [legacyPluginDir], env: { ...buildDiscoveryEnv(stateDir), + OPENCLAW_DISABLE_BUNDLED_PLUGINS: undefined, OPENCLAW_BUNDLED_PLUGINS_DIR: bundledRoot, }, }); @@ -577,6 +590,7 @@ describe("discoverOpenClawPlugins", () => { const { candidates, diagnostics } = discoverOpenClawPlugins({ env: { ...buildDiscoveryEnv(stateDir), + OPENCLAW_DISABLE_BUNDLED_PLUGINS: undefined, OPENCLAW_BUNDLED_PLUGINS_DIR: bundledRoot, }, }); @@ -628,6 +642,7 @@ describe("discoverOpenClawPlugins", () => { const { candidates, diagnostics } = discoverOpenClawPlugins({ env: { ...buildDiscoveryEnv(stateDir), + OPENCLAW_DISABLE_BUNDLED_PLUGINS: undefined, OPENCLAW_BUNDLED_PLUGINS_DIR: bundledRoot, }, }); @@ -1425,6 +1440,7 @@ describe("discoverOpenClawPlugins", () => { }); const env = buildCachedDiscoveryEnv(stateDir, { + OPENCLAW_DISABLE_BUNDLED_PLUGINS: undefined, OPENCLAW_BUNDLED_PLUGINS_DIR: bundledDir, }); const readdirSync = vi.spyOn(fs, "readdirSync");