fix(browser): classify selected web trace file failures by cause (#1396)

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>
This commit is contained in:
Kaoru0822
2026-10-09 19:29:31 -07:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 498cec042a
commit 2b6e9ec03f
6 changed files with 138 additions and 18 deletions
@@ -1,6 +1,14 @@
import { mkdir, readFile, rename, symlink, writeFile } from "node:fs/promises";
import {
chmod,
mkdir,
readFile,
rename,
rm,
symlink,
writeFile,
} from "node:fs/promises";
import { dirname, join } from "node:path";
import { describe, expect, it } from "vitest";
import { describe, expect, it, onTestFinished } from "vitest";
import { exportWebScripts } from "../../../src/application/WebScriptExportService.js";
import { LocalWebModuleArtifacts } from "../../../src/browser/modules/WebModuleArtifacts.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
@@ -163,20 +171,86 @@ describe("selected captured module artifact boundary", () => {
await writeFile(map, "[]");
expect((await new LocalWebModuleArtifacts().load(input)).ok).toBe(false);
});
it("preserves missing filesystem diagnostics separately from malformed input", async () => {
});
describe("caller-selected web module files", () => {
const selectionIssue = (field: readonly string[], message: string) => ({
code: "invalid_request",
details: {
issues: [
{
path: field,
reason: "invalid_value",
message: expect.stringContaining(message),
},
],
},
});
it("reports a missing or non-file manifest selection as invalid input", async () => {
const root = await createTestTempDirectory("rea-module-missing-");
await mkdir(join(root, "directory"));
const missing = join(root, "missing.json");
const directory = join(root, "directory");
await mkdir(directory);
for (const [manifest_path, message] of [
[missing, `(ENOENT): ${missing}`],
[join(missing, "manifest.json"), "(ENOENT)"],
[directory, `Expected a regular file without a symlink: ${directory}`],
] as const) {
const response = await new LocalWebModuleArtifacts().load({
manifest_path,
script_index: 0,
});
if (response.ok) throw new Error("expected selection failure");
expect(projectAnalysisError(response.error)).toMatchObject(
selectionIssue(["manifest_path"], message),
);
}
});
it.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
"reports an unreadable manifest as a host access denial",
async () => {
const { manifestPath } = await fixture();
await chmod(manifestPath, 0o000);
onTestFinished(() => chmod(manifestPath, 0o600));
const response = await new LocalWebModuleArtifacts().load({
manifest_path: manifestPath,
script_index: 0,
});
if (response.ok) throw new Error("expected access denial");
expect(projectAnalysisError(response.error)).toMatchObject({
code: "access_denied",
details: { path: manifestPath, system_code: "EACCES" },
});
},
);
it("reports a missing import map selection as invalid input", async () => {
const { root, manifestPath } = await fixture();
const map = join(root, "missing-import-map.json");
const response = await new LocalWebModuleArtifacts().load({
manifest_path: join(root, "missing.json"),
manifest_path: manifestPath,
script_index: 0,
import_map: { path: map, base_url: "https://app.test/" },
});
if (response.ok) throw new Error("expected missing import map");
expect(projectAnalysisError(response.error)).toMatchObject(
selectionIssue(["import_map", "path"], `(ENOENT): ${map}`),
);
});
it("keeps a missing manifest-derived source as an artifact fault", async () => {
const { manifestPath, sourcePath } = await fixture();
await rm(sourcePath);
const response = await new LocalWebModuleArtifacts().load({
manifest_path: manifestPath,
script_index: 0,
});
if (response.ok) throw new Error("expected missing file");
if (response.ok) throw new Error("expected missing source");
expect(response.error).toMatchObject({
_tag: "ArtifactOperationError",
reason: "io",
});
expect(projectAnalysisError(response.error).details?.detail).toContain(
"ENOENT",
);
});
});
@@ -56,23 +56,28 @@ it.each(["unavailable", "invalid-utf8", "oversized"])(
});
if (response.ok) throw new Error("expected map failure");
const projection = projectAnalysisError(response.error);
if (variant === "invalid-utf8")
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"],
message: expect.stringContaining("UTF-8"),
...(variant === "unavailable"
? { reason: "invalid_value" }
: { reason: "invalid_format" }),
message: expect.stringContaining(
variant === "unavailable" ? `(ENOENT): ${path}` : "UTF-8",
),
},
],
},
});
else
expect(response.error).toMatchObject({
_tag: "ArtifactOperationError",
reason: variant === "oversized" ? "limit" : "io",
detail: expect.stringContaining(path),
});
},
);