Files
reverse-engineering-anything/src/javascript/sourceMaps/SourceMapAdmission.test.ts
T
morluto cb4e5cfbff feat(analysis): make resource budgets recoverable across CLI and MCP (#9706)
* refactor(analysis): centralize resource budgets and recovery facts

* feat(analysis): expose ASAR and Ghidra runtime admission controls

* feat(artifacts): expose reader admission and preserve limited recognition

* feat(javascript): expose recoverable semantic precision budgets

* feat(web): add recoverable source-map budgets and compact retained views

* feat(web): make historical capture decoding budgets recoverable

* fix(desktop): enforce selected view policies across capture and export

* feat(runtime): make Frida and LLDB retention budgets selectable

* feat(native): expose diagnostic budgets and preserve exhaustion causes

* feat(managed): expose recoverable snapshot and representation budgets

* feat(metadata): make Go and Rust inspection budgets recoverable

* feat(wasm): expose representation and producer admissions

* feat(evm): expose per-call worker resource budgets

* feat(android): make resource and string-pool omissions recoverable

* feat(producers): expose command and recorded-capture budgets

* docs(analysis): record recovery contracts and integrated validation

* fix(docs): link calibration oracle from published verification pages

* fix(docs): restore desktop task anchors and receipt links

* test(analysis): align fixtures with selectable budget contracts

* fix(analysis): remove source-location projector dependency cycle

* test(analysis): refresh budget recovery and verifier regressions

* test(analysis): preserve format and publication recovery expectations

* test(windows): align conformance with owned runtime admission

* fix(desktop): preserve selected alias kinds in exported state

* test(analysis): align provider fixtures with recoverable budgets

* test(desktop): validate emitted alias metadata structurally

* fix(ghidra): classify bounded Windows endpoint refusals

* test(cli): assert selectable artifact admission recovery

* fix(cli): preserve capture provenance in environment builds
2026-11-10 05:11:20 -05:00

129 lines
3.9 KiB
TypeScript

import { webSourceLocationInputSchema } from "../../domain/webSourceLocation.js";
import { analyzeWebBundleInputSchema } from "../../domain/webBundleAnalysis.js";
import { webSourceLocationArgs } from "../../../tests/fixtures/webSourceLocation.js";
import { selectedSourceMapLimits } from "../../domain/sourceMapLimits.js";
import { expect, it } from "vitest";
import { inspectSourceMapEnvelope } from "../../domain/sourceMapEnvelope.js";
import { inspectSourceMapValue } from "./SourceMapFormat.js";
import { traceSourceMap } from "./TraceSourceMap.js";
const leaf = {
version: 3,
sources: ["original.ts"],
sourcesContent: ["hello"],
mappings: "AAAA",
};
const indexed = (map: unknown) => ({
version: 3,
sections: [{ offset: { line: 0, column: 0 }, map }],
});
it.each([2, null, undefined, "3"])(
"rejects nested indexed version %s consistently",
(version) => {
const map = indexed({ ...indexed(leaf), version });
expect(inspectSourceMapEnvelope(map)).toMatchObject({
status: "malformed",
invalid_sections: [{ section_path: [0] }],
});
for (const profile of [undefined, "browser-collection"] as const)
expect(() =>
inspectSourceMapValue(map, profile === undefined ? {} : { profile }),
).toThrow(expect.objectContaining({ reason: "format" }));
expect(() =>
traceSourceMap(JSON.stringify(map), "https://example.test/main.js.map", {
line: 1,
column: 0,
}),
).toThrow(expect.objectContaining({ reason: "format" }));
},
);
it("admits numeric version 3 through the same consumers", () => {
const map = indexed(indexed(leaf));
expect(inspectSourceMapEnvelope(map)).toMatchObject({ status: "included" });
expect(
inspectSourceMapValue(map, { profile: "browser-collection" }).leaves,
).toHaveLength(1);
expect(
traceSourceMap(JSON.stringify(map), "https://example.test/main.js.map", {
line: 1,
column: 0,
}).matches,
).toMatchObject([{ section_path: [0, 0], reported_source: "original.ts" }]);
});
it("recovers the same finite map by raising the exact decoder record admission", () => {
const text = JSON.stringify({
version: 3,
sources: ["a.ts"],
sourcesContent: ["original"],
names: [],
mappings: "AAAA",
});
const position = { line: 1, column: 0 };
expect(() =>
traceSourceMap(
text,
"https://example.test/app.map",
position,
selectedSourceMapLimits({ decoded_records: 4 }),
),
).toThrow(
expect.objectContaining({
reason: "limit",
message: expect.stringContaining(
"source_map_limits.decoded_records is 4",
),
}),
);
expect(
traceSourceMap(
text,
"https://example.test/app.map",
position,
selectedSourceMapLimits({ decoded_records: 5 }),
).matches,
).toMatchObject([{ reported_source: "a.ts", content: { text: "original" } }]);
});
it("rejects invalid and inapplicable budget selections at the public owning contracts", () => {
for (const selection of [
{ map_bytes: 0 },
{ output_bytes: 536870888 },
{ decoded_records: 0 },
{ decoded_records: undefined },
{ codec_heap_mib: 127 },
{ fetch_bytes: 1024 },
]) {
expect(
webSourceLocationInputSchema.safeParse({
...webSourceLocationArgs,
source_map_limits: selection,
}).success,
).toBe(false);
}
const bundle = {
cdp_endpoint: "http://127.0.0.1:9222",
allowed_origins: ["https://app.test"],
target_id: "page",
fetch_source_maps: true,
};
expect(
analyzeWebBundleInputSchema.safeParse({
...bundle,
fetch_source_maps: false,
source_map_limits: { decoded_records: 5 },
}).success,
).toBe(false);
for (const selection of [{ map_bytes: 1024 }, { codec_heap_mib: 256 }]) {
expect(
analyzeWebBundleInputSchema.safeParse({
...bundle,
source_map_limits: selection,
}).success,
).toBe(false);
}
});