mirror of
https://github.com/morluto/rea
synced 2026-10-26 14:25:49 -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.
79 lines
2.5 KiB
TypeScript
79 lines
2.5 KiB
TypeScript
import { createServer } from "node:http";
|
|
import { describe, expect, it, onTestFinished } from "vitest";
|
|
import { fetchWebSourceMapsOk } from "../../fixtures/fetchWebSourceMapsOk.js";
|
|
import { analyzeWebBundleInputSchema } from "../../../src/domain/webBundleAnalysis.js";
|
|
|
|
describe("source-map discarded HTTP response ownership", () => {
|
|
it.each([302, 400])(
|
|
"closes an unfinished discarded HTTP %s body",
|
|
async (status) => {
|
|
let didClose = false;
|
|
let notifyClosed: (() => void) | undefined;
|
|
const closed = new Promise<void>((resolve) => {
|
|
notifyClosed = resolve;
|
|
});
|
|
const server = createServer((incoming, response) => {
|
|
if (incoming.url === "/final.map") {
|
|
response.end(
|
|
JSON.stringify({
|
|
version: 3,
|
|
names: [],
|
|
sources: [],
|
|
mappings: "",
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
response.writeHead(
|
|
status,
|
|
status === 302 ? { location: "/final.map" } : {},
|
|
);
|
|
response.write("unfinished response body");
|
|
response.on("close", () => {
|
|
didClose = true;
|
|
notifyClosed?.();
|
|
});
|
|
});
|
|
const closeServer = async (): Promise<void> => {
|
|
server.closeAllConnections();
|
|
if (server.listening)
|
|
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
};
|
|
onTestFinished(closeServer);
|
|
try {
|
|
await new Promise<void>((resolve) =>
|
|
server.listen(0, "127.0.0.1", resolve),
|
|
);
|
|
const address = server.address();
|
|
if (address === null || typeof address === "string")
|
|
throw new Error("Expected TCP listener");
|
|
const origin = `http://127.0.0.1:${String(address.port)}`;
|
|
const url = `${origin}/first.map`;
|
|
const input = analyzeWebBundleInputSchema.parse({
|
|
cdp_endpoint: "http://127.0.0.1:9222",
|
|
allowed_origins: [origin],
|
|
target_id: "page-1",
|
|
fetch_source_maps: true,
|
|
});
|
|
const result = await fetchWebSourceMapsOk(
|
|
[
|
|
{
|
|
scriptKey: `scr_${"1".repeat(64)}`,
|
|
declaredUrl: url,
|
|
fetchUrl: url,
|
|
},
|
|
],
|
|
input,
|
|
);
|
|
expect(result.items[0]?.status).toBe(
|
|
status === 302 ? "included" : "fetch_failed",
|
|
);
|
|
await closed;
|
|
expect(didClose).toBe(true);
|
|
} finally {
|
|
await closeServer();
|
|
}
|
|
},
|
|
);
|
|
});
|