fix(errors): preserve actionable analysis diagnostics

This commit is contained in:
morluto
2026-07-29 07:18:29 +00:00
parent 969519c00f
commit 0f96bf365c
9 changed files with 119 additions and 6 deletions
+57 -1
View File
@@ -242,6 +242,61 @@ describe("analysis error projection", () => {
).toEqual([]);
});
it("gives missing residual unknowns a lookup-specific remediation", () => {
expect(
projectAnalysisError(new UnknownRegistryError("not-found")),
).toMatchObject({
code: "execution_failure",
message:
"The requested residual unknown does not exist in this session. Check the unknown_id and try again.",
remediation: {
action:
"Check that the unknown_id belongs to this session, then retry.",
},
details: { reason: "not-found" },
});
});
it("retains custom input guidance in the projected error details", () => {
expect(
projectAnalysisError(
new AnalysisInputError("find_changed_behavior", undefined, [
{
path: [],
reason: "invalid_value",
message:
"Supply either existing comparisons or one investigation_run",
},
]),
),
).toMatchObject({
details: {
issues: [
{
path: [],
reason: "invalid_value",
message:
"Supply either existing comparisons or one investigation_run",
},
],
},
});
});
it("distinguishes disabled integrity continuation from format support", () => {
expect(
projectAnalysisError(
new ArtifactOperationError("inventory_artifact", "policy"),
),
).toMatchObject({
code: "artifact_operation_failed",
category: "unavailable",
message: expect.stringContaining(
"REA_ARTIFACT_INTEGRITY_CONTINUE_ENABLED=true",
),
});
});
it("validates every closed error-reason variant against the generated contract", () => {
const variants: AnalysisError[] = [
...(
@@ -251,6 +306,7 @@ describe("analysis error projection", () => {
"integrity",
"limit",
"path",
"policy",
"unavailable",
"io",
] as const
@@ -313,7 +369,7 @@ describe("analysis error projection", () => {
).map((diagnostic) => new HopperRemoteError(9, "safe", diagnostic)),
];
expect(variants).toHaveLength(38);
expect(variants).toHaveLength(39);
for (const variant of variants) {
const projected = projectAnalysisError(variant);
const parsed = analysisErrorProjectionSchema.safeParse(projected);
+40
View File
@@ -0,0 +1,40 @@
import { describe, expect, it } from "vitest";
import { z } from "zod";
import { artifactExtractionInputSchema } from "../src/contracts/artifactToolContracts.js";
import { projectInputIssues } from "../src/domain/inputIssueProjection.js";
describe("input issue projection", () => {
it("preserves schema-authored custom correction guidance", () => {
const schema = z
.object({ left: z.string().optional(), right: z.string().optional() })
.superRefine((value, context) => {
if (value.left === undefined && value.right === undefined)
context.addIssue({
code: "custom",
path: [],
message: "Supply either left or right",
});
});
const parsed = schema.safeParse({});
if (parsed.success) throw new Error("expected invalid input");
expect(projectInputIssues(parsed.error.issues, {})).toEqual([
{
path: [],
reason: "invalid_value",
message: "Supply either left or right",
},
]);
});
it("rejects relative extraction destinations at the caller boundary", () => {
expect(
artifactExtractionInputSchema.safeParse({
approved: true,
output_root: "relative/output",
occurrence_ids: [`occ_${"0".repeat(64)}`],
}).success,
).toBe(false);
});
});