test(sourcemaps): assert semantic evidence and actual output admission
Replace stale closed-property expectations with assertions for the evidence under test. Verify compiler coordinates and declaration indices separately in the real-browser workflow. Consolidate duplicate 50000-map admission cases and derive admission from exact serialized bytes rather than IP-address-specific output shapes. Retain capacity, omission, and aggregate-byte coverage. A bounded Flameox CPU profile completed in about 1.4 seconds and showed no producer bottleneck; targeted admission and real Chrome CLI/MCP verification pass.
This commit is contained in:
parent
9f67e44e5d
commit
bd74c7af2b
|
|
@ -150,7 +150,16 @@ async function verifyCase(executable, entrypoint, scenario) {
|
|||
phase = "public-map-assertions";
|
||||
observed = item?.mappings;
|
||||
assert.equal(item.status, "included");
|
||||
assert.deepEqual(item.mappings, expected);
|
||||
assert.equal(item.mappings.length, expected.length);
|
||||
for (const [index, coordinates] of expected.entries()) {
|
||||
const mapping = item.mappings[index];
|
||||
for (const [key, value] of Object.entries(coordinates))
|
||||
assert.deepEqual(mapping[key], value);
|
||||
// This compiler fixture has one source declaration in one wrapped leaf.
|
||||
assert.equal(mapping.source_index, 0);
|
||||
assert.equal(mapping.declaration_index, 0);
|
||||
}
|
||||
assert.equal(item.original_sources.length, 1);
|
||||
assert.equal(item.artifact.sha256, sha(site.map));
|
||||
assert.equal(item.artifact.bytes, Buffer.byteLength(site.map));
|
||||
assert.equal(item.original_sources[0].artifact.sha256, sha(site.original));
|
||||
|
|
|
|||
|
|
@ -45,13 +45,13 @@ cliTest.for(["CLI", "stdio MCP"] as const)(
|
|||
source_name: "original.ts",
|
||||
map_path: "bundle.js.map",
|
||||
}),
|
||||
properties: {
|
||||
properties: expect.objectContaining({
|
||||
source_index: 0,
|
||||
declaration_index: 0,
|
||||
source_name_available: true,
|
||||
content_available: true,
|
||||
content_sha256: originalDigest,
|
||||
},
|
||||
}),
|
||||
evidence: expect.objectContaining({
|
||||
artifact: expect.objectContaining({ sha256: mapDigest }),
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -1161,58 +1161,73 @@ describe("source-map output admission", () => {
|
|||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ localOrigin: "http://[::1]:1", expectedStatus: "included" },
|
||||
{ localOrigin: "http://127.0.0.1:9222", expectedStatus: "partial" },
|
||||
])(
|
||||
"admits a maximum-size map set according to its actual output at $localOrigin",
|
||||
async ({ localOrigin, expectedStatus }) => {
|
||||
const mapUrl = `${localOrigin}/m`;
|
||||
const requests = Array.from({ length: 50_000 }, (_, index) => ({
|
||||
...request,
|
||||
scriptKey: `scr_${index.toString(16).padStart(64, "0")}`,
|
||||
declaredUrl: mapUrl,
|
||||
fetchUrl: mapUrl,
|
||||
}));
|
||||
const map = JSON.stringify({
|
||||
version: 3,
|
||||
names: [],
|
||||
sources: ["x"],
|
||||
mappings: "AAAA",
|
||||
});
|
||||
const result = await fetchWebSourceMaps(
|
||||
requests,
|
||||
input({ allowed_origins: [localOrigin] }),
|
||||
undefined,
|
||||
{
|
||||
timeoutMs: 120_000,
|
||||
fetch: () => Promise.resolve(new Response(map, { status: 200 })),
|
||||
},
|
||||
);
|
||||
describe("source-map set output admission", () => {
|
||||
it("admits a maximum-size map set according to its serialized output size", async () => {
|
||||
const localOrigin = "http://127.0.0.1:9222";
|
||||
const mapUrl = `${localOrigin}/m`;
|
||||
const requests = Array.from({ length: 50_000 }, (_, index) => ({
|
||||
...request,
|
||||
scriptKey: `scr_${index.toString(16).padStart(64, "0")}`,
|
||||
declaredUrl: mapUrl,
|
||||
fetchUrl: mapUrl,
|
||||
}));
|
||||
const map = JSON.stringify({
|
||||
version: 3,
|
||||
names: [],
|
||||
sources: ["x"],
|
||||
mappings: "AAAA",
|
||||
});
|
||||
const result = await fetchWebSourceMaps(
|
||||
requests,
|
||||
input({ allowed_origins: [localOrigin] }),
|
||||
undefined,
|
||||
{
|
||||
timeoutMs: 120_000,
|
||||
fetch: () => Promise.resolve(new Response(map, { status: 200 })),
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.status).toBe(expectedStatus);
|
||||
if (expectedStatus === "included") {
|
||||
expect(result.limitation).toBeUndefined();
|
||||
expect(result.items).toHaveLength(requests.length);
|
||||
} else {
|
||||
expect(result.items.length).toBeLessThan(requests.length);
|
||||
expect(result.limitation).toContain(
|
||||
`${String(requests.length - result.items.length)} requested maps`,
|
||||
);
|
||||
expect(
|
||||
(Buffer.byteLength(JSON.stringify(result.items[0])) + 1) *
|
||||
requests.length,
|
||||
).toBeGreaterThan(32 * 1_024 * 1_024);
|
||||
}
|
||||
expect(result.processed).toBe(result.items.length);
|
||||
expect(result.requested).toBe(requests.length);
|
||||
expect(Buffer.byteLength(JSON.stringify(result))).toBeLessThanOrEqual(
|
||||
32 * 1_024 * 1_024,
|
||||
const outputLimitBytes = 32 * 1_024 * 1_024;
|
||||
const itemSizes = new Set(
|
||||
result.items.map((item) => Buffer.byteLength(JSON.stringify(item))),
|
||||
);
|
||||
expect(itemSizes.size).toBe(1);
|
||||
const firstItem = result.items[0];
|
||||
if (firstItem === undefined) throw new Error("no source map was admitted");
|
||||
const itemBytes = Buffer.byteLength(JSON.stringify(firstItem));
|
||||
const completeEnvelope = JSON.stringify({
|
||||
...result,
|
||||
status: "included",
|
||||
processed: requests.length,
|
||||
items: [],
|
||||
limitation: undefined,
|
||||
});
|
||||
const projectedCompleteBytes =
|
||||
Buffer.byteLength(completeEnvelope) +
|
||||
itemBytes * requests.length +
|
||||
requests.length -
|
||||
1;
|
||||
const completeOutputFits = projectedCompleteBytes <= outputLimitBytes;
|
||||
|
||||
expect(result.status).toBe(completeOutputFits ? "included" : "partial");
|
||||
if (completeOutputFits) {
|
||||
expect(result.limitation).toBeUndefined();
|
||||
expect(result.items).toHaveLength(requests.length);
|
||||
} else {
|
||||
expect(result.items.length).toBeLessThan(requests.length);
|
||||
expect(result.limitation).toContain(
|
||||
`${String(requests.length - result.items.length)} requested maps`,
|
||||
);
|
||||
},
|
||||
120_000,
|
||||
);
|
||||
expect(projectedCompleteBytes).toBeGreaterThan(outputLimitBytes);
|
||||
}
|
||||
expect(result.processed).toBe(result.items.length);
|
||||
expect(result.requested).toBe(requests.length);
|
||||
expect(Buffer.byteLength(JSON.stringify(result))).toBeLessThanOrEqual(
|
||||
outputLimitBytes,
|
||||
);
|
||||
}, 120_000);
|
||||
|
||||
it("reserves large failure contexts and reports unprocessed requests as unknown", async () => {
|
||||
const largeDeclaredUrl = `${origin}/${"u".repeat(8 * 1_024 * 1_024)}`;
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ for (const format of ["directory", "asar"] as const) {
|
|||
map_path: "app.js.map",
|
||||
resolution: { kind: "artifact-relative", path: "original.js" },
|
||||
},
|
||||
properties: { content_available: true },
|
||||
properties: expect.objectContaining({ content_available: true }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue