mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +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.
454 lines
16 KiB
TypeScript
454 lines
16 KiB
TypeScript
import { artifactMcpCall } from "../../../scripts/lib/artifact-e2e.mjs";
|
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
import { dirname, join } from "node:path";
|
|
import { Client } from "@modelcontextprotocol/client";
|
|
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
|
import { expect } from "vitest";
|
|
import { parse } from "yaml";
|
|
import { z } from "zod";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
import { schemaVerifierEnvironment } from "../../../scripts/lib/mcp-verification-environment.mjs";
|
|
|
|
cliTest.for(["setup", "uninstall"] as const)(
|
|
"DSH CLI %s refuses a multi-document patch without losing caller content",
|
|
async (operation, { cli }) => {
|
|
const home = await createTestTempDirectory("rea-dsh-multiple-documents-");
|
|
const profile = join(home, ".dsh");
|
|
const config = join(profile, "cordis.patch.yml");
|
|
await mkdir(profile);
|
|
const original = `# first document
|
|
- insert:
|
|
- id: rea-mcp
|
|
name: '@deepseek-ai/dsh-mcp-client'
|
|
config: {serverName: rea, transport: stdio, command: stale, args: [mcp]}
|
|
---
|
|
# preserve the second document and its comment
|
|
- insert:
|
|
- id: caller
|
|
name: caller-plugin
|
|
`;
|
|
await writeFile(config, original);
|
|
const result = await cli.run({
|
|
arguments:
|
|
operation === "setup"
|
|
? ["setup", "--client", "dsh", "--skill=false", "--yes", "--json"]
|
|
: ["uninstall", "--json"],
|
|
cwd: home,
|
|
environment: { HOME: home, USERPROFILE: home, DSH_HOME: profile },
|
|
});
|
|
expect(await readFile(config, "utf8")).toBe(original);
|
|
expect(result.exitCode, result.stdout).toBe(1);
|
|
expect(result.json).toMatchObject(
|
|
operation === "setup"
|
|
? { status: "needs_human", plannedActions: [], appliedActions: [] }
|
|
: {
|
|
status: "failed",
|
|
items: expect.arrayContaining([
|
|
expect.objectContaining({ name: "dsh", status: "failed" }),
|
|
]),
|
|
},
|
|
);
|
|
await expect(readFile(`${config}.rea.backup`)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest.for([
|
|
{
|
|
label: "blank defaults",
|
|
harness: "",
|
|
agents: " \t ",
|
|
dshRoot: "home/.dsh",
|
|
agentsRoot: "home/.agents",
|
|
},
|
|
{
|
|
label: "tilde roots",
|
|
harness: "~/selected harness",
|
|
agents: "~\\shared agents",
|
|
dshRoot: "home/selected harness",
|
|
agentsRoot: "home/shared agents",
|
|
},
|
|
{
|
|
label: "relative roots",
|
|
harness: "./selected harness",
|
|
agents: "../shared agents",
|
|
dshRoot: "workspace/selected harness",
|
|
agentsRoot: "shared agents",
|
|
},
|
|
])(
|
|
"DSH CLI uses Harness path semantics through setup, doctor and uninstall for $label",
|
|
async ({ harness, agents, dshRoot, agentsRoot }, { cli }) => {
|
|
const root = await createTestTempDirectory("rea-dsh-paths-");
|
|
const home = join(root, "home");
|
|
const cwd = join(root, "workspace");
|
|
const config = join(root, dshRoot, "cordis.patch.yml");
|
|
const skillRoot = join(
|
|
root,
|
|
agentsRoot,
|
|
"skills",
|
|
"reverse-engineer-anything",
|
|
);
|
|
const skill = join(skillRoot, "SKILL.md");
|
|
await mkdir(home);
|
|
await mkdir(cwd);
|
|
await mkdir(dirname(config), { recursive: true });
|
|
const original =
|
|
"# caller patch\n- insert: [{id: caller, name: caller-plugin}]\n";
|
|
await writeFile(config, original);
|
|
const run = (args: readonly string[]) =>
|
|
cli.run({
|
|
arguments: [...args, "--json"],
|
|
cwd,
|
|
environment: {
|
|
HOME: home,
|
|
USERPROFILE: home,
|
|
DSH_HOME: harness,
|
|
DSH_AGENTS_HOME: agents,
|
|
},
|
|
});
|
|
const planned = await run(["setup", "--client", "dsh", "--dry-run"]);
|
|
expect(planned.exitCode).toBe(0);
|
|
expect(planned.json).toMatchObject({
|
|
status: "planned",
|
|
appliedActions: [],
|
|
plannedActions: expect.arrayContaining([
|
|
expect.objectContaining({ id: "configure_client:dsh", target: config }),
|
|
expect.objectContaining({ kind: "install_skill", target: skillRoot }),
|
|
]),
|
|
});
|
|
expect(await readFile(config, "utf8")).toBe(original);
|
|
await expect(readFile(skill)).rejects.toMatchObject({ code: "ENOENT" });
|
|
const configured = await run(["setup", "--client", "dsh", "--yes"]);
|
|
expect(configured.exitCode).toBe(0);
|
|
expect(configured.json).toMatchObject({
|
|
status: "ready",
|
|
clients: { dsh: { status: "configured" } },
|
|
});
|
|
const text = await readFile(config, "utf8");
|
|
expect(text).toContain("# caller patch");
|
|
expect(text).toContain("rea-mcp");
|
|
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
|
expect(await readFile(skill, "utf8")).toContain(
|
|
"name: reverse-engineer-anything",
|
|
);
|
|
const doctor = await run(["doctor", "--client", "dsh", "--skill"]);
|
|
expect(doctor.exitCode).toBe(0);
|
|
expect(doctor.json).toMatchObject({ healthy: true });
|
|
const repeated = await run(["setup", "--client", "dsh", "--yes"]);
|
|
expect(repeated.exitCode).toBe(0);
|
|
expect(repeated.json).toMatchObject({
|
|
status: "ready",
|
|
plannedActions: [],
|
|
appliedActions: [],
|
|
});
|
|
expect(await readFile(config, "utf8")).toBe(text);
|
|
const removed = await run(["uninstall"]);
|
|
expect(removed.exitCode).toBe(0);
|
|
expect(removed.json).toMatchObject({
|
|
status: "complete",
|
|
items: expect.arrayContaining([
|
|
expect.objectContaining({ name: "dsh", status: "removed" }),
|
|
]),
|
|
});
|
|
expect(parse(await readFile(config, "utf8"))).toEqual([
|
|
{ insert: [{ id: "caller", name: "caller-plugin" }] },
|
|
]);
|
|
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
|
await expect(readFile(skill)).rejects.toMatchObject({ code: "ENOENT" });
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"DSH CLI previews, approves, repairs, launches MCP, repeats and uninstalls while preserving caller YAML",
|
|
async ({ cli }) => {
|
|
const home = await createTestTempDirectory("rea-dsh-lifecycle-");
|
|
const profile = join(home, "selected harness");
|
|
const config = join(profile, "cordis.patch.yml");
|
|
const skill = join(
|
|
home,
|
|
".agents/skills/reverse-engineer-anything/SKILL.md",
|
|
);
|
|
await mkdir(profile);
|
|
const original = `# caller home patch
|
|
- insert:
|
|
- id: rea-mcp
|
|
name: '@deepseek-ai/dsh-mcp-client'
|
|
config: {serverName: rea, transport: stdio, command: stale, args: [mcp]}
|
|
- holder: &op
|
|
insert:
|
|
- id: unrelated
|
|
name: caller-plugin
|
|
disabled: true
|
|
config: {cwd: !!js process.cwd()}
|
|
- id: rea-mcp
|
|
name: '@deepseek-ai/dsh-mcp-client'
|
|
config:
|
|
serverName: rea
|
|
transport: stdio
|
|
command: stale
|
|
args: [mcp]
|
|
cwd: !!js process.cwd()
|
|
env:
|
|
REA_LOG_LEVEL: !!js process.env.REA_LOG_LEVEL
|
|
- *op
|
|
`;
|
|
await writeFile(config, original);
|
|
const environment = { HOME: home, USERPROFILE: home, DSH_HOME: profile };
|
|
const run = (args: readonly string[]) =>
|
|
cli.run({
|
|
arguments: [...args, "--json"],
|
|
cwd: home,
|
|
environment,
|
|
});
|
|
const plan = await run(["setup", "--client", "dsh", "--dry-run"]);
|
|
expect(plan.exitCode).toBe(0);
|
|
expect(plan.json).toMatchObject({
|
|
status: "planned",
|
|
appliedActions: [],
|
|
plannedActions: expect.arrayContaining([
|
|
expect.objectContaining({ id: "configure_client:dsh", target: config }),
|
|
expect.objectContaining({ id: "install_skill" }),
|
|
]),
|
|
});
|
|
expect(await readFile(config, "utf8")).toBe(original);
|
|
await expect(readFile(`${config}.rea.backup`)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
const unapproved = await run(["setup", "--client", "dsh"]);
|
|
expect(unapproved.json).toMatchObject({
|
|
status: "needs_confirmation",
|
|
appliedActions: [],
|
|
});
|
|
expect(await readFile(config, "utf8")).toBe(original);
|
|
const configured = await run(["setup", "--client", "dsh", "--yes"]);
|
|
expect(configured.exitCode).toBe(0);
|
|
expect(configured.json).toMatchObject({
|
|
status: "ready",
|
|
clients: { dsh: { status: "configured" } },
|
|
});
|
|
const text = await readFile(config, "utf8");
|
|
expect(text).toContain("# caller home patch");
|
|
const patches = parse(text, {
|
|
customTags: [
|
|
{
|
|
tag: "tag:yaml.org,2002:js",
|
|
resolve: (source: string) => ({ __jsExpr: source }),
|
|
},
|
|
],
|
|
}) as { insert?: { id: string; config: unknown }[] }[];
|
|
const rows = patches.flatMap((patch) => patch.insert ?? []);
|
|
expect(rows.filter(({ id }) => id === "unrelated")).toEqual([
|
|
{
|
|
id: "unrelated",
|
|
name: "caller-plugin",
|
|
disabled: true,
|
|
config: { cwd: { __jsExpr: "process.cwd()" } },
|
|
},
|
|
]);
|
|
expect(rows.filter(({ id }) => id === "rea-mcp")).toHaveLength(1);
|
|
const registration = z
|
|
.object({
|
|
command: z.string(),
|
|
args: z.array(z.string()),
|
|
cwd: z.unknown(),
|
|
env: z.unknown(),
|
|
})
|
|
.parse(rows.find(({ id }) => id === "rea-mcp")?.config);
|
|
expect(registration.cwd).toEqual({ __jsExpr: "process.cwd()" });
|
|
expect(registration.env).toMatchObject({
|
|
REA_LOG_LEVEL: { __jsExpr: "process.env.REA_LOG_LEVEL" },
|
|
});
|
|
const doctor = await run(["doctor", "--client", "dsh", "--skill"]);
|
|
expect(doctor.exitCode).toBe(0);
|
|
expect(doctor.json).toMatchObject({
|
|
healthy: true,
|
|
identity: {
|
|
registrations: expect.arrayContaining([
|
|
expect.objectContaining({ client: "dsh", state: "aligned" }),
|
|
]),
|
|
},
|
|
});
|
|
await verifyGeneratedLauncher(registration, home, environment);
|
|
const repeated = await run(["setup", "--client", "dsh", "--yes"]);
|
|
expect(repeated.json).toMatchObject({
|
|
status: "ready",
|
|
appliedActions: [],
|
|
plannedActions: [],
|
|
});
|
|
expect(await readFile(config, "utf8")).toBe(text);
|
|
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
|
const removed = await run(["uninstall"]);
|
|
expect(removed.exitCode).toBe(0);
|
|
expect(removed.json).toMatchObject({
|
|
status: "complete",
|
|
items: expect.arrayContaining([
|
|
expect.objectContaining({ name: "dsh", status: "removed" }),
|
|
]),
|
|
});
|
|
const remaining = parse(await readFile(config, "utf8"), {
|
|
logLevel: "silent",
|
|
}) as { insert?: { id: string }[] }[];
|
|
expect(
|
|
remaining.flatMap((patch) => patch.insert ?? []).map(({ id }) => id),
|
|
).toEqual(["unrelated"]);
|
|
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
|
await expect(readFile(skill)).rejects.toMatchObject({ code: "ENOENT" });
|
|
},
|
|
);
|
|
|
|
async function verifyGeneratedLauncher(
|
|
registration: { command: string; args: string[] },
|
|
home: string,
|
|
environment: Record<string, string>,
|
|
): Promise<void> {
|
|
// Exercise the generated launcher. Native Cordis expression evaluation belongs
|
|
// to verify:deepseek-client, not this SDK transport journey.
|
|
const transport = new StdioClientTransport({
|
|
command: registration.command,
|
|
args: registration.args,
|
|
cwd: home,
|
|
env: schemaVerifierEnvironment({
|
|
PATH: process.env.PATH ?? "",
|
|
...environment,
|
|
}),
|
|
stderr: "pipe",
|
|
});
|
|
const client = new Client({ name: "dsh-setup-lifecycle", version: "1" });
|
|
try {
|
|
await client.connect(transport);
|
|
expect((await client.listTools()).tools.map(({ name }) => name)).toContain(
|
|
"binary_session",
|
|
);
|
|
const session = await artifactMcpCall(client, {
|
|
name: "binary_session",
|
|
arguments: {},
|
|
});
|
|
expect(session.isError).not.toBe(true);
|
|
expect(session.structuredContent).toMatchObject({
|
|
result: { open: false },
|
|
});
|
|
} finally {
|
|
await client.close();
|
|
await transport.close();
|
|
}
|
|
}
|
|
|
|
cliTest.for(["null", "caller-value", "[caller-value]"])(
|
|
"DSH CLI refuses to edit config %s and plain uninstall removes its owned row",
|
|
async (configValue, { cli }) => {
|
|
const home = await createTestTempDirectory("rea-dsh-malformed-config-");
|
|
const profile = join(home, ".dsh");
|
|
const config = join(profile, "cordis.patch.yml");
|
|
await mkdir(profile);
|
|
const initial = `# caller patch
|
|
- insert:
|
|
- id: other
|
|
name: caller-plugin
|
|
- id: rea-mcp
|
|
name: '@deepseek-ai/dsh-mcp-client'
|
|
config: ${configValue}
|
|
`;
|
|
await writeFile(config, initial);
|
|
const run = (args: readonly string[]) =>
|
|
cli.run({
|
|
arguments: [...args, "--json"],
|
|
cwd: home,
|
|
environment: { HOME: home, USERPROFILE: home, DSH_HOME: profile },
|
|
});
|
|
const configured = await run(["setup", "--client", "dsh", "--yes"]);
|
|
expect(configured.exitCode).not.toBe(0);
|
|
expect(configured.json).toMatchObject({
|
|
status: "needs_human",
|
|
appliedActions: [],
|
|
remediation: expect.stringContaining("config: Use a literal mapping"),
|
|
});
|
|
expect(await readFile(config, "utf8")).toBe(initial);
|
|
await expect(readFile(`${config}.rea.backup`)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
const removed = await run(["uninstall"]);
|
|
expect(removed.exitCode).toBe(0);
|
|
expect(removed.json).toMatchObject({
|
|
status: "complete",
|
|
items: expect.arrayContaining([
|
|
expect.objectContaining({ name: "dsh", status: "removed" }),
|
|
]),
|
|
});
|
|
const remaining = await readFile(config, "utf8");
|
|
expect(remaining).toContain("# caller patch");
|
|
expect(parse(remaining)).toEqual([
|
|
{ insert: [{ id: "other", name: "caller-plugin" }] },
|
|
]);
|
|
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(initial);
|
|
},
|
|
);
|
|
|
|
cliTest.for([
|
|
{
|
|
label: "group-owned rows",
|
|
patch: `- id: tools
|
|
insert:
|
|
- id: other
|
|
name: caller-plugin
|
|
- id: rea-mcp
|
|
name: '@deepseek-ai/dsh-mcp-client'
|
|
config: {serverName: rea, transport: stdio, command: stale, args: [mcp]}
|
|
`,
|
|
remediation: "group with unknown activity",
|
|
removal: "removed",
|
|
},
|
|
{
|
|
label: "expression-backed inserts",
|
|
patch: "- insert: !!js process.env.DSH_ROWS\n",
|
|
remediation: "unknown structure",
|
|
removal: "retained",
|
|
},
|
|
])(
|
|
"DSH CLI rejects setup and preserves ownership for $label",
|
|
async ({ patch, remediation, removal }, { cli }) => {
|
|
const home = await createTestTempDirectory("rea-dsh-ownership-");
|
|
const profile = join(home, ".dsh");
|
|
const config = join(profile, "cordis.patch.yml");
|
|
await mkdir(profile);
|
|
await writeFile(config, patch);
|
|
const run = (args: readonly string[]) =>
|
|
cli.run({
|
|
arguments: [...args, "--json"],
|
|
cwd: home,
|
|
environment: { HOME: home, USERPROFILE: home, DSH_HOME: profile },
|
|
});
|
|
const setup = await run(["setup", "--client", "dsh", "--yes"]);
|
|
expect(setup.exitCode).not.toBe(0);
|
|
expect(setup.json).toMatchObject({
|
|
status: "needs_human",
|
|
appliedActions: [],
|
|
remediation: expect.stringContaining(remediation),
|
|
});
|
|
expect(await readFile(config, "utf8")).toBe(patch);
|
|
await expect(readFile(`${config}.rea.backup`)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
const uninstall = await run(["uninstall"]);
|
|
expect(uninstall.exitCode).toBe(0);
|
|
expect(uninstall.json).toMatchObject({
|
|
status: "complete",
|
|
items: expect.arrayContaining([
|
|
expect.objectContaining({ name: "dsh", status: removal }),
|
|
]),
|
|
});
|
|
if (removal === "removed") {
|
|
expect(parse(await readFile(config, "utf8"))).toEqual([
|
|
{ id: "tools", insert: [{ id: "other", name: "caller-plugin" }] },
|
|
]);
|
|
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(patch);
|
|
} else {
|
|
expect(await readFile(config, "utf8")).toBe(patch);
|
|
await expect(readFile(`${config}.rea.backup`)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
}
|
|
},
|
|
);
|