mirror of
https://github.com/morluto/rea.git
synced 2026-11-17 04:04:25 +00:00
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>
96 lines
3.4 KiB
TypeScript
96 lines
3.4 KiB
TypeScript
import { cliCommand, cliCommands } from "../../../src/cli/commandRegistry.js";
|
|
import { describe, expect, it } from "vitest";
|
|
import { z } from "zod";
|
|
|
|
import { createCli } from "../../../src/cli.js";
|
|
import {
|
|
cliCommandOptionNames,
|
|
createCliInventory,
|
|
} from "../../../scripts/lib/catalog-cli.mjs";
|
|
|
|
type CliInstance = ReturnType<typeof createCli>;
|
|
|
|
const serve = async (
|
|
cli: CliInstance,
|
|
argv: readonly string[],
|
|
): Promise<{ readonly stdout: string; readonly exitCode: number }> => {
|
|
let stdout = "";
|
|
let exitCode = 0;
|
|
await cli.serve([...argv], {
|
|
env: {},
|
|
exit: (code) => {
|
|
exitCode = code;
|
|
},
|
|
stdout: (text) => {
|
|
stdout += text;
|
|
},
|
|
});
|
|
return { stdout, exitCode };
|
|
};
|
|
|
|
const registeredAliases = (
|
|
cli: CliInstance,
|
|
command: string,
|
|
): Record<string, unknown> => {
|
|
const entry = cliCommand(cli, command)?.definition;
|
|
const alias: unknown =
|
|
entry === undefined ? undefined : Reflect.get(entry, "alias");
|
|
return typeof alias === "object" && alias !== null ? { ...alias } : {};
|
|
};
|
|
|
|
describe("CLI option aliases", () => {
|
|
it("rejects an empty primary command inventory", () => {
|
|
expect(() => createCliInventory([])).toThrow(
|
|
"REA exposed no primary CLI commands",
|
|
);
|
|
});
|
|
|
|
it("register only single-character short flags", async () => {
|
|
const cli = createCli({});
|
|
const invalid: string[] = [];
|
|
const undescribed: string[] = [];
|
|
for (const command of createCliInventory(cliCommands(cli)).primary) {
|
|
for (const [option, short] of Object.entries(
|
|
registeredAliases(cli, command),
|
|
))
|
|
if (typeof short !== "string" || short.length !== 1)
|
|
invalid.push(`${command} ${option}: ${String(short)}`);
|
|
// Incur parses `-abc` as stacked one-letter flags, so help must never
|
|
// advertise a multi-letter single-dash spelling.
|
|
const help = await serve(cli, [command, "--help"]);
|
|
expect(help.exitCode, `${command} --help`).toBe(0);
|
|
expect(help.stdout, `${command} --help`).not.toBe("");
|
|
for (const match of help.stdout.matchAll(/(?:^|[\s,])-([a-z][\w-]+)/gmu))
|
|
invalid.push(`${command} help: -${match[1] ?? ""}`);
|
|
const options = /^Options:\n((?: {2}.*\n?)*)/mu.exec(help.stdout)?.[1];
|
|
const entry = cliCommand(cli, command)?.definition;
|
|
expect(entry, `${command} registration`).toBeDefined();
|
|
const schema: unknown = entry && Reflect.get(entry, "options");
|
|
if (schema !== undefined)
|
|
expect(schema, `${command} options schema`).toBeInstanceOf(z.ZodObject);
|
|
if (cliCommandOptionNames(cliCommands(cli), command).length > 0) {
|
|
expect(options, `${command} --help options`).toBeDefined();
|
|
expect(options, `${command} --help option entries`).toMatch(/^ --/mu);
|
|
}
|
|
for (const line of options?.split("\n") ?? [])
|
|
if (/^ {2}--\S+(?: <[^>]+>)?\s*$/u.test(line))
|
|
undescribed.push(`${command} ${line.trim()}`);
|
|
}
|
|
expect(invalid).toEqual([]);
|
|
expect(undescribed).toEqual([]);
|
|
});
|
|
|
|
it("accepts kebab-case long options without registered aliases", async () => {
|
|
const cli = createCli({});
|
|
const result = await serve(cli, [
|
|
"inspect-plist",
|
|
"/nonexistent/REA.app",
|
|
"--relative-path",
|
|
"Contents/Info.plist",
|
|
"--json",
|
|
]);
|
|
expect(result.stdout).not.toContain("Unknown flag");
|
|
expect(result.stdout).toContain("/nonexistent/REA.app");
|
|
});
|
|
});
|