refactor(browser): return complete observation evidence

This commit is contained in:
morluto
2026-09-29 13:56:49 +08:00
parent 9d1f88cbe8
commit 0e2738ffb6
69 changed files with 747 additions and 1206 deletions
+24 -4
View File
@@ -23,6 +23,18 @@ const emitWebMcpEvents = (
options: FakeOptions,
): void => {
if (command.method === "WebMCP.enable" && options.webMcpTools === true) {
const inputSchemaProperties =
options.webMcpSchemaPropertyCount === undefined
? {
orderId: { type: "string", example: "schema-secret" },
includeItems: { type: "boolean", default: true },
}
: Object.fromEntries(
Array.from(
{ length: options.webMcpSchemaPropertyCount },
(_value, index) => [`field_${String(index)}`, { type: "string" }],
),
);
event(socket, "WebMCP.toolsAdded", command.sessionId, {
tools: [
{
@@ -32,10 +44,7 @@ const emitWebMcpEvents = (
backendNodeId: 42,
inputSchema: {
type: "object",
properties: {
orderId: { type: "string", example: "schema-secret" },
includeItems: { type: "boolean", default: true },
},
properties: inputSchemaProperties,
required: ["orderId"],
},
annotations: {
@@ -170,6 +179,17 @@ const emitSessionTimeline = (
name: "networkIdle",
timestamp: 15,
});
for (
let index = 0;
index < (options.sessionTimelineEventCount ?? 0);
index += 1
)
event(socket, "Page.lifecycleEvent", command.sessionId, {
frameId: "frame-main",
loaderId: "loader-reload",
name: `lifecycle-${String(index)}`,
timestamp: 16 + index,
});
if (options.sessionTimeline === "target_detached")
event(socket, "Target.detachedFromTarget", undefined, {
sessionId: command.sessionId,
+7 -3
View File
@@ -43,7 +43,7 @@ export const resultFor = (
case "CacheStorage.requestEntries":
return cacheEntriesResult(port);
case "CacheStorage.requestCachedResponse":
return cachedResponseResult();
return cachedResponseResult(options);
default:
return {};
}
@@ -190,8 +190,12 @@ const cacheEntriesResult = (port: number) => ({
returnCount: 1,
});
const cachedResponseResult = () => ({
response: { body: Buffer.from("cache-body-secret").toString("base64") },
const cachedResponseResult = (options: FakeOptions) => ({
response: {
body: Buffer.from(
options.cachedResponseBody ?? "cache-body-secret",
).toString("base64"),
},
});
export const versionTargetId = (options: FakeOptions): string =>
+3
View File
@@ -53,11 +53,14 @@ export interface FakeOptions {
| "same_origin"
| "outside_policy"
| "target_detached";
readonly sessionTimelineEventCount?: number;
readonly closeAfterMethod?: string;
readonly sensitiveShapes?: boolean;
readonly cachedResponseBody?: string;
readonly invalidResponseBodyBase64?: boolean;
readonly webMcpTools?: boolean;
readonly webMcpFrameCount?: number;
readonly webMcpSchemaPropertyCount?: number;
readonly webMcpChildLeavesScope?: boolean;
readonly electronFileUrl?: string;
readonly duplicateElectronInventory?: boolean;