mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
* refactor(cli): render help pages with REA's help owner REA now renders the root page, every command page, help after an unknown command, the mcp group page, the mcp doctor builtin page and the completions page before incur sees argv, with incur's precedence (update check, --update without help, --mcp and the LLM manifests first; then the integrations; then --version; then root and command pages). help.ts gains arguments, custom global options, the root-only flags and integrations, and a command-list page. The --format row on the root and command pages now lists csv and tsv (#10250), the approved difference; the mcp and mcp add pages keep the document formats they accept. Every other help byte is unchanged: 397 pages compared with incur's Help for all 196 registered commands. Fixes #10250 * test(cli): elide the root command list wherever the root page is printed The golden renderer chose root-page elision by case name, so help after an unknown command froze the whole command list. It now elides any stdout that opens with the root page's rea@<version> title. * refactor(cli): answer --version, --schema and the LLM manifests in REA src/cli/discovery.ts answers help, --version, --schema, --llms and --llms-full with incur's precedence, reading the arguments as the dispatcher receives them (after result output has adapted them, so token counts and buffering are unchanged). commandManifests.ts renders the Markdown index and full manifest, the structured manifests and the --schema document; commandSuggestion.ts ranks Did-you-mean candidates. Both are adapted from incur under its MIT licence. --schema --format md stays with incur: incur renders it without Markdown escaping, unlike REA's renderer, and that difference awaits a decision on #11654. Compared with incur's serve for every registered command and format, 3746 of 3945 discovery invocations are identical; the rest are the 196 Markdown schemas left to incur and the three root help pages with the approved csv/tsv row. * test(cli): pin which discovery document wins when several are asked for Goldens for --llms with --help, --llms with --version, --llms with --llms-full, --schema with --version and --schema with --help, recorded with incur's rendering on the base branch. * refactor(cli): report unknown commands and the update notice from REA src/cli/updateNotice.ts owns the terminal update notice: the same trigger (terminal stdout, no explicit format), text, cache file ($XDG_CACHE_HOME/incur/updates/<package>.json), daily detached refresh through rea --incur-update-check, and opt-outs (NO_UPDATE_NOTIFIER, npm_config_update_notifier=false, CI). Discovery answers the detached refresh first, and reports an unknown command with incur's Did-you-mean suggestion, corrected invocation, help command and notice, as text on a terminal or as the error document, full-output envelope, token count or token window otherwise. outputEnvelope.ts renders these dispatcher failures. Unknown commands with --format md stay with incur pending the Markdown escaping decision on #11654. Compared with incur's serve, 224 of 224 unknown-command invocations are identical, piped and on a terminal with a due notice. * fix(cli): redact unknown-command guidance before rendering Share the producing reply boundary for root lookup, unknown schemas and MCP subcommands. Preserve ordinary argument identity and existing MCP suggestion policies; omit sensitive or unsafe replay commands and redact full-output command metadata. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> --------- Co-authored-by: gensokyo-dev <gensokyo-dev@users.noreply.github.com> Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
import { once } from "node:events";
|
|
import { readFile } from "node:fs/promises";
|
|
import { createServer } from "node:http";
|
|
import type { AddressInfo } from "node:net";
|
|
import { expect } from "vitest";
|
|
|
|
import { PRODUCT_IDENTITY } from "../../../src/identity.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
import {
|
|
createTestWorkspace,
|
|
removeTestWorkspace,
|
|
} from "../../support/workspace/workspaceFixture.js";
|
|
|
|
const cacheFile = (root: string) =>
|
|
`${root}/incur/updates/${encodeURIComponent(PRODUCT_IDENTITY.packageName)}.json`;
|
|
|
|
cliTest(
|
|
"the detached update check records the registry's latest version in the update cache",
|
|
async ({ cli }) => {
|
|
const workspace = await createTestWorkspace("rea-update-check-");
|
|
const requests: string[] = [];
|
|
const registry = createServer((request, response) => {
|
|
requests.push(request.url ?? "");
|
|
response.setHeader("content-type", "application/json");
|
|
response.end(JSON.stringify({ "dist-tags": { latest: "999.1.0" } }));
|
|
});
|
|
registry.listen(0, "127.0.0.1");
|
|
await once(registry, "listening");
|
|
try {
|
|
const { port } = registry.address() as AddressInfo;
|
|
const result = await cli.run({
|
|
arguments: ["--incur-update-check"],
|
|
freshProcess: true,
|
|
environment: {
|
|
...workspace.environment,
|
|
XDG_CACHE_HOME: workspace.path("cache"),
|
|
npm_config_registry: `http://127.0.0.1:${port}/`,
|
|
},
|
|
});
|
|
expect(result).toMatchObject({ exitCode: 0, stdout: "", stderr: "" });
|
|
expect(requests).toEqual([
|
|
`/${encodeURIComponent(PRODUCT_IDENTITY.packageName)}`,
|
|
]);
|
|
const cache = JSON.parse(
|
|
await readFile(cacheFile(workspace.path("cache")), "utf8"),
|
|
) as { readonly checkedAt: unknown; readonly latest: unknown };
|
|
expect(cache).toEqual({
|
|
checkedAt: expect.any(Number),
|
|
latest: "999.1.0",
|
|
});
|
|
} finally {
|
|
registry.close();
|
|
await removeTestWorkspace(workspace.root);
|
|
}
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"an unreachable registry leaves the update cache unwritten and the check silent",
|
|
async ({ cli }) => {
|
|
const workspace = await createTestWorkspace("rea-update-check-");
|
|
try {
|
|
const result = await cli.run({
|
|
arguments: ["--incur-update-check"],
|
|
freshProcess: true,
|
|
environment: {
|
|
...workspace.environment,
|
|
XDG_CACHE_HOME: workspace.path("cache"),
|
|
npm_config_registry: "http://127.0.0.1:9/",
|
|
},
|
|
});
|
|
expect(result).toMatchObject({ exitCode: 0, stdout: "", stderr: "" });
|
|
await expect(
|
|
readFile(cacheFile(workspace.path("cache")), "utf8"),
|
|
).rejects.toMatchObject({ code: "ENOENT" });
|
|
} finally {
|
|
await removeTestWorkspace(workspace.root);
|
|
}
|
|
},
|
|
);
|