* fix(managed): keep caller-input details in managed workflow errors
The managed workflows wrapped every rejected input as
`new AnalysisInputError(op, { cause })` with no issues. The projected
result said "Correct the listed arguments and retry" and listed nothing:
- `rea import-managed-reconstruction`,
`rea project-managed-application-graph` and
`rea verify-managed-native-boundaries` lost every schema issue for
malformed JSON;
- domain checks such as a reconstruction text hash mismatch, or Evidence
from the wrong operation, lost their message on CLI and MCP;
- `rea compare-managed-members` with a missing file did not say which
path failed.
Add managedInputError, which projects Zod issues with their paths and
keeps a domain TypeError's message, as the JavaScript workflows already
do. Return the BinaryTargetError from an unopenable comparison path
unchanged, with details.path, as every other path-based command does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(managed): keep nested Evidence schema issues off request paths
A ZodError raised after the request parsed comes from a nested
Evidence result, so its issue paths are relative to that result.
Projecting it against the whole request reported, for example,
artifact.sha256 as a missing request field. Keep request-relative
projection for the raw request's schema failures. Report nested schema
failures as root issues whose message names the nested location.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(managed): type the malformed nested Evidence fixture
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(workflows): keep input details in the remaining workflow services
Inventory projection (project_android_application_graph and
project_apple_application_graph), build_reconstruction_obligation_ledger
and evaluate_reconstruction_coverage had the same issue-less
`AnalysisInputError({ cause })` as the managed services. For example,
evaluating coverage for an unknown boundary returned "Correct the listed
arguments" with no issues, dropping "Unknown reconstruction boundary: X"
on CLI and MCP.
Move the helpers to src/application/workflowInputError.ts and use them
for these services: requestInputError for raw request schema failures,
workflowInputError for nested schema and domain constraint failures.
Classification is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
177 lines
6.6 KiB
TypeScript
177 lines
6.6 KiB
TypeScript
import { readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
|
|
|
import {
|
|
compareManagedMembersEvidenceValidated,
|
|
compareManagedMemberPaths,
|
|
} from "../../../../src/application/managed/ManagedMemberComparisonService.js";
|
|
import { parseBinaryTarget } from "../../../../src/application/BinaryTargetResolver.js";
|
|
import { managedMemberComparisonResultSchema } from "../../../../src/domain/managed/managedMemberComparison.js";
|
|
import { createEvidence } from "../../../../src/domain/evidence.js";
|
|
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
|
import { jsonValueSchema } from "../../../../src/domain/jsonValue.js";
|
|
import { compareManagedMembersInputSchema } from "../../../../src/domain/managed/managedMemberComparison.js";
|
|
import { inspectManagedMembersBytes } from "../../../../src/dotnet/ManagedMemberInspector.js";
|
|
import { managedPeFixtureTarget } from "../../../../src/dotnet/ManagedPe.fixture.js";
|
|
import { buildManagedPeFixture } from "../../../../src/dotnet/ManagedPe.fixture.js";
|
|
|
|
it.each([
|
|
["accessibility", 6, 0x0011],
|
|
["synchronized implementation", 4, 0x0020],
|
|
])(
|
|
"reports changed observed method %s despite identical CIL",
|
|
async (_name, flagOffset, flags) => {
|
|
const directory = await createTestTempDirectory("rea-managed-flags-");
|
|
const leftPath = join(directory, "left.dll");
|
|
const rightPath = join(directory, "right.dll");
|
|
const left = buildManagedPeFixture();
|
|
const inspection = inspectManagedMembersBytes(
|
|
left,
|
|
managedPeFixtureTarget(left, leftPath),
|
|
);
|
|
const method = inspection.methods[0];
|
|
if (method === undefined) throw new Error("missing method fixture");
|
|
const right = Buffer.from(left);
|
|
right.writeUInt16LE(flags, method.row_offset + flagOffset);
|
|
await writeFile(leftPath, left);
|
|
await writeFile(rightPath, right);
|
|
const result = await compareManagedMemberPaths({ leftPath, rightPath });
|
|
expect(result.ok).toBe(true);
|
|
if (!result.ok) return;
|
|
const comparison = managedMemberComparisonResultSchema.parse(
|
|
result.value.normalized_result,
|
|
);
|
|
expect(comparison.methods[0]).toMatchObject({
|
|
status: "changed",
|
|
dimensions: ["metadata"],
|
|
});
|
|
expect(comparison.methods[0]?.left?.normalized_il_sha256).toBe(
|
|
comparison.methods[0]?.right?.normalized_il_sha256,
|
|
);
|
|
},
|
|
);
|
|
|
|
describe("managed member comparison path workflow", () => {
|
|
it("preserves undecoded signatures as unknown through content-addressed partial Evidence", () => {
|
|
const observe = (signature: number, path: string) => {
|
|
const bytes = buildManagedPeFixture({
|
|
methodSignature: Buffer.from([signature]),
|
|
});
|
|
const target = managedPeFixtureTarget(bytes, path);
|
|
const inspection = inspectManagedMembersBytes(bytes, target);
|
|
return createEvidence(
|
|
target,
|
|
{ id: "partial-fixture", name: "Partial fixture", version: "1" },
|
|
{
|
|
operation: "inspect_managed_members",
|
|
parameters: {},
|
|
result: jsonValueSchema.parse({
|
|
...inspection,
|
|
coverage: { ...inspection.coverage, state: "partial" },
|
|
}),
|
|
confidence: "observed",
|
|
authority: "shipped-artifact",
|
|
},
|
|
);
|
|
};
|
|
const input = compareManagedMembersInputSchema.parse({
|
|
left: observe(0xff, "/tmp/partial-left.dll"),
|
|
right: observe(0xfe, "/tmp/partial-right.dll"),
|
|
});
|
|
const result = compareManagedMembersEvidenceValidated(input);
|
|
expect(result.ok).toBe(true);
|
|
if (!result.ok) return;
|
|
const comparison = managedMemberComparisonResultSchema.parse(
|
|
result.value.normalized_result,
|
|
);
|
|
expect(comparison.coverage.status).toBe("partial");
|
|
expect(comparison.matching.structural_method_shape).toBe(0);
|
|
expect(comparison.methods).toHaveLength(2);
|
|
expect(
|
|
comparison.methods.every(
|
|
({ status, match }) =>
|
|
status === "unknown" && match.status === "unmatched",
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("compares two local paths and returns derived Evidence", async () => {
|
|
const directory = await createTestTempDirectory("rea-managed-compare-");
|
|
const leftPath = join(directory, "left.dll");
|
|
const rightPath = join(directory, "right.dll");
|
|
await writeFile(leftPath, buildManagedPeFixture());
|
|
await writeFile(
|
|
rightPath,
|
|
buildManagedPeFixture({ methodName: "Renamed" }),
|
|
);
|
|
|
|
const result = await compareManagedMemberPaths({
|
|
leftPath,
|
|
rightPath,
|
|
});
|
|
|
|
expect(result.ok).toBe(true);
|
|
if (!result.ok) return;
|
|
expect(result.value).toMatchObject({
|
|
operation: "compare_managed_members",
|
|
confidence: "inferred",
|
|
authority: "analyst-inference",
|
|
});
|
|
expect(
|
|
managedMemberComparisonResultSchema.parse(result.value.normalized_result)
|
|
.matching.exact_il_signature,
|
|
).toBe(1);
|
|
});
|
|
|
|
it("reports an unopenable path with the path that failed", async () => {
|
|
const directory = await createTestTempDirectory("rea-managed-missing-");
|
|
const leftPath = join(directory, "missing.dll");
|
|
const rightPath = join(directory, "right.dll");
|
|
await writeFile(rightPath, buildManagedPeFixture());
|
|
|
|
const result = await compareManagedMemberPaths({ leftPath, rightPath });
|
|
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) return;
|
|
expect(result.error._tag).toBe("BinaryTargetError");
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
details: { path: expect.stringContaining("missing.dll") },
|
|
});
|
|
});
|
|
|
|
it("rejects a file that changes after target identity is resolved", async () => {
|
|
const directory = await createTestTempDirectory(
|
|
"rea-managed-compare-race-",
|
|
);
|
|
const leftPath = join(directory, "left.dll");
|
|
const rightPath = join(directory, "right.dll");
|
|
await writeFile(leftPath, buildManagedPeFixture());
|
|
await writeFile(rightPath, buildManagedPeFixture());
|
|
const replacement = buildManagedPeFixture({
|
|
methodName: "ChangedAfterOpen",
|
|
});
|
|
|
|
const result = await compareManagedMemberPaths(
|
|
{ leftPath, rightPath },
|
|
{
|
|
resolveTarget: async (path) => {
|
|
const target = await parseBinaryTarget(path);
|
|
if (target.ok && path === leftPath)
|
|
await writeFile(path, replacement);
|
|
return target;
|
|
},
|
|
readBytes: (path) => readFile(path),
|
|
},
|
|
);
|
|
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) return;
|
|
expect(result.error._tag).toBe("EvidenceIntegrityError");
|
|
expect(result.error.message).toContain(leftPath);
|
|
});
|
|
});
|