Files
adolf/test/scripts/mcp-code-mode-gateway-client.test.ts
alvis bedb527145
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Vendor OpenClaw source as Adolf fork baseline
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11),
free to diverge. Tree copied sans upstream .git; upstream remote added for
future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19.
Preserves docs/ARCHITECTURE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
2026-07-05 09:36:54 +00:00

184 lines
5.4 KiB
TypeScript

// Mcp Code Mode Gateway Client tests cover mcp code mode gateway client script behavior.
import { describe, expect, it } from "vitest";
import { validateMcpCodeModeResult } from "../../scripts/e2e/lib/mcp-code-mode-validation.ts";
import {
fetchJson,
readMcpCodeModeClientFetchLimits,
} from "../../scripts/e2e/mcp-code-mode-gateway-client.ts";
const okResponse = {
output: [
{
type: "message",
content: [
{
text: "MCP_CODE_MODE_FILE_OK note=fixture-note-alpha unclear=none",
},
],
},
],
};
const okMentions = {
apiCall: 0,
apiFileList: 1,
apiFileRead: 2,
mcpNamespace: 1,
mcpTool: 1,
toolSearchPollution: 0,
};
describe("MCP code-mode gateway Docker client fetch helper", () => {
it("rejects loose numeric env limits instead of parsing prefixes", () => {
expect(() =>
readMcpCodeModeClientFetchLimits({
OPENCLAW_MCP_CODE_MODE_CLIENT_TIMEOUT_MS: "1e3",
}),
).toThrow("invalid OPENCLAW_MCP_CODE_MODE_CLIENT_TIMEOUT_MS: 1e3");
expect(() =>
readMcpCodeModeClientFetchLimits({
OPENCLAW_MCP_CODE_MODE_CLIENT_BODY_MAX_BYTES: "1000ms",
}),
).toThrow("invalid OPENCLAW_MCP_CODE_MODE_CLIENT_BODY_MAX_BYTES: 1000ms");
expect(
readMcpCodeModeClientFetchLimits({
OPENCLAW_MCP_CODE_MODE_CLIENT_BODY_MAX_BYTES: "4096",
OPENCLAW_MCP_CODE_MODE_CLIENT_TIMEOUT_MS: "120000",
}),
).toEqual({
bodyMaxBytes: 4096,
timeoutMs: 120_000,
});
});
it("aborts requests that never resolve", async () => {
let signal: AbortSignal | undefined;
await expect(
fetchJson("https://qa.example.invalid/v1/responses", undefined, {
timeoutMs: 25,
fetchImpl: async (_url, init) => {
signal = init.signal as AbortSignal | undefined;
return new Promise<Response>(() => {});
},
}),
).rejects.toMatchObject({
code: "ETIMEDOUT",
message: "HTTP request to https://qa.example.invalid/v1/responses timed out after 25ms",
});
expect(signal?.aborted).toBe(true);
});
it("times out while reading stalled response bodies", async () => {
await expect(
fetchJson("https://qa.example.invalid/v1/responses", undefined, {
timeoutMs: 25,
fetchImpl: async () =>
new Response(new ReadableStream<Uint8Array>({ start() {} }), {
status: 200,
}),
}),
).rejects.toMatchObject({
code: "ETIMEDOUT",
message: "HTTP request to https://qa.example.invalid/v1/responses timed out after 25ms",
});
});
it("parses successful JSON responses", async () => {
await expect(
fetchJson("https://qa.example.invalid/v1/responses", undefined, {
timeoutMs: 25,
fetchImpl: async () => new Response('{"ok":true}', { status: 200 }),
}),
).resolves.toEqual({ ok: true });
});
it("bounds oversized response bodies", async () => {
await expect(
fetchJson("https://qa.example.invalid/v1/responses", undefined, {
maxBodyBytes: 16,
timeoutMs: 1000,
fetchImpl: async () =>
new Response(JSON.stringify({ ok: true, padding: "x".repeat(128) }), {
status: 200,
}),
}),
).rejects.toMatchObject({
code: "ETOOBIG",
message: "HTTP response from https://qa.example.invalid/v1/responses exceeded 16 bytes",
});
});
});
describe("MCP code-mode gateway Docker client result validation", () => {
it("accepts final text backed by API file reads and MCP tool calls", () => {
expect(validateMcpCodeModeResult(okResponse, okMentions)).toBe(
"MCP_CODE_MODE_FILE_OK note=fixture-note-alpha unclear=none",
);
});
it("rejects hallucinated success text that reports MCP failure", () => {
expect(() =>
validateMcpCodeModeResult(
{
output: [
{
type: "message",
content: [
{
text: "MCP_CODE_MODE_FILE_OK note=fixture-note-alpha but MCP failed",
},
],
},
],
},
okMentions,
),
).toThrow("agent reported MCP failure");
});
it("requires materialized MCP fixture tool evidence", () => {
expect(() =>
validateMcpCodeModeResult(okResponse, {
...okMentions,
apiFileList: 0,
}),
).toThrow("session log lacks API.list usage");
expect(() =>
validateMcpCodeModeResult(okResponse, {
...okMentions,
mcpTool: 0,
}),
).toThrow("session log lacks fixture__lookup_note call");
});
it("rejects MCP.$api and tools.search fallback pollution", () => {
expect(() =>
validateMcpCodeModeResult(okResponse, {
...okMentions,
apiCall: 1,
}),
).toThrow("agent should not call MCP.$api");
expect(() =>
validateMcpCodeModeResult(okResponse, {
...okMentions,
toolSearchPollution: 1,
}),
).toThrow("agent should not use tools.search");
});
it("requires planned exec evidence for the source gateway E2E", () => {
expect(() =>
validateMcpCodeModeResult(okResponse, okMentions, {
plannedTools: ["tools.search"],
requireExec: true,
}),
).toThrow("agent did not call code-mode exec");
expect(() =>
validateMcpCodeModeResult(okResponse, okMentions, {
plannedTools: ["exec"],
requireExec: true,
}),
).not.toThrow();
});
});