Files
reverse-engineering-anything/tests/boundary/cli/contractJsonInputChecks.test.ts
T
Ysopwnableandgensokyo-dev 62014b566d refactor(cli)!: dispatch commands through REA-owned execution
Run ordinary CLI commands through REA's registry, argv parser and result owner.
Remove Incur, the second admission parse, SDK error middleware, output capture
and redundant command traversal. Preserve explicit redaction, publication
receipts, incremental output, terminal notice eligibility and drain ownership.
Migrate fixtures to real registrations and retain the derived-source notices.

Validation includes unchanged public parity goldens, public and lifecycle
regressions, repaired fixture consumers, real TTY base comparisons, exports
beyond the engine string limit, four schema catalogs and final static/docs
checks. Native provider and optional validator coverage limits are in the PR.

Fixes #11654. Fixes #10583. Refs #11682, #11476 and #10511.

BREAKING CHANGE: Markdown argument diagnostics use REA's literal escaping,
table widths and token counts. Flag-shaped unknown MCP subcommands honor the
selected format. Completion --schema/--version routes use the canonical
REA-owned hook rather than the retired SDK generator. Refresh affected literal
snapshots and regenerate completion hooks with rea completions <shell>.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-11-16 13:56:34 +00:00

70 lines
2.4 KiB
TypeScript

import { cliCommand } from "../../../src/cli/commandRegistry.js";
import { createCommandCli } from "../../support/cli/commandCli.js";
import { expect, it } from "vitest";
import { z } from "zod";
import { registerContractCommand } from "../../../src/cli/contractCommand.js";
import type { CliInstance } from "../../../src/cli/types.js";
import { ok } from "../../../src/domain/result.js";
import { silentLogger } from "../../../src/logger.js";
it("admits a checked JSON input through its check only, and the rest through the contract", async () => {
let documentParses = 0;
const contract = {
name: "compare_checked_fixture",
inputSchema: z.strictObject({
// Registration probes the field with undefined; count document walks.
document: z.custom<object>((value) => {
if (value !== undefined) documentParses += 1;
return true;
}),
max_age_ms: z.int().nonnegative().optional(),
}),
};
const received: unknown[] = [];
const cli = createCommandCli();
registerContractCommand(
cli as unknown as CliInstance,
silentLogger,
contract,
{
command: "compare-checked-fixture",
description: "Checked fixture",
positionals: ["document"],
jsonInputs: { document: "document must be JSON" },
jsonInputChecks: {
document: (value) => ok({ checked: value }),
},
},
async (_input, { checked, parsed }) => {
received.push({ checked, parsed });
return {};
},
);
const command = cliCommand(cli, "compare-checked-fixture")?.definition;
if (command === undefined) throw new Error("command is not registered");
const parse = (key: "args" | "options", value: unknown) =>
(Reflect.get(command, key) as { parse(v: unknown): unknown }).parse(value);
const run = (options: unknown) =>
(Reflect.get(command, "run") as (value: unknown) => Promise<unknown>)({
args: parse("args", { document: '{"records":[1,2,3]}' }),
options,
});
await run(parse("options", { maxAgeMs: 5 }));
expect(documentParses).toBe(0);
expect(received).toEqual([
{
checked: { document: { checked: { records: [1, 2, 3] } } },
parsed: { document: { records: [1, 2, 3] }, max_age_ms: 5 },
},
]);
// The contract still admits the remaining fields, past argv parsing.
expect(await run({ maxAgeMs: -1 })).toMatchObject({
code: "invalid_request",
details: { issues: [{ path: ["maxAgeMs"] }] },
});
expect(documentParses).toBe(0);
});