refactor(input): share schema issue error construction

This commit is contained in:
morluto
2026-10-09 00:49:30 +08:00
parent 3c157b4ec6
commit 65a6288257
19 changed files with 115 additions and 124 deletions
+29 -1
View File
@@ -1,10 +1,38 @@
import { describe, expect, it } from "vitest";
import { z } from "zod";
import { projectInputIssues } from "./inputIssueProjection.js";
import {
analysisInputErrorFromIssues,
projectInputIssues,
} from "./inputIssueProjection.js";
import { processScenarioSchema } from "./process/processScenario.js";
describe("input issue projection", () => {
it("builds application input errors with projected and semantic issues", () => {
const schema = z.object({ count: z.number().int() });
const input = { count: "invalid" };
const parsed = schema.safeParse(input);
if (parsed.success) throw new Error("expected invalid input");
const cause = parsed.error;
const error = analysisInputErrorFromIssues(
"inspect_fixture",
parsed.error.issues,
input,
{
cause,
additionalIssues: [
{ path: ["count"], reason: "out_of_range", minimum: 0 },
],
},
);
expect(error.cause).toBe(cause);
expect(error.issues).toEqual([
{ path: ["count"], reason: "invalid_type", expected: "number" },
{ path: ["count"], reason: "out_of_range", minimum: 0 },
]);
});
it("preserves static regex guidance without echoing the rejected value", () => {
const schema = z.object({
value: z.string().regex(/^[^\0]*$/u, "Values cannot contain NUL"),