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>
134 lines
5.0 KiB
TypeScript
134 lines
5.0 KiB
TypeScript
import { cliCommand } from "../../../src/cli/commandRegistry.js";
|
|
import { createCommandCli } from "../../support/cli/commandCli.js";
|
|
import pino from "pino";
|
|
import { stat } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect, it, vi } from "vitest";
|
|
import { z } from "zod";
|
|
|
|
import { inspectAnalysisView } from "../../../src/application/analysisView/AnalysisViewService.js";
|
|
import { registerCoreBinaryCommands } from "../../../src/cli/coreBinaryCommands.js";
|
|
import type { CliInstance } from "../../../src/cli/types.js";
|
|
import { CLI_COMMANDS } from "../../../src/contracts/cliCommandNames.js";
|
|
import { createEvidence } from "../../../src/domain/evidence.js";
|
|
import { functionDossierSchema } from "../../../src/domain/native/functionDossier.js";
|
|
import { ghidraFunctionDossier } from "../../../src/domain/ghidraValues.fixture.js";
|
|
import { ok } from "../../../src/domain/result.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
// A complete analyze_function Evidence as runDirectAnalysis would return it:
|
|
// subject-bound (so the summary view has an artifact) with a schema-valid dossier.
|
|
const cannedCompleteEvidence = () =>
|
|
createEvidence(
|
|
{ path: "/fixtures/native.exe", format: "pe", sha256: "a".repeat(64) },
|
|
{ id: "ghidra", name: "Ghidra", version: "12.1.4" },
|
|
{
|
|
operation: "analyze_function",
|
|
parameters: { procedure: "main" },
|
|
result: functionDossierSchema.parse(ghidraFunctionDossier()),
|
|
rawResult: null,
|
|
},
|
|
);
|
|
|
|
const harness = () => {
|
|
const runDirectAnalysis = vi.fn<
|
|
Parameters<typeof registerCoreBinaryCommands>[2]
|
|
>(async () => ok(cannedCompleteEvidence()));
|
|
const cli = createCommandCli();
|
|
registerCoreBinaryCommands(
|
|
cli as unknown as CliInstance,
|
|
pino({ enabled: false }),
|
|
runDirectAnalysis,
|
|
{},
|
|
);
|
|
const command = cliCommand(cli, CLI_COMMANDS.function)?.definition;
|
|
if (command === undefined)
|
|
throw new Error("function command was not registered");
|
|
const argsSchema = command.args;
|
|
const optionsSchema = command.options;
|
|
if (
|
|
!(argsSchema instanceof z.ZodObject) ||
|
|
!(optionsSchema instanceof z.ZodObject)
|
|
)
|
|
throw new Error("function command has no input schemas");
|
|
const invoke = async (options: Record<string, unknown>): Promise<unknown> =>
|
|
command.run({
|
|
args: argsSchema.parse({
|
|
path: "/fixtures/native.exe",
|
|
address: "main",
|
|
}),
|
|
options: optionsSchema.parse(options),
|
|
formatExplicit: false,
|
|
});
|
|
return { runDirectAnalysis, invoke };
|
|
};
|
|
|
|
it("defaults to the complete dossier and runs analysis", async () => {
|
|
const h = harness();
|
|
const out = (await h.invoke({})) as { operation?: string };
|
|
expect(h.runDirectAnalysis).toHaveBeenCalledOnce();
|
|
expect(out.operation).toBe("analyze_function");
|
|
expect(
|
|
(out as { normalized_result?: unknown }).normalized_result,
|
|
).toBeDefined();
|
|
});
|
|
|
|
it("rejects summary delivery without --evidence_output before any analysis", async () => {
|
|
const h = harness();
|
|
const out = await h.invoke({ detail: "summary" });
|
|
expect(h.runDirectAnalysis).not.toHaveBeenCalled();
|
|
expect(out).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
operation: "analyze_function",
|
|
issues: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
path: ["evidence_output"],
|
|
reason: "invalid_value",
|
|
}),
|
|
]),
|
|
},
|
|
});
|
|
});
|
|
|
|
it("summary delivery returns the compact view and writes a bundle inspect-analysis-view pages", async () => {
|
|
const h = harness();
|
|
const directory = await createTestTempDirectory("rea-fn-detail-");
|
|
const destination = join(directory, "complete.json");
|
|
const out = (await h.invoke({
|
|
detail: "summary",
|
|
evidence_output: destination,
|
|
})) as {
|
|
summary: {
|
|
normalized_result: { kind: string; parent_evidence_id: string };
|
|
};
|
|
evidence_bundle: { path: string; bytes: number };
|
|
};
|
|
expect(h.runDirectAnalysis).toHaveBeenCalledOnce();
|
|
expect(h.runDirectAnalysis.mock.calls[0]?.[3]).toMatchObject({
|
|
includeEvidenceSources: true,
|
|
});
|
|
expect(out.summary.normalized_result.kind).toBe("summary");
|
|
expect(typeof out.summary.normalized_result.parent_evidence_id).toBe(
|
|
"string",
|
|
);
|
|
expect(out.evidence_bundle.bytes).toBeGreaterThan(0);
|
|
expect((await stat(destination)).size).toBeGreaterThan(0);
|
|
// The saved bundle is the evidence-file source inspect-analysis-view reads back.
|
|
const parentId = out.summary.normalized_result.parent_evidence_id;
|
|
const page = await inspectAnalysisView({
|
|
source: { kind: "evidence-file", path: destination, evidence_id: parentId },
|
|
view: { kind: "native", facet: "pseudocode", offset: 0, limit: 16 },
|
|
});
|
|
if (!page.ok) throw page.error;
|
|
expect(page.value.parameters).toMatchObject({ parent_evidence_id: parentId });
|
|
expect(page.value.normalized_result).toMatchObject({
|
|
kind: "native",
|
|
item: {
|
|
text: functionDossierSchema
|
|
.parse(ghidraFunctionDossier())
|
|
.pseudocode.slice(0, 16),
|
|
},
|
|
});
|
|
});
|