






















@@ -1,7 +1,7 @@
11import fs from "node:fs/promises";
22import os from "node:os";
33import path from "node:path";
4-import { afterEach, describe, expect, it, vi } from "vitest";
4+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55import type { OpenClawConfig } from "../config/config.js";
66import { captureEnv } from "../test-utils/env.js";
77import {
@@ -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.",
2324buildSystemPrompt: () => "Bundle MCP e2e test prompt.",
2425};
2526});
@@ -73,8 +74,25 @@ async function resetBundleMcpPluginState() {
7374clearPluginSetupRegistryCache();
7475}
757677+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+7693afterEach(async () => {
7794cliBackendsTesting.resetDepsForTest();
95+await restoreCliRunnerPrepareDeps();
7896await resetBundleMcpPluginState();
7997});
8098@@ -84,6 +102,7 @@ describe("runCliAgent bundle MCP e2e", () => {
84102{ timeout: E2E_TIMEOUT_MS },
85103async () => {
86104const { runCliAgent } = await import("./cli-runner.js");
105+const { closeMcpLoopbackServer } = await import("../gateway/mcp-http.js");
87106const { resetGlobalHookRunner } = await import("../plugins/hook-runner-global.js");
88107await resetBundleMcpPluginState();
89108const envSnapshot = captureEnv([
@@ -138,11 +157,13 @@ describe("runCliAgent bundle MCP e2e", () => {
138157model: "test-bundle",
139158timeoutMs: 20_000,
140159runId: "bundle-mcp-e2e",
160+cleanupBundleMcpOnRunEnd: true,
141161});
142162143163expect(result.payloads?.[0]?.text).toContain("BUNDLE MCP OK FROM-BUNDLE");
144164expect(result.meta.agentMeta?.sessionId.length ?? 0).toBeGreaterThan(0);
145165} finally {
166+await closeMcpLoopbackServer();
146167resetGlobalHookRunner();
147168await fs.rm(tempHome, { recursive: true, force: true });
148169envSnapshot.restore();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。