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>
84 lines
3.1 KiB
TypeScript
84 lines
3.1 KiB
TypeScript
import { estimateTokenCount } from "tokenx";
|
||
import { expect } from "vitest";
|
||
|
||
import { workspaceCliTest } from "../support/cli/workspaceCliFixture.js";
|
||
|
||
workspaceCliTest(
|
||
"applies token controls to manifest and schema documents",
|
||
async ({ cli }) => {
|
||
const run = async (...arguments_: string[]) => {
|
||
const invocation = { arguments: arguments_ };
|
||
const freshTokenCount = arguments_.join(" ") === "--llms --token-count";
|
||
const freshTokenLimit =
|
||
arguments_.join(" ") === "--llms-full --token-limit 1";
|
||
const result = await cli.run({
|
||
...invocation,
|
||
freshProcess: !(
|
||
!freshTokenCount &&
|
||
!freshTokenLimit &&
|
||
(arguments_.includes("--token-count") ||
|
||
arguments_.includes("--token-limit"))
|
||
),
|
||
});
|
||
expect(result.exitCode, result.stderr).toBe(0);
|
||
expect(result.stderr).toBe("");
|
||
return result.stdout;
|
||
};
|
||
|
||
for (const args of [
|
||
["--llms"],
|
||
["--llms-full"],
|
||
["--llms-full", "--format", "json"],
|
||
["inspect-devicetree", "--schema"],
|
||
["inspect-devicetree", "--schema", "--format", "json"],
|
||
]) {
|
||
const document = await run(...args);
|
||
expect(await run(...args, "--token-count")).toBe(
|
||
`${estimateTokenCount(document)}\n`,
|
||
);
|
||
}
|
||
|
||
const document = await run("--llms-full");
|
||
const page = await run("--llms-full", "--token-limit", "1");
|
||
expect(page.length).toBeLessThan(document.length);
|
||
expect(page).toMatch(/\[truncated: showing tokens 0–1 of \d+\]\n$/);
|
||
expect(await run("--llms-full", "--token-limit", "1000000")).toBe(document);
|
||
expect(
|
||
await run("inspect-devicetree", "--schema", "--token-limit", "1"),
|
||
).toMatch(/\[truncated: showing tokens 0–1 of \d+\]\n$/);
|
||
|
||
// Schema does not outrank help or plain version in CLI dispatch.
|
||
expect(
|
||
await run("inspect-devicetree", "--schema", "--help", "--token-count"),
|
||
).toBe(await run("inspect-devicetree", "--schema", "--help"));
|
||
expect(await run("--schema", "--version", "--token-count")).toBe(
|
||
await run("--schema", "--version"),
|
||
);
|
||
expect(await run("completions", "bash", "--schema", "--token-count")).toBe(
|
||
await run("completions", "bash", "--schema"),
|
||
);
|
||
|
||
expect(await run("completions", "bash", "--json", "--token-count")).toBe(
|
||
await run("completions", "bash", "--json"),
|
||
);
|
||
const bash = await run("completions", "bash");
|
||
expect(await run("completions", "bash", "--schema")).toBe(bash);
|
||
expect(await run("completions", "bash", "--version")).toBe(bash);
|
||
|
||
const unknown = await cli.run({
|
||
arguments: ["no-such-command", "--schema"],
|
||
});
|
||
const unknownCount = await cli.run({
|
||
arguments: ["no-such-command", "--schema", "--token-count"],
|
||
});
|
||
expect(unknown.exitCode).toBe(1);
|
||
expect(unknownCount.exitCode).toBe(1);
|
||
expect(unknownCount.stdout).toBe(unknown.stdout);
|
||
const structuredWindow = await cli.run({
|
||
arguments: ["--llms-full", "--format", "json", "--token-limit", "1"],
|
||
});
|
||
expect(structuredWindow.exitCode).toBe(1);
|
||
expect(structuredWindow.stdout).toContain("UNSUPPORTED_OUTPUT_COMBINATION");
|
||
},
|
||
);
|