Files
rea/tests/boundary/filesystem/peResources.test.ts
T
Kaoru0822andClaude Opus 5.5 e1def2bf1a fix(native): report missing and non-file PE resource targets as input errors
`inspect_pe_resources` turned every acquisition failure other than
limits and access denial into `artifact_operation_failed` with "Artifact
could not be read or written. Check file access and try again." A
missing path, a directory, a symlink or a path under a regular file got
that advice, although the caller selected a target that cannot be a PE
image.

Map the stable reader's non-regular-file refusal and ENOENT/ENOTDIR to
`AnalysisInputError` issues on `path`, and a file that changed during the
read to `AnalysisArtifactChangedError`, as the sibling EVM carrier read
does. Other I/O failures stay artifact faults.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-11 02:30:25 +00:00

59 lines
2.3 KiB
TypeScript

import { symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { createPeResourcesService } from "../../../src/composition/binaryDiagnostics.js";
import { peResourceFixture } from "../../../src/native/pe/PeResources.fixture.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
describe("PE resource stable filesystem boundary", () => {
it("rejects symlinks, missing files and directories as caller input without inventing empty inventory", async () => {
const root = await createTestTempDirectory("rea-pe-resource-files-");
const path = join(root, "image.exe");
const alias = join(root, "alias.exe");
await writeFile(path, peResourceFixture().bytes);
await symlink(path, alias);
const service = createPeResourcesService();
for (const [candidate, reason] of [
[root, "invalid_format"],
[alias, "invalid_format"],
[join(root, "missing.exe"), "invalid_value"],
[join(path, "child.exe"), "invalid_value"],
] as const) {
const result = await service.inspect({ path: candidate });
if (result.ok) throw new Error("Expected file acquisition failure");
expect(result.error).toMatchObject({
_tag: "AnalysisInputError",
operation: "inspect_pe_resources",
issues: [
{
path: ["path"],
reason,
message: expect.stringContaining(candidate),
},
],
});
}
});
it("returns typed resource and cancellation failures", async () => {
const root = await createTestTempDirectory("rea-pe-resource-budget-");
const path = join(root, "image.exe");
await writeFile(path, peResourceFixture().bytes);
const service = createPeResourcesService();
for (const input of [
{ path, max_file_bytes: 64 },
{ path, max_entries: 1 },
]) {
const result = await service.inspect(input);
if (result.ok) throw new Error("Expected resource budget failure");
expect(result.error._tag).toBe("AnalysisResourceConstraintError");
}
const result = await service.inspect(
{ path },
{ signal: AbortSignal.abort() },
);
if (result.ok) throw new Error("Expected cancellation");
expect(result.error._tag).toBe("AnalysisCancelledError");
});
});