refactor: return complete analysis results inline

This commit is contained in:
morluto
2026-09-29 08:07:24 +08:00
parent 07ff8b30ee
commit a2a3243ea8
127 changed files with 402 additions and 1508 deletions
@@ -78,7 +78,6 @@ async function runInlineEvidenceScenarios(
expect(compared.isError).not.toBe(true);
expect(compared.structuredContent).toMatchObject({
result: {
schema_version: 1,
summary: { unknown: expect.any(Number) },
coverage: { status: expect.any(String) },
},
@@ -94,7 +93,6 @@ async function runInlineEvidenceScenarios(
expect(sourceCompared.isError).not.toBe(true);
expect(sourceCompared.structuredContent).toMatchObject({
result: {
schema_version: 1,
reference: {
root_sha256: SOURCE_TO_BUNDLE_COMPARISON_EXAMPLE.reference.root_sha256,
},
@@ -116,7 +116,6 @@ describe("application workflow MCP parity", () => {
expect(semantic.isError).not.toBe(true);
expect(semantic.structuredContent).toMatchObject({
result: {
schema_version: 1,
source_evidence_id: left.value.evidence_id,
source_graph_id: analyzed.semantic_graph.graph_id,
summary: { retained_seed_matches: 1 },
@@ -93,7 +93,6 @@ function createReplayScenario(root: string) {
},
javascriptReplayRunner: {
execute: async (prepared) => ({
schema_version: 1,
plan_digest: prepared.publicPlan.plan_digest,
outcomes: [
{
@@ -60,7 +60,6 @@ describe("application workflow CLI parity", () => {
expect(compared).toMatchObject({
operation: "compare_application_versions",
normalized_result: {
schema_version: 1,
summary: { unknown: expect.any(Number) },
},
});
@@ -74,7 +73,7 @@ describe("application workflow CLI parity", () => {
]);
expect(sourceCompared).toMatchObject({
operation: "compare_source_to_bundle",
normalized_result: { schema_version: 1 },
normalized_result: { reference: expect.any(Object) },
});
}, 20_000);
@@ -177,7 +176,7 @@ describe("application workflow CLI Evidence resolution", () => {
);
expect(compared).toMatchObject({
operation: "compare_application_versions",
normalized_result: { schema_version: 1 },
normalized_result: { summary: expect.any(Object) },
});
const missingRecord = await runCli(
@@ -322,7 +321,6 @@ describe("application workflow CLI validation and replay", () => {
"--json",
]);
expect(inline).toMatchObject({
schema_version: 1,
final_state: "complete",
decisions: [{ outcome: "matched" }],
transition_journal: [
-56
View File
@@ -13,7 +13,6 @@ import {
} from "../../../src/cliOutput.js";
const CLI_INTEGRATION_TIMEOUT_MS = 60_000;
const CLI_VARIANT_TIMEOUT_MS = 120_000;
describe("CLI output argument and sanitization boundary", () => {
it("rejects token windows that would corrupt structured output", () => {
@@ -175,59 +174,4 @@ describe("compiled CLI output boundary", () => {
},
CLI_INTEGRATION_TIMEOUT_MS,
);
workspaceCliTest(
"keeps operation failure status independent of output controls",
async ({ cli }) => {
const variants = [
["--format", "toon"],
["--format", "json"],
["--format", "yaml"],
["--format", "md"],
["--format", "jsonl"],
["--filter-output", "category", "--json"],
["--token-limit", "5", "--json"],
["--token-count", "--json"],
];
for (const flags of variants) {
const result = await cli.run({
arguments: [
...flags,
"investigate-versions",
"/tmp/left",
"/tmp/right",
"/tmp/workspace.json",
],
});
expect(result).toMatchObject({
exitCode: 1,
stdout: expect.any(String),
});
}
},
CLI_VARIANT_TIMEOUT_MS,
);
workspaceCliTest(
"keeps failure logs out of structured stdout",
async ({ cli }) => {
const result = await cli.run({
arguments: [
"--json",
"investigate-versions",
"/tmp/left",
"/tmp/right",
"/tmp/workspace.json",
],
environment: { REA_LOG_LEVEL: "error" },
});
expect(result).toMatchObject({
exitCode: 1,
stderr: expect.stringContaining('"status":"error"'),
});
expect(result.json).toMatchObject({ error: "ApprovalRequired" });
},
CLI_INTEGRATION_TIMEOUT_MS,
);
});
@@ -16,7 +16,6 @@ describe("reconstruction obligation ledger CLI parity", () => {
bindings: [],
contradictions: [],
},
page: { offset: 0, limit: 50 },
};
const { stdout } = await execute(
process.execPath,
@@ -95,8 +95,6 @@ describe("evidence bundle filesystem adapter", () => {
await compareEvidenceBundlesCommand({
leftPath: path,
rightPath: path,
offset: 0,
limit: 100,
policy: policy(directory),
}),
).toMatchObject({
@@ -121,7 +121,7 @@ describe("JavaScript export return-shape comparison", () => {
});
describe("JavaScript export return-shape selection", () => {
it("reports selector candidates and enforces candidate, variant, and change limits", async () => {
it("returns complete candidate, variant, and change inventories", async () => {
const candidates = await analyzeSources({
left: `
export const first = () => ({ type: "first" });
@@ -132,38 +132,30 @@ describe("JavaScript export return-shape selection", () => {
});
const missing = compare(candidates[0], candidates[1], {
leftExportName: "missing",
limits: { max_candidate_exports: 1 },
});
expect(missing.left).toMatchObject({
status: "missing",
omitted_candidates: 2,
candidates: [expect.objectContaining({ module_path: "parser.mjs" })],
omitted_candidates: 0,
candidates: expect.arrayContaining([
expect.objectContaining({ export_name: "first" }),
expect.objectContaining({ export_name: "second" }),
expect.objectContaining({ export_name: "third" }),
]),
});
expect(missing.coverage.status).toBe("truncated");
const parsers = await sourceOwnedParsers();
const variantLimited = compare(parsers[0], parsers[1], {
limits: { max_return_variants: 1 },
});
expect(variantLimited.coverage).toMatchObject({
status: "truncated",
omitted_left_variants: 2,
omitted_right_variants: 2,
});
const variants = compare(parsers[0], parsers[1]);
expect(variants.coverage.omitted_left_variants).toBe(0);
expect(variants.coverage.omitted_right_variants).toBe(0);
const changes = await analyzeSources({
left: `export default () => ({ type: "item" });`,
right: `export default () => ({ type: "item", depth: 1, level: 2 });`,
});
const changeLimited = compare(changes[0], changes[1], {
limits: { max_changes: 1 },
});
expect(changeLimited.summary.added).toBe(2);
expect(changeLimited.changes).toHaveLength(1);
expect(changeLimited.coverage).toMatchObject({
status: "truncated",
omitted_changes: 1,
});
const complete = compare(changes[0], changes[1]);
expect(complete.summary.added).toBe(2);
expect(complete.changes).toHaveLength(2);
expect(complete.coverage.omitted_changes).toBe(0);
});
it("refuses an exact selector that resolves to multiple graph nodes", async () => {
@@ -241,11 +233,6 @@ const compare = (
options: {
readonly leftExportName?: string;
readonly rightExportName?: string;
readonly limits?: Partial<{
readonly max_candidate_exports: number;
readonly max_return_variants: number;
readonly max_changes: number;
}>;
} = {},
) =>
compareJavaScriptExportShapes({
@@ -261,11 +248,6 @@ const compare = (
modulePath: "parser.mjs",
exportName: options.rightExportName ?? "default",
},
limits: {
max_candidate_exports: options.limits?.max_candidate_exports ?? 100,
max_return_variants: options.limits?.max_return_variants ?? 128,
max_changes: options.limits?.max_changes ?? 1_000,
},
});
const analyzeGraph = async (root: string) => {
@@ -49,7 +49,7 @@ describe("reconstruction coverage persistence", () => {
).toMatchObject({
ok: false,
error: {
_tag: "InvestigationWorkspaceError",
_tag: "WorkspaceStorageError",
reason: "revision-conflict",
},
});
-1
View File
@@ -286,7 +286,6 @@ const projectStore = (
projectRoot: string,
grants: readonly ReturnType<typeof projectGrant>[],
): ProjectPermissionStore => ({
schema_version: 1,
project_id: `project_${createHash("sha256").update(projectRoot).digest("hex")}`,
project_root: projectRoot,
grants: [...grants],
+1 -6
View File
@@ -1,6 +1,4 @@
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
import { realpath } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import type { AnalysisOperationPort } from "../../../src/application/AnalysisProvider.js";
@@ -10,7 +8,6 @@ import { createServer } from "../../../src/server/createServer.js";
describe("MCP permission preflight", () => {
it("denies extraction before dispatch and returns exact typed remediation", async () => {
const outputRoot = join(await realpath("/tmp"), "rea-permission-denied");
let dispatches = 0;
const analysis: AnalysisOperationPort = {
execute: () => {
@@ -30,8 +27,6 @@ describe("MCP permission preflight", () => {
const result = await client.callTool({
name: "extract_artifact",
arguments: {
approved: true,
output_root: outputRoot,
occurrence_ids: [`occ_${"0".repeat(64)}`],
},
});
@@ -44,7 +39,7 @@ describe("MCP permission preflight", () => {
code: "permission_required",
details: {
capability: "artifact_extract",
missing: { roots: [outputRoot] },
missing: { roots: [expect.stringMatching(/rea-extracted-/u)] },
},
remediation: {
restart_required: true,
@@ -220,8 +220,6 @@ const capability = (provider: ProviderIdentity): CapabilityDescriptor => ({
operation: "address_name",
available: true,
reason: null,
pagination: "none",
exhaustive: true,
effects: {
mutatesArtifact: false,
launchesProcess: true,
@@ -231,7 +229,6 @@ const capability = (provider: ProviderIdentity): CapabilityDescriptor => ({
changesPermissions: false,
requiresRoot: false,
},
limits: { maxResults: null, maxPayloadBytes: 1_000, timeoutMs: 1_000 },
limitations: [],
});
@@ -33,8 +33,8 @@ describe("reconstruction coverage MCP parity", () => {
};
const authority = await permissionAuthorityForRoot(
root,
["investigation_workspace_read", "investigation_workspace_write"],
["investigation_workspace_read", "investigation_workspace_write"],
["reconstruction_coverage_read", "reconstruction_coverage_write"],
["reconstruction_coverage_read", "reconstruction_coverage_write"],
);
const session = createTestBinarySession(() => ({
execute: () => Promise.resolve(observed(null)),
@@ -7,7 +7,7 @@ import { createServer } from "../../../src/server/createServer.js";
import { observed } from "../../fixtures/analysisExecution.js";
describe("reconstruction obligation ledger MCP parity", () => {
it("returns an Evidence-backed page inline", async () => {
it("returns the complete Evidence-backed ledger inline", async () => {
const session = createTestBinarySession(() => ({
execute: () => Promise.resolve(observed(null)),
close: () => Promise.resolve(),
@@ -28,7 +28,6 @@ describe("reconstruction obligation ledger MCP parity", () => {
bindings: [],
contradictions: [],
},
page: { offset: 0, limit: 50 },
},
});
expect(result.isError).not.toBe(true);
+2 -17
View File
@@ -27,8 +27,6 @@ const availabilityProvider = (): AnalysisProvider => {
operation: "current_address",
available: true,
reason: null,
pagination: "none",
exhaustive: true,
effects: {
mutatesArtifact: false,
launchesProcess: false,
@@ -38,11 +36,6 @@ const availabilityProvider = (): AnalysisProvider => {
changesPermissions: false,
requiresRoot: false,
},
limits: {
maxResults: null,
maxPayloadBytes: null,
timeoutMs: null,
},
limitations: [],
};
return {
@@ -69,8 +62,6 @@ const statusCapability = (
operation,
input_contract_version: 1,
output_contract_version: 1,
pagination: "none" as const,
exhaustive: true,
effects: {
mutates_artifact: false,
launches_process: false,
@@ -80,11 +71,6 @@ const statusCapability = (
changes_permissions: false,
requires_root: false,
},
limits: {
max_results: null,
max_payload_bytes: null,
timeout_ms: null,
},
limitations: [],
...(availability.available
? { available: true as const, reason: null, availability_code: null }
@@ -109,10 +95,9 @@ describe("server and catalog identity", () => {
expect(SDK_IDENTITY.server).toBe(
packageJson.dependencies["@modelcontextprotocol/server"],
);
expect(CLI_COMMAND_NAMES).toHaveLength(68);
expect(new Set(CLI_COMMAND_NAMES).size).toBe(68);
expect(new Set(CLI_COMMAND_NAMES).size).toBe(CLI_COMMAND_NAMES.length);
expect(CATALOG_IDENTITY.counts).toEqual({
cli_commands: 68,
cli_commands: CLI_COMMAND_NAMES.length,
mcp_tools: TOOL_CONTRACTS.length,
mcp_prompts: 6,
});
-7
View File
@@ -300,8 +300,6 @@ const provider = (closed: string[]): AnalysisProvider => {
operation: "current_document",
available: true,
reason: null,
pagination: "none",
exhaustive: true,
effects: {
mutatesArtifact: false,
launchesProcess: false,
@@ -311,11 +309,6 @@ const provider = (closed: string[]): AnalysisProvider => {
changesPermissions: false,
requiresRoot: false,
},
limits: {
maxResults: null,
maxPayloadBytes: null,
timeoutMs: null,
},
limitations: [],
};
return {
-1
View File
@@ -51,7 +51,6 @@ describe("tool result projection", () => {
const result = toCallToolResult(
err(
new HopperProcessError(80, {
schema_version: 1,
component: "hopper_private_display",
operation: "launch",
status: "error",
@@ -36,7 +36,7 @@ describe("Ghidra local transport", () => {
const path = join(root, "bridge-endpoint.json");
await writeFile(
path,
`${JSON.stringify({ schema_version: 1, host: "127.0.0.1", port: 49152 })}\n`,
`${JSON.stringify({ host: "127.0.0.1", port: 49152 })}\n`,
);
await expect(
@@ -51,9 +51,9 @@ describe("Ghidra local transport", () => {
});
it.each([
{ schema_version: 1, host: "0.0.0.0", port: 49152 },
{ schema_version: 1, host: "127.0.0.1", port: 0 },
{ schema_version: 1, host: "127.0.0.1", port: 49152, token: "leak" },
{ host: "0.0.0.0", port: 49152 },
{ host: "127.0.0.1", port: 0 },
{ host: "127.0.0.1", port: 49152, token: "leak" },
])(
"rejects an invalid or expanded TCP endpoint: $host:$port",
async (value) => {
@@ -101,7 +101,6 @@ class ExitingLauncher implements BridgeLauncher {
class DiagnosticExitingLauncher implements BridgeLauncher {
launch() {
const diagnostic: HopperStartupDiagnostic = {
schema_version: 1,
component: "hopper_private_display",
operation: "launch",
status: "error",
@@ -39,7 +39,6 @@ type DiagnosticOverrides = Partial<
const diagnostic = (overrides: DiagnosticOverrides = {}) => {
const common = {
schema_version: 1,
component: "hopper_private_display",
operation: "probe",
reason: "ready",
@@ -52,7 +52,9 @@ describe("managed static provider path boundary", () => {
);
expect(boundaries.ok).toBe(true);
if (!boundaries.ok) return;
expect(asManagedNativeBoundaryResult(boundaries.value)).toMatchObject({
const boundaryResult = asManagedNativeBoundaryResult(boundaries.value);
expect(boundaryResult).not.toHaveProperty("schema_version");
expect(boundaryResult).toMatchObject({
artifact: { path, sha256: parsed.value.sha256, format: "pe" },
module_refs: [],
pinvoke_imports: [],
@@ -508,7 +508,6 @@ describe("controlled JavaScript replay cancellation and export", () => {
const metadata = await stat(path);
expect(metadata.mode & 0o777).toBe(0o600);
expect(JSON.parse(await readFile(path, "utf8"))).toMatchObject({
schema_version: 1,
sources: null,
});
} finally {
@@ -5,11 +5,9 @@ import {
createCacheProvider,
createTestBinarySession,
} from "../../fixtures/binarySession.js";
import { createEvidenceBundle } from "../../../src/domain/evidenceBundle.js";
import { createInvestigationWorkspace } from "../../../src/domain/investigationWorkspace.js";
describe("binary session", () => {
it("returns detached provider, target, and workspace metadata", async () => {
it("returns detached provider and target metadata", async () => {
const [first] = await createBinarySessionTargets();
const session = createTestBinarySession(createCacheProvider([]));
expect((await session.open(first)).ok).toBe(true);
@@ -29,19 +27,6 @@ describe("binary session", () => {
if (active !== undefined) Reflect.set(active, "path", "/tmp/forged");
expect(session.activeTarget()?.path).toBe(first);
const workspace = createInvestigationWorkspace(
"Detached workspace",
createEvidenceBundle([]),
[],
);
expect(session.retainInvestigationWorkspace(workspace)).toBe("added");
const direct = session.investigationWorkspace(workspace.workspace_id, 1);
if (direct !== undefined) Reflect.set(direct, "revision", 999);
const listed = session.investigationWorkspaces()[0];
if (listed !== undefined) Reflect.set(listed, "workspace_id", "forged");
expect(
session.investigationWorkspace(workspace.workspace_id, 1),
).toMatchObject({ revision: 1, workspace_id: workspace.workspace_id });
await session.close();
});
});
@@ -16,8 +16,6 @@ const nonHopperProvider = (operations: string[]): AnalysisProvider => {
operation: "address_name",
available: true,
reason: null,
pagination: "none",
exhaustive: true,
effects: {
mutatesArtifact: false,
launchesProcess: false,
@@ -27,11 +25,6 @@ const nonHopperProvider = (operations: string[]): AnalysisProvider => {
changesPermissions: false,
requiresRoot: false,
},
limits: {
maxResults: null,
maxPayloadBytes: null,
timeoutMs: null,
},
limitations: [],
},
],
@@ -30,8 +30,6 @@ describe("binary session", () => {
operation: "address_name",
available: false,
reason: "fixture intentionally omits symbol lookup",
pagination: "none",
exhaustive: false,
effects: {
mutatesArtifact: false,
launchesProcess: false,
@@ -41,11 +39,6 @@ describe("binary session", () => {
changesPermissions: false,
requiresRoot: false,
},
limits: {
maxResults: null,
maxPayloadBytes: null,
timeoutMs: null,
},
limitations: ["No symbol lookup implementation."],
},
],
@@ -202,8 +202,6 @@ const capability = (
operation,
available: true,
reason: null,
pagination: "none",
exhaustive: true,
effects: {
mutatesArtifact: false,
launchesProcess: true,
@@ -213,6 +211,5 @@ const capability = (
changesPermissions: false,
requiresRoot: false,
},
limits: { maxResults: null, maxPayloadBytes: 1_000_000, timeoutMs: 5_000 },
limitations: [],
});
@@ -296,8 +296,6 @@ const capability = (
operation,
available: true,
reason: null,
pagination: "none",
exhaustive: true,
effects: {
mutatesArtifact: false,
launchesProcess: operation === "address_name",
@@ -307,7 +305,6 @@ const capability = (
changesPermissions: false,
requiresRoot: false,
},
limits: { maxResults: null, maxPayloadBytes: 1_000, timeoutMs: 1_000 },
limitations: [],
});
@@ -6,7 +6,7 @@ import {
ArtifactOperationError,
EvidenceFileError,
HopperRemoteError,
InvestigationWorkspaceError,
WorkspaceStorageError,
UnknownRegistryError,
projectAnalysisError,
type AnalysisError,
@@ -53,7 +53,7 @@ describe("analysis error projection contract", () => {
"name-conflict",
"io",
] as const
).map((reason) => new InvestigationWorkspaceError("update", reason)),
).map((reason) => new WorkspaceStorageError("update", reason)),
...(
[
"not-found",
@@ -1,14 +1,12 @@
import { describe, expect, it } from "vitest";
import {
CONFORMANCE_PACKAGE_VERSION,
createConformancePackage,
parseConformancePackage,
type ConformancePackageInput,
} from "../../../src/domain/conformancePackage.js";
const validPackageInput: ConformancePackageInput = {
schema_version: CONFORMANCE_PACKAGE_VERSION,
name: "test-fixture",
description: "A test conformance fixture",
created_at: "2026-07-28T00:00:00Z",
@@ -72,7 +70,7 @@ describe("conformance package parsing", () => {
it("rejects invalid package structure", () => {
expect(
parseConformancePackage({ ...validPackage, schema_version: 999 }),
parseConformancePackage({ ...validPackage, name: "" }),
).toMatchObject({ ok: false, error: { kind: "invalid_package" } });
});
@@ -1,7 +1,6 @@
import { describe, expect, it } from "vitest";
import {
CONFORMANCE_PACKAGE_VERSION,
createConformancePackage,
type ConformancePackageInput,
} from "../../../src/domain/conformancePackage.js";
@@ -13,7 +12,6 @@ import {
} from "../../../src/domain/conformanceReplay.js";
const validPackageInput: ConformancePackageInput = {
schema_version: CONFORMANCE_PACKAGE_VERSION,
name: "test-fixture",
description: "A test conformance fixture",
created_at: "2026-07-28T00:00:00Z",
-7
View File
@@ -138,8 +138,6 @@ const cacheCapability = (
operation,
available: true,
reason: null,
pagination: "none",
exhaustive: true,
effects: {
mutatesArtifact,
launchesProcess: false,
@@ -149,10 +147,5 @@ const cacheCapability = (
changesPermissions: false,
requiresRoot: false,
},
limits: {
maxResults: null,
maxPayloadBytes: null,
timeoutMs: null,
},
limitations: [],
});
-1
View File
@@ -54,7 +54,6 @@ else {
await writeFile(
pending,
`${JSON.stringify({
schema_version: 1,
host: "127.0.0.1",
port: address.port,
})}\n`,
-2
View File
@@ -19,7 +19,6 @@ describe.sequential("verifier run identity", () => {
const nested = createVerifierRun();
expect(first).toEqual({
schema_version: 1,
run_id: expect.stringMatching(
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u,
),
@@ -60,7 +59,6 @@ describe.sequential("verifier run identity", () => {
const completed = await completeVerifierRun(run);
expect(completed.process_lineage).toMatchObject({
status: "verified",
schema_version: 1,
observed_at: expect.stringMatching(/Z$/u),
launcher_pid: process.pid,
launcher_parent_pid: process.ppid,