Files
reverse-engineering-anything/tests/acceptance/cliBuiltinDocumentTokens.test.ts
T
morlutoandCopilot Autofix powered by AI 675d4076de test: strengthen regression oracles and cleanup ownership (#8152)
* test: strengthen suite oracles and cleanup ownership

* test: reuse setup across independent scenarios (#8153)

* Potential fix for pull request finding 'CodeQL / Improper code sanitization'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2026-10-31 00:22:16 +08:00

75 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { estimateTokenCount } from "tokenx";
import { expect } from "vitest";
import { workspaceCliTest } from "../support/cli/workspaceCliFixture.js";
import { runFileCli } from "../support/cli/cliFixture.js";
workspaceCliTest(
"applies token controls to SDK 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 (!freshTokenCount &&
!freshTokenLimit &&
(arguments_.includes("--token-count") ||
arguments_.includes("--token-limit"))
? runFileCli(cli, invocation)
: cli.run(invocation));
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 Incur's 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"),
);
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");
},
);