Files
reverse-engineering-anything/tests/boundary/cli/cliToolCoverage.test.ts
T
morluto 48220827c4 test(cli): report CLI fields that admit values their contract refuses (#10575)
* test(cli): report CLI fields that admit values their contract refuses

For every CLI command that reaches an MCP contract, compare each
name-matched CLI field with its contract field on empty, NUL,
caller-relative host path and numeric argv spellings. The 16 mismatches on
main are recorded in a baseline with a counted ceiling that can only go
down: a new mismatch fails, and so does a listed one that no longer occurs.

* test: cover constrained CLI contract fields

* fix(cli): admit relative web trace paths

* test(cli): probe numeric contract fields by type, including bounds

Numeric probes no longer require the contract to admit 0 or 1, so ranged fields such as inspect-byte-entropy --block-size (256..65536) are compared, with probes just past each declared bound.

* fix(cli): describe caller-relative web trace paths and expect native Windows spellings

The relative-path CLI arguments lost their contract descriptions; they now describe the caller-relative resolution. absoluteCallerPath renders native separators on Windows, so the web trace acceptance tests use native manifest paths for CLI and MCP parity.

* test(cli): keep forward-slash Windows manifest coverage through MCP

The CLI renders caller paths with native separators through absoluteCallerPath; MCP keeps the caller's spelling. The web trace parity tests now also call MCP with the forward-slash manifest spelling and expect the same trace with that path echoed, restoring the #1078 coverage.
2026-11-15 17:07:09 +08:00

129 lines
4.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { createCli } from "../../../src/cli.js";
import { createCliInventory } from "../../../scripts/lib/catalog-cli.mjs";
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
import { CLI_COMMAND_NAMES } from "../../../src/cliCommandNames.js";
import { CLI_COMMAND_TOOL_ALIASES } from "./cliContractAliases.js";
/** MCP operations without a dedicated CLI command or direct command alias. */
const MCP_TOOLS_WITHOUT_DEDICATED_CLI = Object.freeze([
// Runtime settings belong to the long-lived MCP server; CLI calls use launch/per-call controls.
"inspect_analysis_settings",
"update_analysis_settings",
// MCP session control selects a resource root; CLI resource commands take paths directly.
"open_bundle_resources",
"address_name",
"comment",
"current_address",
"current_procedure",
"current_document",
"goto_address",
"inline_comment",
"list_bookmarks",
"list_documents",
"list_names",
"list_procedures",
"list_segments",
"list_strings",
"next_address",
"prev_address",
"procedure_address",
"procedure_assembly",
"procedure_callees",
"procedure_callers",
"procedure_info",
"resolve_containing_procedure",
"set_address_name",
"set_addresses_names",
"set_bookmark",
"set_comment",
"set_inline_comment",
"unset_bookmark",
"get_objc_classes",
"get_objc_protocols",
"batch_decompile",
"get_call_graph",
"analyze_swift_types",
"find_xrefs_to_name",
"trace_call_path",
"open_binary",
"close_binary",
// Investigation reset acts on the long-lived MCP server's retained history.
"reset_investigation",
"binary_session",
"export_evidence_bundle",
"import_evidence_bundle",
"compare_functions",
"find_changed_behavior",
"build_call_path",
"correlate_static_and_runtime",
"verify_reconstruction",
"list_unknowns",
"record_unknown",
"update_unknown",
"verify_unknown_resolution",
"get_evidence_bundle",
"get_navigation_context",
"inspect_address_context",
"start_gdb_session",
"gdb_session_status",
"close_gdb_session",
"start_rizin_debug_session",
"rizin_debug_session_status",
"close_rizin_debug_session",
"start_frida_session",
"load_frida_script",
"resume_frida_session",
"unload_frida_script",
"frida_session_status",
"close_frida_session",
// Build computers are held by the long-lived MCP server between actions.
"start_build_computer",
"act_on_build_computer",
"close_build_computer",
"start_build_capture",
"mark_build_checkpoint",
"stop_build_capture",
"export_build_environment",
"check_build_task",
"measure_build_task",
"record_build_consent",
]);
describe("CLI canonical tool coverage", () => {
it("accounts for every MCP tool on the CLI or marks it intentionally MCP-only", () => {
const registeredCli = createCliInventory(createCli());
const registeredCommandNames = new Set([
...registeredCli.primary,
...registeredCli.aliases.map(({ name }) => name),
]);
const cliToolNames = new Set(
registeredCli.primary.map((command) => command.replaceAll("-", "_")),
);
for (const [command, names] of Object.entries(CLI_COMMAND_TOOL_ALIASES)) {
expect(registeredCommandNames.has(command)).toBe(true);
for (const name of names) cliToolNames.add(name);
}
for (const command of CLI_COMMAND_NAMES)
expect(registeredCommandNames.has(command)).toBe(true);
const intentionalMcpOnly = new Set<string>(MCP_TOOLS_WITHOUT_DEDICATED_CLI);
expect(
[...intentionalMcpOnly].filter((name) => cliToolNames.has(name)).sort(),
).toEqual([]);
const unaccounted = TOOL_CONTRACTS.map(({ name }) => name).filter(
(name) => !cliToolNames.has(name) && !intentionalMcpOnly.has(name),
);
expect(unaccounted).toEqual([]);
expect(new Set(MCP_TOOLS_WITHOUT_DEDICATED_CLI).size).toBe(
MCP_TOOLS_WITHOUT_DEDICATED_CLI.length,
);
expect(
MCP_TOOLS_WITHOUT_DEDICATED_CLI.every((name) =>
TOOL_CONTRACTS.some((contract) => contract.name === name),
),
).toBe(true);
});
});