test: tighten browser mcp assertions

This commit is contained in:
Peter Steinberger
2026-05-11 14:50:16 +01:00
parent 5dbeacabc9
commit ed6d72efcf
3 changed files with 25 additions and 28 deletions

View File

@@ -17,6 +17,11 @@ type ToolCall = {
name: string;
arguments?: Record<string, unknown>;
};
type ToolCallMock = {
mock: {
calls: Array<[ToolCall]>;
};
};
type ChromeMcpSessionFactory = Exclude<
Parameters<typeof setChromeMcpSessionFactoryForTest>[0],
@@ -256,9 +261,9 @@ describe("chrome MCP page parsing", () => {
name: "new_page",
arguments: { url: "about:blank", timeout: 5000 },
});
expect(session.client.callTool).not.toHaveBeenCalledWith(
expect.objectContaining({ name: "navigate_page" }),
);
const callToolMock = session.client.callTool as unknown as ToolCallMock;
const callNames = callToolMock.mock.calls.map(([call]) => call.name);
expect(callNames).not.toContain("navigate_page");
});
it("parses evaluate_script text responses when structuredContent is missing", async () => {
@@ -654,12 +659,11 @@ describe("chrome MCP page parsing", () => {
// intentionally no timeoutMs
});
expect(session.client.callTool).toHaveBeenCalledWith(
expect.objectContaining({
name: "navigate_page",
arguments: expect.objectContaining({ timeout: 20_000 }),
}),
);
const callToolMock = session.client.callTool as unknown as ToolCallMock;
const navigateCall = callToolMock.mock.calls.find(
([call]) => call.name === "navigate_page",
)?.[0];
expect(navigateCall?.arguments?.timeout).toBe(20_000);
});
it("resets the Chrome MCP session when a navigate_page call hangs past the safety-net timeout", async () => {

View File

@@ -96,10 +96,8 @@ describe("pw-ai", () => {
targetId: "T1",
});
expect(res.refs).toMatchObject({
e1: { role: "button", name: "OK" },
e2: { role: "link", name: "Docs" },
});
expect(res.refs.e1).toEqual({ role: "button", name: "OK" });
expect(res.refs.e2).toEqual({ role: "link", name: "Docs" });
await clickViaPlaywright({
cdpUrl: "http://127.0.0.1:18792",
@@ -142,10 +140,8 @@ describe("pw-ai", () => {
expect(res.snapshot).toContain("[ref=1]");
expect(res.snapshot).toContain("[ref=2]");
expect(res.refs).toMatchObject({
1: { role: "button", name: "OK" },
2: { role: "link", name: "Docs" },
});
expect(res.refs["1"]).toEqual({ role: "button", name: "OK" });
expect(res.refs["2"]).toEqual({ role: "link", name: "Docs" });
await clickViaPlaywright({
cdpUrl: "http://127.0.0.1:18792",

View File

@@ -335,11 +335,8 @@ describe("runBrowserProxyCommand", () => {
}),
);
expect(dispatcherMocks.dispatch).toHaveBeenCalledWith(
expect.objectContaining({
path: "/snapshot",
}),
);
const [request] = dispatcherMocks.dispatch.mock.calls[0] as [{ path?: string }, ...unknown[]];
expect(request.path).toBe("/snapshot");
});
it("rejects unauthorized body.profile when allowProfiles is configured", async () => {
@@ -436,12 +433,12 @@ describe("runBrowserProxyCommand", () => {
}),
);
expect(dispatcherMocks.dispatch).toHaveBeenCalledWith(
expect.objectContaining({
path: "/stop",
query: { profile: "openclaw" },
}),
);
const [request] = dispatcherMocks.dispatch.mock.calls[0] as [
{ path?: string; query?: unknown },
...unknown[],
];
expect(request.path).toBe("/stop");
expect(request.query).toEqual({ profile: "openclaw" });
});
it("rejects persistent profile creation when allowProfiles is empty", async () => {