mirror of
https://github.com/morluto/rea
synced 2026-10-27 06:33:32 -04:00
2b6e9ec03f
trace_web_module_imports and trace_web_source_location reported a missing
or non-file manifest, source map or import map as artifact_operation_failed
("Artifact could not be read or written" / "unsafe or conflicting internal
path"). These are caller selections: report ENOENT/ENOTDIR and non-regular
files as invalid input on the selected field, and EACCES/EPERM as a host
access denial. A missing manifest-derived source file stays an artifact fault.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
84 lines
3.0 KiB
TypeScript
84 lines
3.0 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 === "oversized")
|
|
expect(response.error).toMatchObject({
|
|
_tag: "ArtifactOperationError",
|
|
reason: "limit",
|
|
detail: expect.stringContaining(path),
|
|
});
|
|
else
|
|
expect(projection).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
issues: [
|
|
{
|
|
path: ["source_map", "path"],
|
|
...(variant === "unavailable"
|
|
? { reason: "invalid_value" }
|
|
: { reason: "invalid_format" }),
|
|
message: expect.stringContaining(
|
|
variant === "unavailable" ? `(ENOENT): ${path}` : "UTF-8",
|
|
),
|
|
},
|
|
],
|
|
},
|
|
});
|
|
},
|
|
);
|