fix: isolate bundled plugin test roots (#73235) (thanks @zqchris) · openclaw/openclaw@b8f071a
steipete
·
2026-04-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -795,6 +795,7 @@ describe("gateway server cron", () => {
|
795 | 795 | }); |
796 | 796 | |
797 | 797 | test("ignores ambient disabled channel env when validating announce delivery", async () => { |
| 798 | +vi.stubEnv("OPENCLAW_DISABLE_BUNDLED_PLUGINS", "1"); |
798 | 799 | vi.stubEnv("SLACK_BOT_TOKEN", "xoxb-ambient"); |
799 | 800 | vi.stubEnv("TELEGRAM_BOT_TOKEN", "ambient-telegram"); |
800 | 801 | const { prevSkipCron } = await setupCronTestRun({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -147,9 +147,11 @@ const expectedSortedCatalog = (): ModelCatalogRpcEntry[] => [
|
147 | 147 | |
148 | 148 | describe("gateway server models + voicewake", () => { |
149 | 149 | const listModels = async (params?: { view?: "default" | "configured" | "all" }) => |
150 | | -params |
151 | | - ? rpcReq<{ models: ModelCatalogRpcEntry[] }>(ws, "models.list", params) |
152 | | - : rpcReq<{ models: ModelCatalogRpcEntry[] }>(ws, "models.list"); |
| 150 | +withEnvAsync({ OPENCLAW_DISABLE_BUNDLED_PLUGINS: "1" }, async () => |
| 151 | +params |
| 152 | + ? await rpcReq<{ models: ModelCatalogRpcEntry[] }>(ws, "models.list", params) |
| 153 | + : await rpcReq<{ models: ModelCatalogRpcEntry[] }>(ws, "models.list"), |
| 154 | +); |
153 | 155 | |
154 | 156 | const seedPiCatalog = () => { |
155 | 157 | piSdkMock.enabled = true; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -330,6 +330,7 @@ describe("resolveBundledPluginsDir", () => {
|
330 | 330 | process.execArgv.length = 0; |
331 | 331 | process.env.VITEST = "true"; |
332 | 332 | process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = path.join(overrideRoot, "extensions"); |
| 333 | +delete process.env.OPENCLAW_TEST_TRUST_BUNDLED_PLUGINS_DIR; |
333 | 334 | delete process.env.OPENCLAW_DISABLE_BUNDLED_PLUGINS; |
334 | 335 | |
335 | 336 | const bundledDir = resolveBundledPluginsDir(); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
|
7 | 7 | import { resolveUserPath } from "../utils.js"; |
8 | 8 | |
9 | 9 | const DISABLED_BUNDLED_PLUGINS_DIR = path.join(os.tmpdir(), "openclaw-empty-bundled-plugins"); |
| 10 | +const TEST_TRUST_BUNDLED_PLUGINS_DIR_ENV = "OPENCLAW_TEST_TRUST_BUNDLED_PLUGINS_DIR"; |
10 | 11 | let bundledPluginsDirOverrideForTest: string | undefined; |
11 | 12 | |
12 | 13 | export function areBundledPluginsDisabled(env: NodeJS.ProcessEnv = process.env): boolean { |
@@ -27,6 +28,20 @@ function isSourceCheckoutRoot(packageRoot: string): boolean {
|
27 | 28 | ); |
28 | 29 | } |
29 | 30 | |
| 31 | +function isTruthyEnvValue(value: string | undefined): boolean { |
| 32 | +const normalized = value?.trim().toLowerCase(); |
| 33 | +return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on"; |
| 34 | +} |
| 35 | + |
| 36 | +function shouldTrustTestBundledPluginsDirOverride(env: NodeJS.ProcessEnv): boolean { |
| 37 | +const isVitestProcess = Boolean(env.VITEST) || Boolean(process.env.VITEST); |
| 38 | +return ( |
| 39 | +isVitestProcess && |
| 40 | +(isTruthyEnvValue(env[TEST_TRUST_BUNDLED_PLUGINS_DIR_ENV]) || |
| 41 | +isTruthyEnvValue(process.env[TEST_TRUST_BUNDLED_PLUGINS_DIR_ENV])) |
| 42 | +); |
| 43 | +} |
| 44 | + |
30 | 45 | function hasUsableBundledPluginTree(pluginsDir: string): boolean { |
31 | 46 | if (!fs.existsSync(pluginsDir)) { |
32 | 47 | return false; |
@@ -183,6 +198,9 @@ export function resolveBundledPluginsDir(env: NodeJS.ProcessEnv = process.env):
|
183 | 198 | if (override) { |
184 | 199 | const resolvedOverride = resolveUserPath(override, env); |
185 | 200 | if (fs.existsSync(resolvedOverride)) { |
| 201 | +if (shouldTrustTestBundledPluginsDirOverride(env)) { |
| 202 | +return path.resolve(resolvedOverride); |
| 203 | +} |
186 | 204 | const trustedOverride = resolveTrustedExistingOverride(resolvedOverride); |
187 | 205 | if (trustedOverride) { |
188 | 206 | return trustedOverride; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1015,10 +1015,10 @@ function resolveExistingExternalBundledRuntimeDepsRoots(params: {
|
1015 | 1015 | packageRoot: string; |
1016 | 1016 | env: NodeJS.ProcessEnv; |
1017 | 1017 | }): string[] | null { |
1018 | | -const packageRoot = path.resolve(params.packageRoot); |
| 1018 | +const packageRoot = realpathOrResolve(params.packageRoot); |
1019 | 1019 | const externalBaseDirs = resolveBundledRuntimeDepsExternalBaseDirs(params.env); |
1020 | 1020 | for (const externalBaseDir of externalBaseDirs) { |
1021 | | -const relative = path.relative(path.resolve(externalBaseDir), packageRoot); |
| 1021 | +const relative = path.relative(realpathOrResolve(externalBaseDir), packageRoot); |
1022 | 1022 | if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) { |
1023 | 1023 | continue; |
1024 | 1024 | } |
@@ -1031,6 +1031,14 @@ function resolveExistingExternalBundledRuntimeDepsRoots(params: {
|
1031 | 1031 | return null; |
1032 | 1032 | } |
1033 | 1033 | |
| 1034 | +function realpathOrResolve(targetPath: string): string { |
| 1035 | +try { |
| 1036 | +return fs.realpathSync.native(targetPath); |
| 1037 | +} catch { |
| 1038 | +return path.resolve(targetPath); |
| 1039 | +} |
| 1040 | +} |
| 1041 | + |
1034 | 1042 | function resolveSourceCheckoutRuntimeDepsCacheDir(params: { |
1035 | 1043 | pluginId: string; |
1036 | 1044 | pluginRoot: string; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,9 @@ vi.mock("@mariozechner/clipboard", () => ({
|
37 | 37 | |
38 | 38 | // Ensure Vitest environment is properly set. |
39 | 39 | process.env.VITEST = "true"; |
| 40 | +// Tests frequently point bundled plugin discovery at temp fixture roots. Production still rejects |
| 41 | +// arbitrary OPENCLAW_BUNDLED_PLUGINS_DIR overrides unless this Vitest-only opt-in is present. |
| 42 | +process.env.OPENCLAW_TEST_TRUST_BUNDLED_PLUGINS_DIR ??= "1"; |
40 | 43 | // Config validation walks plugin manifests; keep an aggressive cache in tests to avoid |
41 | 44 | // repeated filesystem discovery across suites/workers. |
42 | 45 | process.env.OPENCLAW_PLUGIN_MANIFEST_CACHE_MS ??= "60000"; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。