Files
rea/scripts/lib/browser-nested-source-map-e2e.mjs
T
morluto 72ba1cd92b fix(verifiers): centralize failure and cleanup ownership
Own operation results and exact rejections in withVerifierCleanup, including
undefined, null and independent cleanup failures. Remove the optional-primary
cleanup contract and migrate every caller, preserving returns, annotations,
signal restoration and dependent cleanup order.

Make Frida/JEB reporters fail on reasonless rejections and retain JEB fixture
files while provider cleanup is incomplete. Own the nested packaged WASM
verifier and expose its composite process/root cleanup capability for retry.
Update runnable docs and isolated fixture dependencies.

Validation: 547 focused cases in 20 files, eight isolated boundary unit checks,
static/build/docs/discovery gates and duplication check (3.58%). Node process,
SDK and descriptor cleanup are exercised; provider and packaging results in
orchestration tests are simulated. Pack/install subprocess ownership remains
with the existing shared package runner outside the nested-command change.
2026-10-24 15:38:35 +08:00

239 lines
8.7 KiB
JavaScript

import assert from "node:assert/strict";
import { execFile } from "node:child_process";
import { createHash } from "node:crypto";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { TraceMap, eachMapping } from "@jridgewell/trace-mapping";
import { CdpBrowserProvider } from "../../dist/browser/CdpBrowserProvider.js";
import { listBrowserTargetsInputSchema } from "../../dist/domain/browserObservation.js";
import { CdpConnection } from "../../dist/browser/CdpConnection.js";
import { parseEvidence } from "../../dist/domain/evidence.js";
import { traceSourceMap } from "../../dist/javascript/sourceMaps/TraceSourceMap.js";
import { startBrowserSourceMapSite } from "../fixtures/browser-source-map-site.mjs";
import { startRuntimeFixtureBrowser } from "./browser-runtime-fixture-lifecycle.mjs";
import { withVerifierCleanup } from "./verifier-cleanup.mjs";
const cases = [
{ name: "same-line nested column control", prefixes: ["\n\n ", " "] },
{ name: "zero outer column control", prefixes: ["\n\n", "\n "] },
{ name: "nested line resets outer column", prefixes: ["\n\n ", "\n"] },
{
name: "nested line retains its own column",
prefixes: ["\n\n ", "\n "],
},
];
/** Verify compiler-produced nested maps through an actual owned Chrome and public CLI. */
export async function verifyBrowserNestedSourceMaps(
executable,
entrypoint = fileURLToPath(new URL("../rea.mjs", import.meta.url)),
) {
const results = [];
for (const scenario of cases) {
try {
const proof = await verifyCase(executable, entrypoint, scenario);
results.push({ name: scenario.name, status: "pass", ...proof });
} catch (cause) {
results.push({
name: scenario.name,
status: "fail",
phase: cause.qualificationPhase ?? "native-producer-admission",
proof: cause.qualificationReceipt ?? null,
error: String(cause),
});
}
}
// Preserve every affected owner and control even when BEFORE fails.
process.stdout.write(
`${JSON.stringify({ nested_source_map_cases: results })}\n`,
);
assert.equal(results.filter(({ status }) => status === "fail").length, 0);
return { cases: results, actual_chrome: true, public_cli: true };
}
async function verifyCase(executable, entrypoint, scenario) {
const site = await startBrowserSourceMapSite({
prefixes: scenario.prefixes,
sourceMapAnnotation: true,
sourcefile: "../src/nested-fixture.ts",
});
let fixture;
let connection;
let phase = "native-map-admission";
let browserVersion;
let expected;
let observed;
return withVerifierCleanup(async () => {
try {
const mapUrl = `${site.origin}/maps/app.js.map`;
// This independent existing decoder already composes valid nested offsets.
// It is a before-product admission control, not the expected browser oracle.
const point = traceSourceMap(site.map, mapUrl, site.position);
assert.equal(point.matches.length, 1);
assert.equal(
point.matches[0].original_position.line,
site.originalPosition.line,
);
assert.equal(
point.matches[0].original_position.column,
site.originalPosition.column,
);
expected = compilerMappingsAtPhysicalPositions(site, mapUrl);
assert.ok(
expected.length > 0,
"Native compiler leaf must carry point mappings",
);
phase = "owned-browser-startup";
fixture = await startRuntimeFixtureBrowser(executable, site.origin);
const endpoint = `http://127.0.0.1:${fixture.port}`;
const provider = new CdpBrowserProvider();
const targets = await provider.listTargets(
listBrowserTargetsInputSchema.parse({
cdp_endpoint: endpoint,
allowed_origins: [site.origin],
</