fix(mcp): emit valid schemas for empty arrays (#535)
Replace empty tuples with a shared empty-array schema. Validate all input and output schemas against Draft 2020-12 during catalog generation and packaged MCP verification, with runtime and catalog regression coverage. Closes #528 Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
import { emptyArraySchema } from "./emptyArraySchema.js";
|
||||
import { sanitizedBrowserUrlSchema } from "./browserObservation.js";
|
||||
import { webScreenshotArtifactSchema } from "./webScreenshot.js";
|
||||
|
||||
@@ -229,14 +230,14 @@ export const browserScenarioCompletenessSchema = z.discriminatedUnion(
|
||||
z.strictObject({
|
||||
status: z.literal("complete"),
|
||||
equality_eligible: z.literal(true),
|
||||
missing_sections: z.tuple([]),
|
||||
truncated_sections: z.tuple([]),
|
||||
missing_sections: emptyArraySchema,
|
||||
truncated_sections: emptyArraySchema,
|
||||
}),
|
||||
z.strictObject({
|
||||
status: z.literal("incomplete"),
|
||||
equality_eligible: z.literal(false),
|
||||
missing_sections: z.array(completenessSectionSchema).min(1),
|
||||
truncated_sections: z.tuple([]),
|
||||
truncated_sections: emptyArraySchema,
|
||||
}),
|
||||
z.strictObject({
|
||||
status: z.literal("truncated"),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { emptyArraySchema } from "./emptyArraySchema.js";
|
||||
import { evidenceSchema } from "./evidence.js";
|
||||
|
||||
const addressSchema = z
|
||||
@@ -87,14 +88,14 @@ export const callPathResultSchema = z.union([
|
||||
status: z.literal("not_found"),
|
||||
shortest_hops: z.null(),
|
||||
search_scope: z.object({ exhaustive: z.literal(true) }),
|
||||
paths: z.tuple([]),
|
||||
paths: emptyArraySchema,
|
||||
}),
|
||||
z.object({
|
||||
...resultContextShape,
|
||||
status: z.literal("unknown"),
|
||||
shortest_hops: z.null(),
|
||||
search_scope: z.object({ exhaustive: z.literal(false) }),
|
||||
paths: z.tuple([]),
|
||||
paths: emptyArraySchema,
|
||||
}),
|
||||
]);
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { emptyArraySchema } from "./emptyArraySchema.js";
|
||||
|
||||
describe("empty array schema", () => {
|
||||
it("accepts only an empty array", () => {
|
||||
expect(emptyArraySchema.parse([])).toEqual([]);
|
||||
for (const value of [
|
||||
[null],
|
||||
["candidate"],
|
||||
[0],
|
||||
[false],
|
||||
[{}],
|
||||
[[]],
|
||||
null,
|
||||
{},
|
||||
]) {
|
||||
expect(emptyArraySchema.safeParse(value).success).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
import { z } from "zod";
|
||||
|
||||
/** An empty array whose JSON Schema is valid under Draft 2020-12. */
|
||||
export const emptyArraySchema = z.array(z.never()).length(0);
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { emptyArraySchema } from "./emptyArraySchema.js";
|
||||
import { evidenceSchema } from "./evidence.js";
|
||||
import { javascriptApplicationGraphSchema } from "./javascriptApplicationGraph.js";
|
||||
import { JAVASCRIPT_APPLICATION_NODE_KINDS } from "./javascriptApplicationGraphSchemas.js";
|
||||
@@ -37,7 +38,7 @@ export const compareApplicationVersionsInputSchema = z
|
||||
}
|
||||
});
|
||||
|
||||
const emptyCandidateNodesSchema = z.tuple([]);
|
||||
const emptyCandidateNodesSchema = emptyArraySchema;
|
||||
const candidateNodesSchema = z.tuple([nodeIdSchema]).rest(nodeIdSchema);
|
||||
const exactMatchSchema = z.strictObject({
|
||||
status: z.literal("matched"),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { emptyArraySchema } from "./emptyArraySchema.js";
|
||||
import { evidenceSchema } from "./evidence.js";
|
||||
import {
|
||||
cliMetadataGuidSchema,
|
||||
@@ -48,15 +49,15 @@ const matchedComparisonSchema = z.strictObject({
|
||||
status: z.literal("matched"),
|
||||
basis: concreteMatchBasisSchema,
|
||||
confidence: z.enum(["exact", "high"]),
|
||||
candidate_left_tokens: z.tuple([]),
|
||||
candidate_right_tokens: z.tuple([]),
|
||||
candidate_left_tokens: emptyArraySchema,
|
||||
candidate_right_tokens: emptyArraySchema,
|
||||
});
|
||||
const unmatchedComparisonSchema = z.strictObject({
|
||||
status: z.literal("unmatched"),
|
||||
basis: z.literal("none"),
|
||||
confidence: z.literal("unknown"),
|
||||
candidate_left_tokens: z.tuple([]),
|
||||
candidate_right_tokens: z.tuple([]),
|
||||
candidate_left_tokens: emptyArraySchema,
|
||||
candidate_right_tokens: emptyArraySchema,
|
||||
});
|
||||
const ambiguousComparisonSchema = z.strictObject({
|
||||
status: z.literal("ambiguous"),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { emptyArraySchema } from "./emptyArraySchema.js";
|
||||
import { evidenceSchema } from "./evidence.js";
|
||||
import { cliMetadataGuidSchema } from "./managedArtifact.js";
|
||||
|
||||
@@ -72,7 +73,7 @@ export const pinvokeVerificationSchema = z.discriminatedUnion("status", [
|
||||
basis: z.enum(["no-native-candidate", "unsupported-native-evidence"]),
|
||||
confidence: z.literal("unknown"),
|
||||
matched_native: z.null(),
|
||||
candidates: z.tuple([]),
|
||||
candidates: emptyArraySchema,
|
||||
}),
|
||||
z.strictObject({
|
||||
...pinvokeVerificationContextShape,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { emptyArraySchema } from "./emptyArraySchema.js";
|
||||
import { inspectWebPageWithSourceInputSchema } from "./browserObservation.js";
|
||||
import { webTextArtifactSchema } from "./webContentArtifact.js";
|
||||
|
||||
@@ -71,9 +72,9 @@ const sourceMapSchema = z.union([
|
||||
...parsedSourceMapShape,
|
||||
status: z.enum(["fetch_failed", "invalid", "policy_filtered"]),
|
||||
artifact: z.null(),
|
||||
original_sources: z.tuple([]),
|
||||
original_module_edges: z.tuple([]),
|
||||
mappings: z.tuple([]),
|
||||
original_sources: emptyArraySchema,
|
||||
original_module_edges: emptyArraySchema,
|
||||
mappings: emptyArraySchema,
|
||||
limitation: z.string(),
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { emptyArraySchema } from "./emptyArraySchema.js";
|
||||
import { webPageInspectionSchema } from "./browserObservation.js";
|
||||
import { webMcpDiscoverySchema } from "./webMcpDiscovery.js";
|
||||
|
||||
@@ -21,7 +22,7 @@ const changeSchema = z.object({
|
||||
});
|
||||
const emptyDimensionShape = {
|
||||
total_changes: z.literal(0),
|
||||
changes: z.tuple([]),
|
||||
changes: emptyArraySchema,
|
||||
};
|
||||
const dimensionSchema = z.union([
|
||||
z
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user