refactor(mcp): simplify tool inputs and inline results

This commit is contained in:
morluto
2026-09-29 11:22:00 +08:00
parent bd0e341572
commit f55c2b9267
70 changed files with 468 additions and 741 deletions
+31 -25
View File
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import { BrowserScenarioSecrets } from "./BrowserScenarioSecrets.js";
import { browserScenarioSchema } from "../domain/browserScenario.js";
import { BROWSER_SCENARIO_CAPTURE_LIMITS } from "../domain/browserScenarioValues.js";
const secret = (secret_id: string) => ({ source: "secret", secret_id });
const literal = (value: string) => ({
@@ -23,14 +24,6 @@ const baseScenario = () => ({
query: [{ name: "token", value: secret("session") }],
},
allowed_origins: ["https://api.example.test", "https://app.example.test"],
environment: {
viewport: { width: 1_280, height: 720 },
locale: "en-US",
timezone: "UTC",
color_scheme: "dark",
reduced_motion: "reduce",
service_workers: "block",
},
actions: [
{
step_id: "login",
@@ -124,22 +117,6 @@ const baseScenario = () => ({
at_end: ["dom", "storage"],
events: ["console", "page-errors", "network", "websockets"],
},
limits: {
max_duration_ms: 60_000,
action_timeout_ms: 5_000,
navigation_timeout_ms: 10_000,
max_events: 2_000,
max_frames: 100,
max_workers: 20,
max_popups: 10,
max_websockets: 100,
max_dom_nodes: 10_000,
max_accessibility_nodes: 10_000,
max_screenshots: 16,
max_screenshot_bytes: 4 * 1_024 * 1_024,
max_storage_entries: 256,
max_total_metadata_bytes: 4 * 1_024 * 1_024,
},
});
describe("browserScenarioSchema", () => {
@@ -149,13 +126,40 @@ describe("browserScenarioSchema", () => {
"https://api.example.test",
"https://app.example.test",
]);
expect(parsed.environment.viewport.device_scale_factor).toBe(1);
expect(parsed.environment).toMatchObject({
viewport: { width: 1_280, height: 720, device_scale_factor: 1 },
locale: "en-US",
timezone: "UTC",
color_scheme: "light",
reduced_motion: "reduce",
service_workers: "block",
});
expect(parsed.request_replay).toEqual({
mode: "exact",
unmatched: "abort",
routes: expect.any(Array),
});
expect(parsed.capture).toEqual({
after_each_step: ["screenshot", "url", "accessibility"],
at_end: ["dom", "storage"],
events: ["console", "page-errors", "network", "websockets"],
});
expect(parsed.redaction.header_names).toEqual([
"authorization",
"cookie",
"proxy-authorization",
"set-cookie",
]);
expect(parsed.limits).toEqual(BROWSER_SCENARIO_CAPTURE_LIMITS);
});
it("rejects caller supplied capture limits", () => {
expect(
browserScenarioSchema.safeParse({
...baseScenario(),
limits: { max_duration_ms: 1 },
}).success,
).toBe(false);
});
it("redacts overlapping secrets longest-first", () => {
@@ -205,7 +209,9 @@ describe("browserScenarioSchema", () => {
expect(browserScenarioSchema.safeParse(scenario).success).toBe(false);
}
});
});
describe("browserScenarioSchema credential handling", () => {
it("rejects redirects outside declared origins", () => {
const scenario = baseScenario();
scenario.request_replay.routes[0]!.response = {
@@ -58,14 +58,6 @@ const scenario = (
},
start_url: { url: "https://app.example.test/" },
allowed_origins: ["https://app.example.test"],
environment: {
viewport: { width: 1_280, height: 720 },
locale: "en-US",
timezone: "UTC",
color_scheme: "light",
reduced_motion: "reduce",
service_workers: "block",
},
actions: Array.from({ length: options.actions ?? 1 }, (_, index) => ({
step_id: `wait_${index}`,
action: "wait_for_timeout",
@@ -83,22 +75,6 @@ const scenario = (
at_end: [],
events: options.events ?? [],
},
limits: {
max_duration_ms: 10_000,
action_timeout_ms: 1_000,
navigation_timeout_ms: 1_000,
max_events: 100,
max_frames: 10,
max_workers: 10,
max_popups: 10,
max_websockets: 10,
max_dom_nodes: 100,
max_accessibility_nodes: 100,
max_screenshots: 2,
max_screenshot_bytes: 1_024,
max_storage_entries: 10,
max_total_metadata_bytes: 16_384,
},
});
type SnapshotKind = BrowserScenario["capture"]["after_each_step"][number];
@@ -122,7 +122,6 @@ const captureScreenshot = async (
return {
state: "captured" as const,
value: {
uri: `rea://web-screenshot/sha256/${sha256}`,
sha256,
bytes: bytes.byteLength,
media_type: "image/png" as const,
@@ -52,22 +52,6 @@ describe("PlaywrightScenarioEvents", () => {
at_end: [],
events: ["page-errors"],
},
limits: {
max_duration_ms: 10_000,
action_timeout_ms: 1_000,
navigation_timeout_ms: 1_000,
max_events: 10,
max_frames: 10,
max_workers: 10,
max_popups: 10,
max_websockets: 10,
max_dom_nodes: 100,
max_accessibility_nodes: 100,
max_screenshots: 1,
max_screenshot_bytes: 1_024,
max_storage_entries: 10,
max_total_metadata_bytes: 1_000_000,
},
});
const secrets = BrowserScenarioSecrets.resolve(scenario, {});
if (secrets === undefined) throw new Error("Expected resolved secrets");