mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 01:54:49 +00:00
* perf(js/browser/uefi): index export shape coverage and AST writes, eliminate CdpRuntimeRequests re-parse and UefiLzmaWorker JSON round-trip (#13530) * fix(browser): detach published runtime initiator facts
93 lines
2.8 KiB
TypeScript
93 lines
2.8 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { WEB_RUNTIME_LIMITS } from "../../domain/webRuntime.js";
|
|
import { receiveCdpEvent } from "../CdpConnection.js";
|
|
import { CdpRuntimeRequests } from "./CdpRuntimeRequests.js";
|
|
|
|
const origin = "https://example.test";
|
|
const sources = {
|
|
session: {
|
|
operation: "observe_web_execution" as const,
|
|
allowedOrigins: new Set([origin]),
|
|
target: { frame_id: "main" },
|
|
},
|
|
sourceUrl: (_scriptId: string, url: string) => url,
|
|
location: (): never => {
|
|
throw new Error("This parser-only initiator has no callsites");
|
|
},
|
|
};
|
|
const event = (
|
|
extraRequest: Record<string, string>,
|
|
extraInitiator: Record<string, unknown> = {},
|
|
) => ({
|
|
method: "Network.requestWillBeSent",
|
|
params: {
|
|
requestId: "request",
|
|
frameId: "main",
|
|
timestamp: 1,
|
|
request: { url: `${origin}/resource`, method: "POST", ...extraRequest },
|
|
initiator: { type: "parser", ...extraInitiator },
|
|
},
|
|
});
|
|
|
|
it("budgets retained request facts independently of discarded POST bodies", () => {
|
|
const requests = new CdpRuntimeRequests(sources);
|
|
requests.ingest(
|
|
receiveCdpEvent(
|
|
event({
|
|
postData: "p".repeat(WEB_RUNTIME_LIMITS.retainedEventBytes + 1),
|
|
}),
|
|
),
|
|
);
|
|
const retained = requests.result();
|
|
expect(retained).toHaveLength(1);
|
|
expect(retained[0]).toMatchObject({
|
|
method: "POST",
|
|
reported_initiator: { type: "parser" },
|
|
});
|
|
expect(JSON.stringify(retained)).not.toContain("postData");
|
|
});
|
|
|
|
it("keeps retained initiator facts independent of a returned result", () => {
|
|
const requests = new CdpRuntimeRequests(sources);
|
|
requests.ingest(
|
|
receiveCdpEvent(event({}, { extension: { label: "producer" } })),
|
|
);
|
|
const initiator = requests.result()[0]?.reported_initiator;
|
|
const extension = initiator?.extension;
|
|
if (
|
|
typeof extension !== "object" ||
|
|
extension === null ||
|
|
Array.isArray(extension)
|
|
)
|
|
throw new Error("Missing producer extension");
|
|
extension.label = "changed by caller";
|
|
expect(requests.result()[0]?.reported_initiator).toEqual({
|
|
type: "parser",
|
|
extension: { label: "producer" },
|
|
});
|
|
});
|
|
|
|
it("preserves a typed resource refusal for oversized retained initiator facts", () => {
|
|
const requests = new CdpRuntimeRequests(sources);
|
|
requests.ingest(
|
|
receiveCdpEvent(
|
|
event(
|
|
{},
|
|
{ retained: "r".repeat(WEB_RUNTIME_LIMITS.retainedEventBytes + 1) },
|
|
),
|
|
),
|
|
);
|
|
expect(() => requests.result()).toThrow(
|
|
expect.objectContaining({
|
|
_tag: "AnalysisResourceConstraintError",
|
|
operation: "observe_web_execution",
|
|
resource: "capacity",
|
|
reportedLimits: expect.objectContaining({
|
|
boundary: "browser-runtime-retention",
|
|
kind: "requests",
|
|
limit_bytes: WEB_RUNTIME_LIMITS.retainedEventBytes,
|
|
}),
|
|
}),
|
|
);
|
|
});
|