* refactor(browser): share captured-script acquisition boundaries Reuse stable capture/source acquisition and identity validation for module and source-map analysis. Preserve host I/O, malformed input, unavailable source and digest mismatch diagnostics. Refs #851 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * feat(browser): trace captured website source-map locations Refs #851. Preserve selected capture/map byte identity, duplicate mappings and embedded source evidence through the pinned upstream codec. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * test(browser): verify source-map artifacts and synchronize generated contracts Cover byte-preserving map reads and actionable filesystem constraints. Refresh generated public schemas and metadata on current main. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): preserve inert source-map URL context The selected URL is local codec context and grants no transport authority. Preserve its reported text and verify normal/userinfo contexts through real public interfaces, alongside independent manifest byte identity. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
79 lines
2.8 KiB
TypeScript
79 lines
2.8 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect, it } from "vitest";
|
|
import { LocalWebSourceLocationArtifacts } from "../../../src/browser/assets/WebSourceLocationArtifacts.js";
|
|
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
|
import { ok } from "../../../src/domain/result.js";
|
|
import { WEB_SOURCE_MAP_LIMITS } from "../../../src/domain/webSourceLocation.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import {
|
|
webSourceLocationArgs,
|
|
webSourceLocationFixture,
|
|
} from "../../fixtures/webSourceLocation.js";
|
|
|
|
const reader = () => {
|
|
const { sourceMap: _sourceMap, ...script } = webSourceLocationFixture();
|
|
return new LocalWebSourceLocationArtifacts({
|
|
load: () => Promise.resolve(ok(script)),
|
|
});
|
|
};
|
|
it("reads exact selected map bytes, retaining a BOM and explicitly selected URL context", async () => {
|
|
const root = await createTestTempDirectory("rea-map-artifacts-");
|
|
const path = join(root, "app.map");
|
|
const text = '\uFEFF{"version":3,"sources":[],"names":[],"mappings":""}';
|
|
await writeFile(path, text);
|
|
const response = await reader().load({
|
|
...webSourceLocationArgs,
|
|
source_map: { ...webSourceLocationArgs.source_map, path },
|
|
});
|
|
if (!response.ok) throw response.error;
|
|
expect(response.value.sourceMap).toEqual({
|
|
file: {
|
|
path,
|
|
sha256: createHash("sha256").update(text).digest("hex"),
|
|
bytes: Buffer.byteLength(text),
|
|
},
|
|
url: webSourceLocationArgs.source_map.url,
|
|
text,
|
|
});
|
|
});
|
|
it.each(["unavailable", "invalid-utf8", "oversized"])(
|
|
"preserves the selected map reader failure: %s",
|
|
async (variant) => {
|
|
const root = await createTestTempDirectory("rea-map-artifacts-");
|
|
const path = join(root, "app.map");
|
|
if (variant === "invalid-utf8")
|
|
await writeFile(path, Buffer.from([255, 254]));
|
|
if (variant === "oversized")
|
|
await writeFile(
|
|
path,
|
|
Buffer.alloc(WEB_SOURCE_MAP_LIMITS.mapBytes + 1, 32),
|
|
);
|
|
const response = await reader().load({
|
|
...webSourceLocationArgs,
|
|
source_map: { ...webSourceLocationArgs.source_map, path },
|
|
});
|
|
if (response.ok) throw new Error("expected map failure");
|
|
const projection = projectAnalysisError(response.error);
|
|
if (variant === "invalid-utf8")
|
|
expect(projection).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
issues: [
|
|
{
|
|
path: ["source_map", "path"],
|
|
message: expect.stringContaining("UTF-8"),
|
|
},
|
|
],
|
|
},
|
|
});
|
|
else
|
|
expect(response.error).toMatchObject({
|
|
_tag: "ArtifactOperationError",
|
|
reason: variant === "oversized" ? "limit" : "io",
|
|
detail: expect.stringContaining(path),
|
|
});
|
|
},
|
|
);
|