fix(contracts): align CLI/MCP boundary contracts (#946)

* fix(cli): validate native scenario and preserve JSON paths

* fix(process): reject invalid UTF-8 JSON inputs

* fix(cli): retain missing JSON path diagnostics

* test(cli): cover relative brace and bracket JSON paths

* test(cli): reject missing native scenario steps

* fix(mcp): advertise reserved process environment key

* fix(process): reject NUL in process scenario values

* fix(process): advertise NUL input constraints to MCP

* fix(cli): report scenario input schema issues

* fix(contracts): align CLI and MCP input validation

* fix(mcp): document semantic output constraints

* fix(mcp): describe process journal compatibility

* docs: regenerate catalog after schema grouping

* docs: regenerate catalog after main merge

* fix(cli): preserve JSON and native UI input diagnostics

* test(mcp): reuse advertised tool schemas in managed flow
This commit is contained in:
morluto
2026-10-08 00:03:36 +08:00
committed by GitHub
parent fc4a9a0592
commit 4a6073810a
26 changed files with 897 additions and 58 deletions
+128 -1
View File
@@ -113,7 +113,7 @@ describe("compiled CLI JSON input failure status", () => {
XDG_CACHE_HOME: root,
},
});
expect(result.json).toMatchObject({
expect(JSON.parse(result.stdout.trim())).toMatchObject({
code: "invalid_request",
input_path: "",
input_reason: "read-failed",
@@ -121,6 +121,58 @@ describe("compiled CLI JSON input failure status", () => {
expect(result.exitCode).toBe(1);
},
);
cliTest(
"classifies an overlong malformed inline value before dispatch",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-cli-json-overlong-");
const input = `[${"x".repeat(3_000)}`;
const result = await cli.run({
arguments: ["compare-javascript-export-shapes", input, "--json"],
environment: {
HOME: root,
XDG_CONFIG_HOME: root,
XDG_CACHE_HOME: root,
},
});
expect(result.json).toMatchObject({
code: "invalid_request",
category: "invalid_input",
details: {
operation: "compare-javascript-export-shapes",
issues: [{ path: [], reason: "invalid_format", expected: "JSON" }],
},
});
expect(result.json).not.toHaveProperty("input_path");
expect(result.stdout).not.toContain("read-failed");
expect(result.stderr).toBe("");
expect(result.exitCode).toBe(1);
},
);
cliTest(
"preserves explicit overlong JSON path diagnostics",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-cli-json-overlong-path-");
const input = `[${"x".repeat(3_000)}.json`;
const result = await cli.run({
arguments: ["compare-javascript-export-shapes", input, "--json"],
environment: {
HOME: root,
XDG_CONFIG_HOME: root,
XDG_CACHE_HOME: root,
},
});
expect(result.json).toMatchObject({
code: "invalid_request",
input_path: input,
input_reason: "read-failed",
});
expect(result.exitCode).toBe(1);
},
);
});
describe("compiled JSON parser and logger success seam", () => {
@@ -159,3 +211,78 @@ describe("compiled JSON parser and logger success seam", () => {
},
);
});
describe("compiled CLI parser with relative brace and bracket paths", () => {
for (const filename of ["[input].json", "{capture}.json"])
cliTest(
`reads the selected relative file ${filename}`,
async ({ processes }) => {
const root = await createTestTempDirectory("rea-cli-json-path-");
const value = { selected: filename };
await writeFile(join(root, filename), JSON.stringify(value));
const moduleUrl = new URL(
"../../../dist/cliJsonInput.js",
import.meta.url,
).href;
const result = await processes.run(
process.execPath,
[
"--input-type=module",
"-e",
`import { parseCliJsonInput } from ${JSON.stringify(moduleUrl)};
console.log(JSON.stringify(await parseCliJsonInput(process.argv[1], "test-input")));`,
filename,
],
{
cwd: root,
env: {
HOME: root,
XDG_CONFIG_HOME: root,
XDG_CACHE_HOME: root,
},
},
);
expect(result.stdout).toBe(`${JSON.stringify({ ok: true, value })}\n`);
expect(result.stderr).toBe("");
expect(result.exitCode).toBe(0);
},
);
for (const filename of ["[missing].json", "{missing}.json"])
cliTest(
`keeps missing relative path diagnostics for ${filename}`,
async ({ processes }) => {
const root = await createTestTempDirectory("rea-cli-json-missing-");
const moduleUrl = new URL(
"../../../dist/cliJsonInput.js",
import.meta.url,
).href;
const result = await processes.run(
process.execPath,
[
"--input-type=module",
"-e",
`import { parseCliJsonInput } from ${JSON.stringify(moduleUrl)};
console.log(JSON.stringify(await parseCliJsonInput(process.argv[1], "test-input")));`,
filename,
],
{
cwd: root,
env: {
HOME: root,
XDG_CONFIG_HOME: root,
XDG_CACHE_HOME: root,
},
},
);
expect(JSON.parse(result.stdout.trim())).toMatchObject({
ok: false,
error: { input_path: filename, input_reason: "read-failed" },
});
expect(result.stderr).toBe("");
expect(result.exitCode).toBe(0);
},
);
});