Skip to content

Commit dafd9df

Browse files
committed
test(ui): observe MCP cancellation at the HTTP boundary
1 parent 2f3cd08 commit dafd9df

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

‎ui/src/e2e/mcp-app-conformance.e2e.test.ts‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
createMcpAppTeardownRecorder,
3737
type McpAppFixtureEvent as FixtureEvent,
3838
openMcpAppProofContext,
39+
observeMcpAppHttpResponses,
3940
observeMcpAppNetwork,
4041
findAppFrame,
4142
mountControlUiHost,
@@ -548,6 +549,7 @@ describeConformance("MCP App Control UI and standalone host conformance", () =>
548549
),
549550
);
550551
const diagnostics: Array<Record<string, unknown>> = [];
552+
const http = observeMcpAppHttpResponses(gatewayPort);
551553
const cancellationResults: Array<Record<string, unknown>> = [];
552554
const timingResults: Array<{
553555
scenario: string;
@@ -716,6 +718,7 @@ describeConformance("MCP App Control UI and standalone host conformance", () =>
716718
await fixture.configure({ ...spec, releasePath });
717719
const startedAtMs = Date.now();
718720
const networkStart = diagnostics.length;
721+
const httpStart = http.responses.length;
719722
const observation: Record<string, unknown> = { scenario: spec.scenario, startedAtMs };
720723
cancellationResults.push(observation);
721724
try {
@@ -728,6 +731,9 @@ describeConformance("MCP App Control UI and standalone host conformance", () =>
728731
).length,
729732
)
730733
.toBe(1);
734+
const startedResponses = http.responses.slice(httpStart);
735+
expect(startedResponses).toHaveLength(1);
736+
const response = startedResponses[0]!;
731737
if (spec.action === "abort") {
732738
await app.locator("#cancel-call").click();
733739
}
@@ -782,14 +788,14 @@ describeConformance("MCP App Control UI and standalone host conformance", () =>
782788
expect(events.filter((event) => event.event === "tool-complete")).toMatchObject(
783789
spec.cooperative ? [] : [{ requestId: call.id, aborted: true }],
784790
);
785-
// Fixture stdio and Playwright network events arrive independently.
786-
await expect
787-
.poll(() =>
788-
diagnostics
789-
.slice(networkStart)
790-
.filter((event) => event.event === "requestfailed" && event.method === "POST"),
791-
)
792-
.toHaveLength(1);
791+
// Chromium may omit requestfailed when navigation destroys the old document.
792+
// Observe the exact Gateway response, not an unrelated teardown/control POST.
793+
await expect.poll(() => response.destroyed).toBe(true);
794+
observation.transport = {
795+
closed: response.destroyed,
796+
writableFinished: response.writableFinished,
797+
};
798+
expect(response.writableFinished).toBe(false);
793799
} finally {
794800
if (releasePath) {
795801
await fs.writeFile(releasePath, "released");
@@ -837,8 +843,12 @@ describeConformance("MCP App Control UI and standalone host conformance", () =>
837843
scenario: spec.scenario + "-control",
838844
callDelayMs: 0,
839845
});
846+
const controlHttpStart = http.responses.length;
840847
await app.locator("#call-app").click();
841848
await waitForTextContaining(app.locator("#app-tool"), "companion-called");
849+
const controlResponses = http.responses.slice(controlHttpStart);
850+
expect(controlResponses).toHaveLength(1);
851+
expect(controlResponses[0]?.writableFinished).toBe(true);
842852
const controlEvents = (await fixture.readEvents()).filter(
843853
(event) => event.scenario === spec.scenario + "-control",
844854
);
@@ -998,6 +1008,7 @@ describeConformance("MCP App Control UI and standalone host conformance", () =>
9981008
"companion-called",
9991009
);
10001010
} finally {
1011+
http.stop();
10011012
await fs.writeFile(
10021013
path.join(proofDir, "browser-diagnostics.json"),
10031014
JSON.stringify(diagnostics, null, 2),

‎ui/src/test-helpers/mcp-app-conformance-fixture.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
// Real official App and stdio MCP fixtures shared by conformance scenarios.
2+
import { channel } from "node:diagnostics_channel";
23
import fs from "node:fs/promises";
4+
import type { IncomingMessage, ServerResponse } from "node:http";
35
import { createRequire } from "node:module";
46
import path from "node:path";
57
import type { Browser, BrowserContext, ConsoleMessage, Frame, Locator, Page } from "playwright";
68
import { expect } from "vitest";
79

810
const require = createRequire(import.meta.url);
911

12+
export function observeMcpAppHttpResponses(gatewayPort: number) {
13+
const responses: ServerResponse[] = [];
14+
const requests = channel("http.server.request.start");
15+
const onRequest = (message: unknown) => {
16+
// SAFETY: Node publishes these exact objects before the real HTTP request handler runs.
17+
const { request, response } = message as {
18+
request: IncomingMessage;
19+
response: ServerResponse;
20+
};
21+
if (
22+
request.socket.localPort === gatewayPort &&
23+
request.method === "POST" &&
24+
request.url === "/__openclaw__/mcp-app/view"
25+
) {
26+
responses.push(response);
27+
}
28+
};
29+
requests.subscribe(onRequest);
30+
return { responses, stop: () => requests.unsubscribe(onRequest) };
31+
}
32+
1033
export function observeMcpAppNetwork(
1134
page: Page,
1235
label: string,

0 commit comments

Comments
 (0)