mirror of
https://github.com/morluto/rea
synced 2026-10-25 22:08:11 -04:00
10b83a9b62
Return typed fetch outcomes with completed map coverage when acquisition is cancelled or a response resource fails. Compose those facts with the captured inspection as partial bundle Evidence, preserving exclusions, exact abort causes, and cleanup priority without claiming unperformed script analysis. Keep complete response-body SHA-256 and byte counts when map interpretation fails, while preserving compact failure rows and capacity for later valid maps. Reuse the read owner digest for successful text artifacts and preflight their JSON representation before parsing. Historical failed rows remain importable. Exercise controlled HTTP/stream boundaries, CLI SIGINT, and SDK cancellation with later MCP Evidence retrieval. Share the public cancellation fixture and use one Result API across consumers. Real Chromium and Windows CLI cancellation were not verified.
77 lines
2.4 KiB
TypeScript
77 lines
2.4 KiB
TypeScript
import type { ServerResponse } from "node:http";
|
|
|
|
import { createDeferred } from "./binarySession.js";
|
|
import { startFakeCdpBrowser } from "./fakeCdpBrowser.js";
|
|
|
|
/** Two allowed maps and one excluded map, with the second HTTP response held open. */
|
|
export const startSourceMapCancellationBrowser = async () => {
|
|
const mapText = JSON.stringify({
|
|
version: 3,
|
|
names: [],
|
|
sources: ["src/original.js"],
|
|
sourcesContent: ["export const value = 1;"],
|
|
mappings: "AAAA",
|
|
});
|
|
const scriptText = "export const observed = true;";
|
|
const completedMapPath = createDeferred<string>();
|
|
const secondRequest = createDeferred<string>();
|
|
let firstPath: string | undefined;
|
|
let heldResponse: ServerResponse | undefined;
|
|
const browser = await startFakeCdpBrowser({
|
|
sourceMapReply(url, response) {
|
|
if (url !== "/first.js.map" && url !== "/second.js.map") return false;
|
|
if (firstPath === undefined) {
|
|
firstPath = url;
|
|
response.end(mapText);
|
|
completedMapPath.resolve(url);
|
|
return true;
|
|
}
|
|
heldResponse = response;
|
|
secondRequest.resolve(url);
|
|
return true;
|
|
},
|
|
commandResult: ({ method }) =>
|
|
method === "Debugger.getScriptSource"
|
|
? { scriptSource: scriptText }
|
|
: undefined,
|
|
commandEvents(command, origin) {
|
|
if (command.method !== "Debugger.enable") return undefined;
|
|
const script = (id: string, sourceMapURL: string) => ({
|
|
method: "Debugger.scriptParsed",
|
|
...(command.sessionId === undefined
|
|
? {}
|
|
: { sessionId: command.sessionId }),
|
|
params: {
|
|
scriptId: id,
|
|
url: `${origin}/${id}.js`,
|
|
hash: id,
|
|
length: Buffer.byteLength(scriptText),
|
|
isModule: true,
|
|
executionContextId: 1,
|
|
scriptLanguage: "JavaScript",
|
|
sourceMapURL,
|
|
},
|
|
});
|
|
return [
|
|
script("first", "/first.js.map"),
|
|
script("second", "/second.js.map"),
|
|
script("excluded", "https://outside.example.test/other.js.map"),
|
|
];
|
|
},
|
|
});
|
|
const releasePendingResponse = (): void => {
|
|
heldResponse?.destroy();
|
|
};
|
|
return {
|
|
browser,
|
|
mapText,
|
|
completedMapPath: completedMapPath.promise,
|
|
secondRequest: secondRequest.promise,
|
|
releasePendingResponse,
|
|
async close() {
|
|
releasePendingResponse();
|
|
await browser.close();
|
|
},
|
|
};
|
|
};
|