Skip to content

Commit 6bd430e

Browse files
committed
test(agents): narrow bundle mcp e2e setup
1 parent e2f82d4 commit 6bd430e

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/agents/cli-runner.bundle-mcp.e2e.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "node:fs/promises";
22
import os from "node:os";
33
import path from "node:path";
4-
import { afterEach, describe, expect, it, vi } from "vitest";
4+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55
import type { OpenClawConfig } from "../config/config.js";
66
import { captureEnv } from "../test-utils/env.js";
77
import {
@@ -20,6 +20,7 @@ vi.mock("./cli-runner/helpers.js", async () => {
2020
// This e2e only validates bundle MCP wiring into the spawned CLI backend.
2121
// Stub the large prompt-construction path so cold Vitest workers do not
2222
// time out before the actual MCP roundtrip runs.
23+
buildCliAgentSystemPrompt: () => "Bundle MCP e2e test prompt.",
2324
buildSystemPrompt: () => "Bundle MCP e2e test prompt.",
2425
};
2526
});
@@ -73,8 +74,25 @@ async function resetBundleMcpPluginState() {
7374
clearPluginSetupRegistryCache();
7475
}
7576

77+
async function restoreCliRunnerPrepareDeps() {
78+
const { setCliRunnerPrepareTestDeps } = await import("./cli-runner/prepare.js");
79+
const { resolveMcpLoopbackScopedTools } = await import("../gateway/mcp-http.runtime.js");
80+
setCliRunnerPrepareTestDeps({ resolveMcpLoopbackScopedTools });
81+
}
82+
83+
beforeEach(async () => {
84+
const { setCliRunnerPrepareTestDeps } = await import("./cli-runner/prepare.js");
85+
setCliRunnerPrepareTestDeps({
86+
// This test validates downstream bundle MCP config injection. The generic
87+
// OpenClaw loopback tool inventory is covered by prepare-level tests and is
88+
// expensive under cold Linux container workers.
89+
resolveMcpLoopbackScopedTools: () => ({ agentId: "main", tools: [] }),
90+
});
91+
});
92+
7693
afterEach(async () => {
7794
cliBackendsTesting.resetDepsForTest();
95+
await restoreCliRunnerPrepareDeps();
7896
await resetBundleMcpPluginState();
7997
});
8098

@@ -84,6 +102,7 @@ describe("runCliAgent bundle MCP e2e", () => {
84102
{ timeout: E2E_TIMEOUT_MS },
85103
async () => {
86104
const { runCliAgent } = await import("./cli-runner.js");
105+
const { closeMcpLoopbackServer } = await import("../gateway/mcp-http.js");
87106
const { resetGlobalHookRunner } = await import("../plugins/hook-runner-global.js");
88107
await resetBundleMcpPluginState();
89108
const envSnapshot = captureEnv([
@@ -138,11 +157,13 @@ describe("runCliAgent bundle MCP e2e", () => {
138157
model: "test-bundle",
139158
timeoutMs: 20_000,
140159
runId: "bundle-mcp-e2e",
160+
cleanupBundleMcpOnRunEnd: true,
141161
});
142162

143163
expect(result.payloads?.[0]?.text).toContain("BUNDLE MCP OK FROM-BUNDLE");
144164
expect(result.meta.agentMeta?.sessionId.length ?? 0).toBeGreaterThan(0);
145165
} finally {
166+
await closeMcpLoopbackServer();
146167
resetGlobalHookRunner();
147168
await fs.rm(tempHome, { recursive: true, force: true });
148169
envSnapshot.restore();

0 commit comments

Comments
 (0)