mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
* test(mcp): check advertised schemas against a portable dialect in every profile * fix(mcp): re-emit advertised patterns in a portable regex grammar * fix(mcp): present discover_tools input through the selected profile The hot-cold catalog registered discover_tools directly with the SDK, so the default compact input profile still advertised its canonical schema, including page-size defaults clients apply on their own (#5322). Route every listed input schema, transport discovery included, through one server-owned presentation, and pass the selected presentation to the deferred server, which serves recorded tool schemas but not discovery. * fix(mcp): keep the Evidence union on described borrowed inputs borrowEvidenceInput installed its advertised projection on one schema instance. A call site's .describe() rebuilds the schema from its definition, so match_native_functions advertised left and right as unconstrained values in every input profile. Install the projection in the borrowed parser's constructor so derived schemas keep it, for both borrowed inputs and borrowed arrays. * fix(mcp): validate advertised dialect by selected profile * fix(mcp): preserve schema widening through references * feat(mcp): project compact input schemas into the portable advertised dialect One projection (advertisedDialectProjection.ts) owns the compact input advertisement: one type per node, items on every array, string literals as enums, oneOf widened to anyOf, allOf merged, tuples as element unions, exclusive bounds made inclusive, and every keyword outside the dialect dropped. Each rewrite is exact or widening; server validation is unchanged. The root description and sentences for dropped cross-field constraints move to the tool description, which Codex and Zed keep. The compact baseline falls to nullable values only (29), which the dialect cannot express without narrowing an input. The gateway shape repairs (typeArrayItemUnions, hasGatewayIncompatibleShape), the second dependentRequired-to-prose copy and the strict-gateway test denylist are removed; the dialect checker gates the inline presentation instead. * fix(mcp): refuse zero-padded repeat bounds and record host-specific path patterns * fix(mcp): keep projected schemas permissive * fix(mcp): keep references valid when presentation widens their targets * fix(mcp): keep a single union branch's closure scoped to its properties * fix(mcp): keep an allOf member's tuple tail with its own positions * fix(mcp): relax references into negations and conditionals presentation may remove * test(mcp): select the borrowed Evidence contract from its family * fix(mcp): keep astral literals and dynamic references widening in every mode * fix(mcp): omit astral literals and relax untracked references when presentation widens * fix(mcp): read reference pointers by schema position, not segment spelling * fix(mcp): protect references into collapsing boolean unions and keep referencing branches out of the collapse * fix(mcp): keep reduced schemas open when their root admits names by pattern * test(mcp): keep the reduced-schema pattern case outside the size-limited block * fix(mcp): omit patterns whose classes name astral characters * fix(mcp): decide union collapse and pointer protection from canonical branches * docs(mcp): document non-u astral matching and pin BMP agreement across V8 modes * fix(mcp): keep prototype-named properties as own properties in the dialect projection * test(mcp): expect the advertised base64 schema to omit the unbounded pad-bit probe * fix(mcp): protect references into unevaluated keywords lost evaluation removes * fix(mcp): emit stack-safe classes with non-ASCII members and protect draft-07 reference siblings * fix(mcp): protect references into literal siblings of relaxed draft-07 references * feat(mcp): omit output schemas from tools/list by default (#10646) * feat(mcp): omit output schemas from tools/list by default No surveyed model API reads an output schema, MCP client validators repeat REA's own result validation, and complete output schemas were about 92% of the default tools/list. REA_MCP_OUTPUT_SCHEMA_PROFILE now resolves to off through one owner (resolveMcpOutputSchemaProfile); compact and full remain selectable. structuredContent is still delivered, and the deferred server serves both off and full from the recorded catalog with the matching recorded identity. Tests and artifact verifiers that validate results against complete advertised output contracts select full explicitly. * fix(mcp): select schemas in verification workflows * fix(mcp): select complete output schemas in the Electron verifier * fix(mcp): select complete output schemas in standalone verifier probes * fix(mcp): select complete output schemas in every verifier transport * test(mcp): select full output schemas in packet and signal schema checks * fix(mcp): validate the doctor probe reply against the canonical output contract (#10655) * fix(mcp): validate the doctor probe reply against the canonical output contract * test(mcp): replay doctor probe validation under every output profile * test(mcp): accept typed-branch nullable unions in the advertised dialect (#10649) * test(mcp): select full output schemas in HTTP session workflows * fix(mcp): keep the Evidence union on described borrowed inputs (#10597) * fix(mcp): keep the Evidence union on described borrowed inputs borrowEvidenceInput installed its advertised projection on one schema instance. A call site's .describe() rebuilds the schema from its definition, so match_native_functions advertised left and right as unconstrained values in every input profile. Install the projection in the borrowed parser's constructor so derived schemas keep it, for both borrowed inputs and borrowed arrays. * test(mcp): select the borrowed Evidence contract from its family * docs(mcp): admit baseline growth only for restored contract declarations * fix(mcp): state reduced multi-type properties as typed branches, not type lists The reduced fallback derived a property's types and emitted them as a type list, which Gemini, Moonshot and Ark reject. A property whose canonical schema is anyOf string and number therefore traded a typed union for a rejected construct when the inline projection fell back. Emit one type, or anyOf typed branches, so [T, null] becomes the dialect's nullable union.
204 lines
7.3 KiB
TypeScript
204 lines
7.3 KiB
TypeScript
import { withVerifierCleanup } from "../../scripts/lib/verifier-cleanup.mjs";
|
|
import { execFile } from "node:child_process";
|
|
import { createHash } from "node:crypto";
|
|
import { lstat, readFile, readdir, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { promisify } from "node:util";
|
|
|
|
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
|
|
import { Client } from "@modelcontextprotocol/client";
|
|
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
|
import { expect, it } from "vitest";
|
|
|
|
import { artifactMcpCall } from "../../scripts/lib/artifact-e2e.mjs";
|
|
import {
|
|
artifactExtractionResultSchema,
|
|
artifactInventoryResultSchema,
|
|
} from "../../src/domain/artifactGraph.js";
|
|
import { artifactInspectionResultSchema } from "../../src/domain/artifactInspection.js";
|
|
import { parseEvidence } from "../../src/domain/evidence.js";
|
|
import { advertisedMcpToolSchemas } from "../fixtures/advertisedMcpTool.js";
|
|
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
|
import { schemaVerifierEnvironment } from "../../scripts/lib/mcp-verification-environment.mjs";
|
|
|
|
const execute = promisify(execFile);
|
|
const cli = fileURLToPath(new URL("../../scripts/rea.mjs", import.meta.url));
|
|
|
|
const setup = async () => {
|
|
const root = await createTestTempDirectory(
|
|
"rea-public-extraction-selection-",
|
|
);
|
|
const path = join(root, "fixture.zip");
|
|
const writer = new ZipWriter(new Uint8ArrayWriter());
|
|
await writer.add("lib/selected.so", new TextReader("native fixture"));
|
|
await writer.add("lib/other.so", new TextReader("other architecture"));
|
|
await writer.add("res/2f.xml", new TextReader("lower"));
|
|
await writer.add("res/2F.xml", new TextReader("upper"));
|
|
const bytes = await writer.close();
|
|
await writeFile(path, bytes);
|
|
const environment = {
|
|
PATH: process.env.PATH ?? "",
|
|
HOME: root,
|
|
USERPROFILE: root,
|
|
REA_LOG_LEVEL: "silent",
|
|
REA_ANALYSIS_PROVIDER: "auto",
|
|
};
|
|
const run = async (command: string, flags: readonly string[] = []) => {
|
|
const { stdout } = await execute(
|
|
process.execPath,
|
|
[cli, command, path, ...flags, "--json"],
|
|
{
|
|
env: environment,
|
|
timeout: 30000,
|
|
maxBuffer: 16 * 1024 * 1024,
|
|
},
|
|
);
|
|
return parseEvidence(JSON.parse(stdout));
|
|
};
|
|
const inspected = artifactInspectionResultSchema.parse(
|
|
(await run("inspect-artifact")).normalized_result,
|
|
);
|
|
const inventoryEvidence = inspected.substeps.find(
|
|
({ evidence }) => evidence.operation === "inventory_artifact",
|
|
)?.evidence;
|
|
if (inventoryEvidence === undefined)
|
|
throw new Error("Missing inventory Evidence");
|
|
const inventory = artifactInventoryResultSchema.parse(
|
|
inventoryEvidence.normalized_result,
|
|
);
|
|
const occurrence = (path: string) => {
|
|
const entry = inventory.occurrences.find(
|
|
({ logical_path }) => logical_path === path,
|
|
);
|
|
if (entry === undefined) throw new Error(`Missing occurrence: ${path}`);
|
|
return entry.occurrence_id;
|
|
};
|
|
return { root, path, bytes, environment, run, inventory, occurrence };
|
|
};
|
|
|
|
it("extracts repeatable CLI selections into the exact requested destination", async () => {
|
|
const data = await setup();
|
|
const ids = [
|
|
data.occurrence("lib/selected.so"),
|
|
data.occurrence("lib/other.so"),
|
|
];
|
|
const output = join(data.root, "chosen-output");
|
|
const evidence = await data.run("extract-artifact", [
|
|
"--output-root",
|
|
output,
|
|
...ids.flatMap((id) => ["--occurrence-id", id]),
|
|
]);
|
|
const result = artifactExtractionResultSchema.parse(
|
|
evidence.normalized_result,
|
|
);
|
|
expect(result.output_root).toBe(output);
|
|
expect(result.artifacts.map(({ relative_path }) => relative_path)).toEqual([
|
|
"lib/other.so",
|
|
"lib/selected.so",
|
|
]);
|
|
expect(result.extraction_manifest.selected_occurrence_ids).toEqual(
|
|
[...ids].sort(),
|
|
);
|
|
expect(result.manifest).toEqual(data.inventory.manifest);
|
|
expect(await readdir(output)).toEqual(["lib"]);
|
|
expect(await readFile(join(output, "lib/selected.so"), "utf8")).toBe(
|
|
"native fixture",
|
|
);
|
|
});
|
|
|
|
it("keeps CLI/MCP selection identity, invalid-input refusals and committed output after close", async () => {
|
|
const data = await setup();
|
|
const id = data.occurrence("lib/selected.so");
|
|
const cliResult = artifactExtractionResultSchema.parse(
|
|
(
|
|
await data.run("extract-artifact", [
|
|
"--output-root",
|
|
join(data.root, "cli-output"),
|
|
"--occurrence-id",
|
|
id,
|
|
])
|
|
).normalized_result,
|
|
);
|
|
const transport = new StdioClientTransport({
|
|
command: process.execPath,
|
|
args: [cli, "mcp"],
|
|
env: schemaVerifierEnvironment({
|
|
...data.environment,
|
|
REA_MCP_INPUT_SCHEMA_PROFILE: "full",
|
|
REA_MCP_TOOL_FAMILIES: "artifact,session",
|
|
}),
|
|
stderr: "pipe",
|
|
});
|
|
const client = new Client({
|
|
name: "extraction-selection-test",
|
|
version: "1",
|
|
});
|
|
const output = join(data.root, "mcp-output");
|
|
await withVerifierCleanup(async () => {
|
|
await client.connect(transport);
|
|
const opened = await artifactMcpCall(client, {
|
|
name: "open_binary",
|
|
arguments: { path: data.path },
|
|
});
|
|
expect(opened.isError).not.toBe(true);
|
|
const schemas = await advertisedMcpToolSchemas(client, "extract_artifact");
|
|
for (const occurrence_ids of [[id], [id, data.occurrence("lib/other.so")]])
|
|
expect(
|
|
schemas.ajv.validate(schemas.inputSchema, {
|
|
output_root: output,
|
|
occurrence_ids,
|
|
}),
|
|
JSON.stringify(schemas.ajv.errors),
|
|
).toBe(true);
|
|
expect(
|
|
schemas.ajv.validate(schemas.inputSchema, {
|
|
output_root: output,
|
|
occurrence_ids: [id, id],
|
|
}),
|
|
).toBe(false);
|
|
expect(schemas.ajv.errors).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({ keyword: "uniqueItems" }),
|
|
]),
|
|
);
|
|
const reply = await artifactMcpCall(client, {
|
|
name: "extract_artifact",
|
|
arguments: { output_root: output, occurrence_ids: [id] },
|
|
});
|
|
expect(reply.isError).not.toBe(true);
|
|
const evidence = parseEvidence(reply.structuredContent);
|
|
const result = artifactExtractionResultSchema.parse(
|
|
evidence.normalized_result,
|
|
);
|
|
expect(result.output_root).toBe(output);
|
|
expect(result.extraction_manifest).toEqual(cliResult.extraction_manifest);
|
|
expect(result.artifacts).toEqual(cliResult.artifacts);
|
|
for (const [index, occurrence_ids] of [
|
|
[`occ_${"0".repeat(64)}`],
|
|
[id, id],
|
|
].entries()) {
|
|
const invalidOutput = join(data.root, `invalid-output-${index}`);
|
|
const invalid = await artifactMcpCall(client, {
|
|
name: "extract_artifact",
|
|
arguments: { output_root: invalidOutput, occurrence_ids },
|
|
});
|
|
expect(invalid.isError).toBe(true);
|
|
await expect(lstat(invalidOutput)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
}
|
|
const closed = await artifactMcpCall(client, {
|
|
name: "close_binary",
|
|
arguments: {},
|
|
});
|
|
expect(closed.isError).not.toBe(true);
|
|
}, [() => client.close(), () => transport.close()]);
|
|
expect(await readFile(join(output, "lib/selected.so"), "utf8")).toBe(
|
|
"native fixture",
|
|
);
|
|
const digest = (bytes: Uint8Array) =>
|
|
createHash("sha256").update(bytes).digest("hex");
|
|
expect(digest(await readFile(data.path))).toBe(digest(data.bytes));
|
|
});
|