mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 11:01:11 +00:00
Merge branch 'fix/served-schema-parity' into fix/advertised-allof-patterns
This commit is contained in:
commit
d21c19c15d
4 files changed
+102
-106
No files matched your search
@@ -1,16 +1,13 @@
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { McpServer } from "@modelcontextprotocol/server";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { ARTIFACT_COMPARISON_EXAMPLE } from "../../../src/contracts/artifactComparisonExample.js";
|
||||
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
import { toolRegistrationOptions } from "../../../src/server/toolRegistrationOptions.js";
|
||||
import { advertisedSchemaErrors } from "../../fixtures/mcpAdvertisedSchemaValidity.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
import { canonicalInputSchema } from "../../fixtures/canonicalOutputSchema.js";
|
||||
import { servedToolCatalog } from "../../fixtures/servedToolCatalog.js";
|
||||
|
||||
const evidence = ARTIFACT_COMPARISON_EXAMPLE.left;
|
||||
const retained = {
|
||||
@@ -22,97 +19,83 @@ const file = {
|
||||
path: join(tmpdir(), "evidence.json"),
|
||||
} as const;
|
||||
|
||||
it("advertises one spelling per compare_artifacts source and rejects the same sides the parser rejects", async () => {
|
||||
it("accepts one spelling per compare_artifacts source and serves every accepted side", async () => {
|
||||
const contract = toolContract("compare_artifacts");
|
||||
const server = new McpServer({ name: "artifact-sources", version: "0" });
|
||||
const client = new Client(
|
||||
{ name: "artifact-sources", version: "0" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
const tool = (await servedToolCatalog()).find(
|
||||
({ name }) => name === contract.name,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
server.registerTool(
|
||||
contract.name,
|
||||
toolRegistrationOptions(contract),
|
||||
async () => ({ content: [] }),
|
||||
);
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const { tools } = await client.listTools();
|
||||
expect(advertisedSchemaErrors(tools)).toEqual([]);
|
||||
const tool = tools.find(({ name }) => name === contract.name);
|
||||
if (tool === undefined) throw new Error("compare_artifacts not advertised");
|
||||
expect(tool.inputSchema.examples).toEqual([
|
||||
{
|
||||
left: {
|
||||
kind: "retained-evidence",
|
||||
evidence_id: ARTIFACT_COMPARISON_EXAMPLE.left.evidence_id,
|
||||
},
|
||||
right: {
|
||||
kind: "retained-evidence",
|
||||
evidence_id: ARTIFACT_COMPARISON_EXAMPLE.right.evidence_id,
|
||||
},
|
||||
if (tool === undefined) throw new Error("compare_artifacts not advertised");
|
||||
// The canonical examples reference retained Evidence instead of
|
||||
// embedding complete records.
|
||||
expect(canonicalInputSchema(contract.name).examples).toEqual([
|
||||
{
|
||||
left: {
|
||||
kind: "retained-evidence",
|
||||
evidence_id: ARTIFACT_COMPARISON_EXAMPLE.left.evidence_id,
|
||||
},
|
||||
]);
|
||||
const validate = new Ajv2020({
|
||||
strict: false,
|
||||
validateFormats: false,
|
||||
}).compile(tool.inputSchema);
|
||||
const sides: readonly (readonly [string, unknown, boolean])[] = [
|
||||
["complete Evidence", evidence, true],
|
||||
["retained reference", retained, true],
|
||||
["Evidence file", file, true],
|
||||
[
|
||||
"selected bundle record",
|
||||
{ ...file, evidence_id: evidence.evidence_id },
|
||||
true,
|
||||
],
|
||||
["second inline spelling", { kind: "inline", evidence }, false],
|
||||
["retained reference without ID", { kind: "retained-evidence" }, false],
|
||||
["two references at once", { ...retained, path: file.path }, false],
|
||||
[
|
||||
"Evidence carrying a source kind",
|
||||
{ ...evidence, kind: "retained-evidence" },
|
||||
false,
|
||||
],
|
||||
["relative Evidence file", { ...file, path: "evidence.json" }, false],
|
||||
["empty side", {}, false],
|
||||
];
|
||||
for (const [label, side, accepted] of sides)
|
||||
for (const input of [
|
||||
{ left: side, right: retained },
|
||||
{ left: retained, right: side },
|
||||
]) {
|
||||
expect(contract.inputSchema.safeParse(input).success, label).toBe(
|
||||
accepted,
|
||||
);
|
||||
expect(validate(input), label).toBe(accepted);
|
||||
}
|
||||
expect(contract.inputSchema.safeParse({ left: retained }).success).toBe(
|
||||
right: {
|
||||
kind: "retained-evidence",
|
||||
evidence_id: ARTIFACT_COMPARISON_EXAMPLE.right.evidence_id,
|
||||
},
|
||||
},
|
||||
]);
|
||||
const validate = new Ajv2020({
|
||||
strict: false,
|
||||
validateFormats: false,
|
||||
}).compile(tool.inputSchema);
|
||||
const sides: readonly (readonly [string, unknown, boolean])[] = [
|
||||
["complete Evidence", evidence, true],
|
||||
["retained reference", retained, true],
|
||||
["Evidence file", file, true],
|
||||
[
|
||||
"selected bundle record",
|
||||
{ ...file, evidence_id: evidence.evidence_id },
|
||||
true,
|
||||
],
|
||||
["second inline spelling", { kind: "inline", evidence }, false],
|
||||
["retained reference without ID", { kind: "retained-evidence" }, false],
|
||||
["two references at once", { ...retained, path: file.path }, false],
|
||||
[
|
||||
"Evidence carrying a source kind",
|
||||
{ ...evidence, kind: "retained-evidence" },
|
||||
false,
|
||||
);
|
||||
expect(validate({ left: retained })).toBe(false);
|
||||
// compare_functions is the precedent for the inline and retained forms;
|
||||
// only the Evidence-file reference extends it.
|
||||
const functions = toolContract("compare_functions");
|
||||
const shared = sides.filter(
|
||||
([, side]) =>
|
||||
typeof side !== "object" ||
|
||||
side === null ||
|
||||
!("kind" in side) ||
|
||||
side.kind !== "evidence-file",
|
||||
);
|
||||
expect(shared).toHaveLength(sides.length - 3);
|
||||
for (const [label, side] of shared)
|
||||
expect(
|
||||
functions.inputSchema.safeParse({ left: side, right: retained })
|
||||
.success,
|
||||
label,
|
||||
).toBe(
|
||||
contract.inputSchema.safeParse({ left: side, right: retained }).success,
|
||||
],
|
||||
["relative Evidence file", { ...file, path: "evidence.json" }, false],
|
||||
["empty side", {}, false],
|
||||
];
|
||||
for (const [label, side, accepted] of sides)
|
||||
for (const input of [
|
||||
{ left: side, right: retained },
|
||||
{ left: retained, right: side },
|
||||
]) {
|
||||
expect(contract.inputSchema.safeParse(input).success, label).toBe(
|
||||
accepted,
|
||||
);
|
||||
} finally {
|
||||
await Promise.allSettled([client.close(), server.close()]);
|
||||
}
|
||||
// Known gap (#15311): the served schema reduces each side to an
|
||||
// object, so it accepts every side and runtime rejects the invalid
|
||||
// ones. servedSchemaParity.test.ts lists `compare_artifacts left.*`.
|
||||
expect(validate(input), label).toBe(true);
|
||||
}
|
||||
expect(contract.inputSchema.safeParse({ left: retained }).success).toBe(
|
||||
false,
|
||||
);
|
||||
expect(validate({ left: retained })).toBe(false);
|
||||
// compare_functions is the precedent for the inline and retained forms;
|
||||
// only the Evidence-file reference extends it.
|
||||
const functions = toolContract("compare_functions");
|
||||
const shared = sides.filter(
|
||||
([, side]) =>
|
||||
typeof side !== "object" ||
|
||||
side === null ||
|
||||
!("kind" in side) ||
|
||||
side.kind !== "evidence-file",
|
||||
);
|
||||
expect(shared).toHaveLength(sides.length - 3);
|
||||
for (const [label, side] of shared)
|
||||
expect(
|
||||
functions.inputSchema.safeParse({ left: side, right: retained }).success,
|
||||
label,
|
||||
).toBe(
|
||||
contract.inputSchema.safeParse({ left: side, right: retained }).success,
|
||||
);
|
||||
});
|
||||
@@ -19,6 +19,7 @@ import { createToolResultDelivery } from "../../../src/server/toolResult.js";
|
||||
import { toolRegistrationOptions } from "../../../src/server/toolRegistrationOptions.js";
|
||||
import { startFakeCdpBrowser } from "../../fixtures/fakeCdpBrowser.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
import { servedToolCatalog } from "../../fixtures/servedToolCatalog.js";
|
||||
|
||||
const delivery = createToolResultDelivery(STDIO_DEFAULT_MAX_BUFFER_SIZE);
|
||||
|
||||
@@ -68,17 +69,19 @@ function invalidComparisonInputs(
|
||||
{ before: passive.before, after: { ...passive.after, webmcp: {} } },
|
||||
{ before_scenario: {}, after_scenario: {} },
|
||||
{ ...scenario, before_scenario: { ...scenarioCapture, steps: [{}] } },
|
||||
];
|
||||
const advertisedInvalid = [
|
||||
// Incomplete input groups: the served root cannot hold combinators, so
|
||||
// its description names the groups and runtime enforces them.
|
||||
{},
|
||||
{ before: passive.before },
|
||||
{ before_scenario: scenario.before_scenario },
|
||||
];
|
||||
const advertisedInvalid = [
|
||||
{ before: { inspection: "{}" }, after: passive.after },
|
||||
{
|
||||
before: passive.before,
|
||||
after: { ...passive.after, webmcp: "{}" },
|
||||
},
|
||||
{ before_scenario: "{}", after_scenario: scenarioCapture },
|
||||
{ before_scenario: scenario.before_scenario },
|
||||
{ ...passive, unexpected: true },
|
||||
{
|
||||
...scenario,
|
||||
@@ -121,7 +124,9 @@ describe("browser comparison input boundary", () => {
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
// The bare server runs the handler; the advertisement is what a
|
||||
// session server serves.
|
||||
const advertised = (await servedToolCatalog()).find(
|
||||
({ name }) => name === contract.name,
|
||||
);
|
||||
if (advertised === undefined) throw new Error("Missing comparison tool");
|
||||
@@ -153,7 +158,7 @@ describe("browser comparison input boundary", () => {
|
||||
// Strict clients reject combinators and dependentRequired, so the
|
||||
// projection states the groups in its description and leaves group
|
||||
// completeness and exclusion to the canonical runtime parser.
|
||||
expect(advertised.inputSchema.description).toContain(
|
||||
expect(advertised.description).toContain(
|
||||
"before + after; before_scenario + after_scenario + [normalization]",
|
||||
);
|
||||
const runtimeOnlyInvalid = [
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import {
|
||||
canonicalInputSchema,
|
||||
canonicalOutputSchema,
|
||||
} from "../../fixtures/canonicalOutputSchema.js";
|
||||
import { canonicalOutputSchema } from "../../fixtures/canonicalOutputSchema.js";
|
||||
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { createPackageWithOptions } from "@electron/asar";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
@@ -145,12 +143,21 @@ it("advertises exact source selection and retains its scope through summary, Evi
|
||||
const validate = new Ajv2020({
|
||||
strict: false,
|
||||
validateFormats: false,
|
||||
}).compile(canonicalInputSchema("analyze_javascript_application"));
|
||||
}).compile(schema);
|
||||
const canonical = toolContract("analyze_javascript_application");
|
||||
expect(validate({ input_path: root, source_paths: ["main.mjs"] })).toBe(
|
||||
true,
|
||||
);
|
||||
expect(validate({ input_path: root, source_paths: [1] })).toBe(false);
|
||||
for (const source_paths of [[], [""], [1]])
|
||||
expect(validate({ input_path: root, source_paths })).toBe(false);
|
||||
expect(
|
||||
canonical.inputSchema.safeParse({ input_path: root, source_paths })
|
||||
.success,
|
||||
).toBe(false);
|
||||
// Known gap (#15311): the reduced schema keeps the array's item type but
|
||||
// not its minItems or item minLength (servedSchemaParity.test.ts).
|
||||
for (const source_paths of [[], [""]])
|
||||
expect(validate({ input_path: root, source_paths })).toBe(true);
|
||||
const selected = await client.callTool({
|
||||
name: "analyze_javascript_application",
|
||||
arguments: {
|
||||
|
||||
@@ -587,8 +587,9 @@ it("derives violations for root, nested and array path fields", async () => {
|
||||
* Fields whose canonical rule lives in a `.refine()` or transform, so the
|
||||
* served schema has no keyword for it and no guidance names it. The generated
|
||||
* property found each; the value is one input runtime rejects and the served
|
||||
* schema accepts. Endpoint fields are #15319; the UEFI paths and Frida
|
||||
* programs check absoluteness in a refinement instead of the shared pattern.
|
||||
* schema accepts. Endpoint fields are #15319; the UEFI paths check
|
||||
* absoluteness in a refinement instead of the shared pattern; Frida `program`
|
||||
* and objdump fields depend on a cross-field rule.
|
||||
*/
|
||||
const REFINEMENT_GAPS: Readonly<Record<string, string>> = {
|
||||
"capture_web_screenshot cdp_endpoint": "a",
|
||||
|
||||
Reference in new issue
Block a user