mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:00:43 +00:00
test: keep bundled root fixtures scoped
This commit is contained in:
@@ -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<typeof import("../../plugins/bundled-dir.js")>();
|
||||
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;
|
||||
|
||||
|
||||
@@ -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<typeof import("../../plugins/bundled-dir.js")>();
|
||||
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 };
|
||||
|
||||
@@ -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<typeof import("../../plugins/bundled-dir.js")>();
|
||||
return {
|
||||
...actual,
|
||||
resolveBundledPluginsDir: (env: NodeJS.ProcessEnv = process.env) =>
|
||||
env.OPENCLAW_BUNDLED_PLUGINS_DIR ?? actual.resolveBundledPluginsDir(env),
|
||||
};
|
||||
});
|
||||
|
||||
function writeExternalSetupChannelPlugin(
|
||||
options: {
|
||||
setupEntry?: boolean;
|
||||
|
||||
@@ -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] : [];
|
||||
|
||||
@@ -10,6 +10,15 @@ import {
|
||||
mkdirSafeDir,
|
||||
} from "./test-helpers/fs-fixtures.js";
|
||||
|
||||
vi.mock("./bundled-dir.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./bundled-dir.js")>();
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user