From 40c6dade8eb608141ec62dd90a8ee4195d52fbd8 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 20 Nov 2026 08:24:46 -0500 Subject: [PATCH] test(mcp): consolidate reduced output schema proof at the SDK boundary (#12823) * test(mcp): consolidate reduced output schema proof at the SDK boundary * test(mcp): verify both required fields on the reduced output root --- src/contracts/compactOutputSchema.test.ts | 67 ------------------- .../boundary/mcp/outputSchemaProfile.test.ts | 23 ++++--- 2 files changed, 15 insertions(+), 75 deletions(-) diff --git a/src/contracts/compactOutputSchema.test.ts b/src/contracts/compactOutputSchema.test.ts index 4e64d7dfd9..a6f1e758ac 100644 --- a/src/contracts/compactOutputSchema.test.ts +++ b/src/contracts/compactOutputSchema.test.ts @@ -48,27 +48,6 @@ const referencedSchema = { }, } as const; -const oversizedSchema = (): Record => ({ - type: "object", - description: "A complete result envelope.", - properties: { - envelope: { type: "string" }, - result: { - type: "object", - properties: Object.fromEntries( - Array.from({ length: 200 }, (_, index) => [ - `field_${index}`, - { type: "string", description: `Field ${index}` }, - ]), - ), - required: Array.from({ length: 200 }, (_, index) => `field_${index}`), - additionalProperties: false, - }, - }, - required: ["envelope", "result"], - additionalProperties: false, -}); - describe("compact advertised output schema", () => { it("drops nested annotation prose while keeping the root guidance and validation", () => { const { schema, presentation } = compactAdvertisedOutputSchema( @@ -102,46 +81,6 @@ describe("compact advertised output schema", () => { expect(entries.items).toMatchObject({ type: "object" }); }); - it("reduces an oversized contract to a widening root shape within budget", () => { - const budgetBytes = 4 * 1024; - const { schema, presentation } = compactAdvertisedOutputSchema( - oversizedSchema(), - budgetBytes, - ); - expect(presentation).toBe("reduced"); - expect(serializedBytes(schema)).toBeLessThanOrEqual(budgetBytes); - expect(schema.type).toBe("object"); - expect(schema.required).toEqual(["envelope", "result"]); - expect(schema.additionalProperties).toBe(false); - expect(schema.description).toContain("compact output schema profile"); - const result = (schema.properties as Record) - .result as Record; - expect(result.type).toBe("object"); - expect(result.properties).toBeUndefined(); - }); - - it("accepts a valid canonical result after reduction", () => { - const budgetBytes = 4 * 1024; - const { schema } = compactAdvertisedOutputSchema( - oversizedSchema(), - budgetBytes, - ); - const validate = new Ajv2020({ strict: false }).compile(schema); - const result = { - envelope: "ok", - result: Object.fromEntries( - Array.from({ length: 200 }, (_, index) => [ - `field_${index}`, - `value ${index}`, - ]), - ), - }; - expect(validate(result)).toBe(true); - // The advertisement is wider than the canonical contract: dropping nested - // detail must never reject a valid result, but it can accept an invalid one. - expect(validate({ envelope: "ok", result: { unknown: 1 } })).toBe(true); - }); - it("keeps a non-object root accepting every JSON value when it cannot fit", () => { const arraySchema = { type: "array", @@ -162,10 +101,4 @@ describe("compact advertised output schema", () => { expect(validate(["anything"])).toBe(true); expect(validate({ also: "anything" })).toBe(true); }); - - it("is deterministic across equivalent inputs", () => { - expect(compactAdvertisedOutputSchema(oversizedSchema(), 4 * 1024)).toEqual( - compactAdvertisedOutputSchema(oversizedSchema(), 4 * 1024), - ); - }); }); diff --git a/tests/boundary/mcp/outputSchemaProfile.test.ts b/tests/boundary/mcp/outputSchemaProfile.test.ts index 7f133dab0a..464169b5c1 100644 --- a/tests/boundary/mcp/outputSchemaProfile.test.ts +++ b/tests/boundary/mcp/outputSchemaProfile.test.ts @@ -198,14 +198,16 @@ it("rejects canonical-invalid output that the reduced advertisement accepts", as z.string().optional(), ]), ); - const outputSchema = z.strictObject({ - value: z.string(), - payload: z.object({ - inner: z.string(), - count: z.number().int(), - ...nestedDetail, - }), - }); + const outputSchema = z + .strictObject({ + value: z.string(), + payload: z.object({ + inner: z.string(), + count: z.number().int(), + ...nestedDetail, + }), + }) + .describe("Fixture result envelope."); const server = createServer("compact"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); @@ -255,6 +257,7 @@ it("rejects canonical-invalid output that the reduced advertisement accepts", as const tools = (await client.listTools()).tools; const advertised = tools.find((tool) => tool.name === contract.name)! .outputSchema as Record; + expect(advertised.description).toContain("Fixture result envelope."); expect(advertised.description).toContain("reduced form"); expect((advertised.properties as Record).payload).toEqual({ type: "object", @@ -270,6 +273,10 @@ it("rejects canonical-invalid output that the reduced advertisement accepts", as validateFormats: false, }).compile(advertised); expect(validateAdvertised(malformed)).toBe(true); + expect(validateAdvertised([])).toBe(false); + expect(validateAdvertised({ payload: malformed.payload })).toBe(false); + expect(validateAdvertised({ value: malformed.value })).toBe(false); + expect(validateAdvertised({ ...malformed, extra: true })).toBe(false); const success = await client.callTool({ name: contract.name,