Files
reverse-engineering-anything/tests/boundary/cli/cliFullOutputTokenCount.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

76 lines
2.1 KiB
TypeScript

import { Writable } from "node:stream";
import { estimateTokenCount } from "tokenx";
import { describe, expect, it } from "vitest";
import { formatCliOutput } from "../../../src/cli/cliOutputFormatter.js";
import { parseCliOutputArguments } from "../../../src/cliOutput.js";
import { createCliResultOutput } from "../../../src/cli/cliResultOutput.js";
const countFor = async (
value: unknown,
format: "toon" | "yaml",
notice = false,
): Promise<{ readonly handled: boolean; readonly text: string }> => {
const chunks: Buffer[] = [];
const destination = new Writable({
write(chunk: Buffer, _encoding, callback) {
chunks.push(chunk);
callback();
},
});
const output = createCliResultOutput(
parseCliOutputArguments([
"fixture",
"--format",
format,
"--full-output",
"--token-count",
]),
destination,
);
if (output === undefined) throw new Error("Missing output surface");
const handled = await output.write(value, {
command: "fixture",
duration: "0ms",
...(notice
? {
cta: {
description: "Update available",
commands: [{ command: "rea --update" }],
},
}
: {}),
});
return { handled, text: Buffer.concat(chunks).toString("utf8") };
};
describe("full-output token counts", () => {
it.each(
(["toon", "yaml"] as const).flatMap((format) =>
[false, true].map((notice) => ({ format, notice })),
),
)(
"counts the emitted envelope without a terminal notice ($format, notice: $notice)",
async ({ format, notice }) => {
const value = { imported: 0, unknowns_added: 0, total: 0 };
const counted = await countFor(value, format, notice);
expect(counted.handled).toBe(true);
expect(counted.text).toBe(
`${estimateTokenCount(
formatCliOutput(
{
ok: true,
data: value,
meta: { command: "fixture", duration: "0ms" },
},
format,
),
)}\n`,
);
},
);
// The public CLI replay also covers bare counts for these formats.
});