fix: report malformed application evidence as input errors

This commit is contained in:
morluto
2026-10-10 03:52:35 +08:00
parent 55a46f7c71
commit 218c13160e
15 changed files with 613 additions and 165 deletions
@@ -313,7 +313,7 @@ describe("evidence bundle filesystem adapter", () => {
error: {
_tag: "EvidenceIntegrityError",
userMessage: expect.stringContaining(
"Evidence semantic identifier does not match its record",
"at records.0.evidence_id: Evidence semantic identifier does not match its record",
),
},
});
@@ -320,7 +320,7 @@ describe("complete comparison projections", () => {
});
describe("JavaScript application workflow error diagnostics", () => {
it("returns safe explicit Evidence constraints from graph workflows", async () => {
it("identifies the inconsistent Evidence subject in graph workflows", async () => {
const root = await createTestTempDirectory(
"rea-application-workflow-diagnostics-",
);
@@ -328,10 +328,10 @@ describe("JavaScript application workflow error diagnostics", () => {
const evidence = await analyzeFixture(root);
const subject = evidence.subject;
if (subject === null) throw new Error("Analysis Evidence subject missing");
const secretPath = "/private/token=do-not-return";
const inconsistentPath = "/different/application.js";
const inconsistent = {
...evidence,
subject: { ...subject, local_path: secretPath },
subject: { ...subject, local_path: inconsistentPath },
};
const result = traceApplicationFeatureEvidence({
@@ -346,11 +346,10 @@ describe("JavaScript application workflow error diagnostics", () => {
expect(result.error.issues).toContainEqual(
expect.objectContaining({
reason: "invalid_value",
message:
"JavaScript application Evidence subject does not match its result",
path: ["application", "subject"],
message: expect.stringContaining("subject must match"),
}),
);
expect(JSON.stringify(result.error.issues)).not.toContain(secretPath);
});
it("preserves schema-authored Evidence validation messages", async () => {
@@ -232,7 +232,9 @@ const analyzeReturn = async (root: string, properties: string) => {
await writeFixtureFiles(root, { "parser.mjs": `${prefix}${expression});\n` });
const analyzed = await analyzeJavaScriptApplication({ input_path: root });
if (!analyzed.ok) throw analyzed.error;
const source = parseApplicationGraphEvidence(analyzed.value);
const parsed = parseApplicationGraphEvidence(analyzed.value);
if (!parsed.ok) throw new Error("Analysis Evidence must parse");
const source = parsed.value;
const observation = source.graph.nodes
.flatMap(({ observations }) => observations)
.find(
@@ -938,7 +938,9 @@ const analyzeGraph = async (root: string) => {
input_path: root,
});
if (!result.ok) throw result.error;
return parseApplicationGraphEvidence(result.value);
const parsed = parseApplicationGraphEvidence(result.value);
if (!parsed.ok) throw new Error("Analysis Evidence must parse");
return parsed.value;
};
const analyzeSources = async (
@@ -15,7 +15,9 @@ const analyze = async (root: string) => {
format: "directory",
});
if (!result.ok) throw result.error;
const authenticated = parseApplicationGraphEvidence(result.value);
const parsed = parseApplicationGraphEvidence(result.value);
if (!parsed.ok) throw new Error("Analysis Evidence must parse");
const authenticated = parsed.value;
return {
graph: authenticated.graph,
result: javascriptApplicationAnalysisResultSchema.parse(
@@ -668,9 +668,16 @@ it("rejects static application Evidence whose subject path disagrees with its re
},
};
expect(() => parseApplicationGraphEvidence(inconsistent)).toThrow(
"JavaScript application Evidence subject does not match its result",
);
const parsed = parseApplicationGraphEvidence(inconsistent);
expect(parsed.ok).toBe(false);
if (!parsed.ok)
expect(parsed.error.issues).toContainEqual(
expect.objectContaining({
path: ["subject"],
reason: "invalid_value",
message: expect.stringContaining("subject must match"),
}),
);
});
const compareTrees = async (previous: string, current: string) => {
@@ -682,9 +689,11 @@ const compareTrees = async (previous: string, current: string) => {
if (!reference.ok) throw new Error(reference.error.message);
const analyzed = await analyzeJavaScriptApplication({ input_path: current });
if (!analyzed.ok) throw analyzed.error;
const application = parseApplicationGraphEvidence(
const parsedApplication = parseApplicationGraphEvidence(
JSON.parse(JSON.stringify(analyzed.value)),
);
if (!parsedApplication.ok) throw new Error("Analysis Evidence must parse");
const application = parsedApplication.value;
const comparison = compareSourceToBundle({
reference: reference.value,
application: {