From 03edb00a1cb66712e3441a6fbd7333fca4534f44 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 25 Aug 2026 11:12:39 -0700 Subject: [PATCH] perf(test): seed MCP Doctor fixtures without config mutations (#129498) --- src/cli/mcp-cli.test.ts | 79 ++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/src/cli/mcp-cli.test.ts b/src/cli/mcp-cli.test.ts index 4c3a533ec1ca..2281545447d2 100644 --- a/src/cli/mcp-cli.test.ts +++ b/src/cli/mcp-cli.test.ts @@ -21,6 +21,17 @@ import { import { writeProbeMcpServer } from "./mcp-cli.test-support.js"; import { runCliWithExitFinalization } from "./one-shot-exit.js"; +async function writeMcpDoctorServers( + home: string, + servers: Record, +): Promise { + await fs.writeFile( + path.join(home, ".openclaw", "openclaw.json"), + `${JSON.stringify({ mcp: { servers } })}\n`, + "utf8", + ); +} + describe("mcp cli", () => { beforeEach(() => { resetMcpCliTestState(); @@ -609,30 +620,31 @@ describe("mcp cli", () => { }); it("reports ignored OAuth Authorization headers regardless of casing", async () => { - await withTempHome("openclaw-cli-mcp-home-", async () => { + await withTempHome("openclaw-cli-mcp-home-", async (home) => { const workspaceDir = await createWorkspace(); vi.spyOn(process, "cwd").mockReturnValue(workspaceDir); readMcpOAuthCredentialsStatus.mockResolvedValue({ state: "authorized" }); - for (const { name, header, oauth } of [ - { name: "lowercase", header: "authorization", oauth: true }, - { name: "titlecase", header: "Authorization", oauth: true }, - { name: "uppercase", header: "AUTHORIZATION", oauth: true }, - { name: "proxy", header: "Proxy-Authorization", oauth: true }, - { name: "unrelated", header: "X-Tenant", oauth: true }, - { name: "without-oauth", header: "AUTHORIZATION", oauth: false }, - ]) { - await runMcpCommand([ - "mcp", - "set", - name, - JSON.stringify({ - url: "https://mcp.example.com/mcp", - headers: { [header]: "$MCP_HEADER" }, - ...(oauth ? { auth: "oauth" } : {}), - }), - ]); - } + await writeMcpDoctorServers( + home, + Object.fromEntries( + [ + { name: "lowercase", header: "authorization", oauth: true }, + { name: "titlecase", header: "Authorization", oauth: true }, + { name: "uppercase", header: "AUTHORIZATION", oauth: true }, + { name: "proxy", header: "Proxy-Authorization", oauth: true }, + { name: "unrelated", header: "X-Tenant", oauth: true }, + { name: "without-oauth", header: "AUTHORIZATION", oauth: false }, + ].map(({ name, header, oauth }) => [ + name, + { + url: "https://mcp.example.com/mcp", + headers: { [header]: "$MCP_HEADER" }, + ...(oauth ? { auth: "oauth" } : {}), + }, + ]), + ), + ); mockLog.mockClear(); await runMcpCommand(["mcp", "doctor", "--json"]); @@ -662,21 +674,22 @@ describe("mcp cli", () => { }); it("bounds concurrent MCP doctor server checks", async () => { - await withTempHome("openclaw-cli-mcp-home-", async () => { + await withTempHome("openclaw-cli-mcp-home-", async (home) => { const workspaceDir = await createWorkspace(); vi.spyOn(process, "cwd").mockReturnValue(workspaceDir); - for (let index = 0; index < 6; index += 1) { - await runMcpCommand([ - "mcp", - "set", - `server-${index}`, - JSON.stringify({ - url: `https://mcp-${index}.example.com`, - transport: "streamable-http", - auth: "oauth", - }), - ]); - } + await writeMcpDoctorServers( + home, + Object.fromEntries( + Array.from({ length: 6 }, (_, index) => [ + `server-${index}`, + { + url: `https://mcp-${index}.example.com`, + transport: "streamable-http", + auth: "oauth", + }, + ]), + ), + ); const checksBlocked = createDeferred(); readMcpOAuthCredentialsStatus.mockImplementation(async () => {