mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 09:56:23 +00:00
* fix(cli): reject invalid inline values and honor requested output on terminals - Reject inline boolean and empty number values the schema cannot accept instead of coercing --skill=yes to false or --limit= to 0. - Give captured mcp add output the terminal presentation of every other command through one shared result destination. - Show the unapproved setup plan whose remediation asks a terminal reader to review it, and open the setup rail once when a scoped run starts at approval. - Treat --full-output and --token-count as requesting the result document, so setup and argument errors no longer add terminal presentation beside it. - Answer --schema for an unknown command in the selected format, and set the exit code instead of exiting so piped stdout drains. * fix(cli): keep rejected boolean and number literals across repeated flags Binding stored one scalar value, so a later valid flag replaced an earlier literal before the schema could reject it. Boolean and number literals the field rejects now stay bound, including decimal unions and count options, while repeated valid flags still use the last value. --dry-run keeps its own error. * test(cli): assert the terminal full-output failure envelope The terminal --full-output regression only checked that usage text was absent. Decode the default document and the --json envelope and require VALIDATION_ERROR with the skill field's invalid_type error. * test(cli): accept a counted setup approval prompt A scoped terminal plan names every eligible action, so a Linux host that can install Hopper asks "Apply these N changes?" rather than the singular question. The consent helper now answers either prompt, and the rail test finds that question before checking the intro was rendered once. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.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),
|
|
structuredOutput: 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),
|
|
},
|
|
});
|
|
});
|