From 212c4af50d0590fae506c842b7634f8f1478ef58 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 18 Apr 2026 22:33:43 +0100 Subject: [PATCH] perf: skip disabled bundle MCP scans --- src/agents/cli-runner/bundle-mcp.test.ts | 35 +++++++++++++----------- src/plugins/bundle-config-shared.ts | 6 +++- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/agents/cli-runner/bundle-mcp.test.ts b/src/agents/cli-runner/bundle-mcp.test.ts index c71041129e0..120a5cc6544 100644 --- a/src/agents/cli-runner/bundle-mcp.test.ts +++ b/src/agents/cli-runner/bundle-mcp.test.ts @@ -1,6 +1,6 @@ import fs from "node:fs/promises"; import path from "node:path"; -import { afterAll, describe, expect, it } from "vitest"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; import type { OpenClawConfig } from "../../config/types.openclaw.js"; import { createBundleMcpTempHarness, @@ -11,6 +11,15 @@ import { captureEnv } from "../../test-utils/env.js"; import { prepareCliBundleMcpConfig } from "./bundle-mcp.js"; const tempHarness = createBundleMcpTempHarness(); +let bundleProbeHomeDir = ""; +let bundleProbeWorkspaceDir = ""; +let bundleProbeServerPath = ""; + +beforeAll(async () => { + bundleProbeHomeDir = await tempHarness.createTempDir("openclaw-cli-bundle-mcp-home-"); + bundleProbeWorkspaceDir = await tempHarness.createTempDir("openclaw-cli-bundle-mcp-workspace-"); + ({ serverPath: bundleProbeServerPath } = await createBundleProbePlugin(bundleProbeHomeDir)); +}); afterAll(async () => { await tempHarness.cleanup(); @@ -28,7 +37,7 @@ describe("prepareCliBundleMcpConfig", () => { args: ["./fake-claude.mjs"], }, workspaceDir, - config: {}, + config: { plugins: { enabled: false } }, }); const configFlagIndex = prepared.backend.args?.indexOf("--mcp-config") ?? -1; @@ -47,11 +56,7 @@ describe("prepareCliBundleMcpConfig", () => { it("injects a merged --mcp-config overlay for bundle-MCP-enabled backends", async () => { const env = captureEnv(["HOME"]); try { - const homeDir = await tempHarness.createTempDir("openclaw-cli-bundle-mcp-home-"); - const workspaceDir = await tempHarness.createTempDir("openclaw-cli-bundle-mcp-workspace-"); - process.env.HOME = homeDir; - - const { serverPath } = await createBundleProbePlugin(homeDir); + process.env.HOME = bundleProbeHomeDir; const config: OpenClawConfig = { plugins: { @@ -68,7 +73,7 @@ describe("prepareCliBundleMcpConfig", () => { command: "node", args: ["./fake-claude.mjs"], }, - workspaceDir, + workspaceDir: bundleProbeWorkspaceDir, config, }); @@ -80,7 +85,7 @@ describe("prepareCliBundleMcpConfig", () => { const raw = JSON.parse(await fs.readFile(generatedConfigPath as string, "utf-8")) as { mcpServers?: Record; }; - expect(raw.mcpServers?.bundleProbe?.args).toEqual([await fs.realpath(serverPath)]); + expect(raw.mcpServers?.bundleProbe?.args).toEqual([await fs.realpath(bundleProbeServerPath)]); expect(prepared.mcpConfigHash).toMatch(/^[0-9a-f]{64}$/); await prepared.cleanup?.(); @@ -147,11 +152,7 @@ describe("prepareCliBundleMcpConfig", () => { it("merges loopback overlay config with bundle MCP servers", async () => { const env = captureEnv(["HOME"]); try { - const homeDir = await tempHarness.createTempDir("openclaw-cli-bundle-mcp-home-"); - const workspaceDir = await tempHarness.createTempDir("openclaw-cli-bundle-mcp-workspace-"); - process.env.HOME = homeDir; - - await createBundleProbePlugin(homeDir); + process.env.HOME = bundleProbeHomeDir; const config: OpenClawConfig = { plugins: { @@ -168,7 +169,7 @@ describe("prepareCliBundleMcpConfig", () => { command: "node", args: ["./fake-claude.mjs"], }, - workspaceDir, + workspaceDir: bundleProbeWorkspaceDir, config, additionalConfig: { mcpServers: { @@ -209,7 +210,7 @@ describe("prepareCliBundleMcpConfig", () => { args: ["./fake-claude.mjs"], }, workspaceDir, - config: {}, + config: { plugins: { enabled: false } }, env: { OPENCLAW_MCP_TOKEN: "loopback-token-123", OPENCLAW_MCP_SESSION_KEY: "agent:main:telegram:group:chat123", @@ -250,6 +251,7 @@ describe("prepareCliBundleMcpConfig", () => { resumeArgs: ["exec", "resume", "{sessionId}"], }, workspaceDir: "/tmp/openclaw-bundle-mcp-codex", + config: { plugins: { enabled: false } }, additionalConfig: { mcpServers: { openclaw: { @@ -290,6 +292,7 @@ describe("prepareCliBundleMcpConfig", () => { args: ["--prompt", "{prompt}"], }, workspaceDir: "/tmp/openclaw-bundle-mcp-gemini", + config: { plugins: { enabled: false } }, additionalConfig: { mcpServers: { openclaw: { diff --git a/src/plugins/bundle-config-shared.ts b/src/plugins/bundle-config-shared.ts index c7742fa3e1f..6cf34bfe9eb 100644 --- a/src/plugins/bundle-config-shared.ts +++ b/src/plugins/bundle-config-shared.ts @@ -102,11 +102,15 @@ export function loadEnabledBundleConfig(params: { }) => { config: TConfig; diagnostics: string[] }; createDiagnostic: (pluginId: string, message: string) => TDiagnostic; }): { config: TConfig; diagnostics: TDiagnostic[] } { + const normalizedPlugins = normalizePluginsConfig(params.cfg?.plugins); + if (!normalizedPlugins.enabled) { + return { config: params.createEmptyConfig(), diagnostics: [] }; + } + const registry = loadPluginManifestRegistry({ workspaceDir: params.workspaceDir, config: params.cfg, }); - const normalizedPlugins = normalizePluginsConfig(params.cfg?.plugins); const diagnostics: TDiagnostic[] = []; let merged = params.createEmptyConfig();