feat(evidence): discover retained records without full payloads (#1682)
* feat(evidence): discover retained records without full payloads * fix(evidence): guide oversized results to retained discovery * style(tests): format retained discovery recovery assertion
This commit is contained in:
@@ -9,6 +9,53 @@ import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
import { analysisViewLayoutEvidence } from "../../fixtures/analysisView.js";
|
||||
import { createEvidence } from "../../../src/domain/evidence.js";
|
||||
import { ghidraFunctionDossier } from "../../../src/domain/ghidraValues.fixture.js";
|
||||
import { createEvidenceBundle } from "../../../src/domain/evidenceBundle.js";
|
||||
import { inspectEvidenceBundle } from "../../../src/application/investigation/InspectEvidenceBundle.js";
|
||||
|
||||
cliTest(
|
||||
"discovers native records from a complete portable bundle using the shared workflow",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-evidence-discovery-cli-");
|
||||
const parent = createEvidence(
|
||||
{ path: "/fixtures/native.exe", format: "pe", sha256: "a".repeat(64) },
|
||||
{ id: "ghidra", name: "Ghidra", version: "12.1.4" },
|
||||
{
|
||||
operation: "analyze_function",
|
||||
parameters: {},
|
||||
result: ghidraFunctionDossier(),
|
||||
},
|
||||
);
|
||||
const bundle = createEvidenceBundle([parent]);
|
||||
const path = join(root, "evidence.json");
|
||||
await writeFile(path, JSON.stringify(bundle));
|
||||
const options = {
|
||||
detail: "summary" as const,
|
||||
filters: { evidence_id: parent.evidence_id },
|
||||
};
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"inspect-evidence-bundle",
|
||||
JSON.stringify({ path, ...options }),
|
||||
"--json",
|
||||
],
|
||||
environment: { HOME: root, XDG_CONFIG_HOME: root, XDG_CACHE_HOME: root },
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
const expected = inspectEvidenceBundle(bundle, options);
|
||||
if (!expected.ok) throw expected.error;
|
||||
expect(result.json).toEqual(expected.value);
|
||||
const complete = await cli.run({
|
||||
arguments: [
|
||||
"inspect-evidence-bundle",
|
||||
JSON.stringify({ path }),
|
||||
"--json",
|
||||
],
|
||||
environment: { HOME: root, XDG_CONFIG_HOME: root, XDG_CACHE_HOME: root },
|
||||
});
|
||||
expect(complete.exitCode).toBe(0);
|
||||
expect(complete.json).toEqual(bundle);
|
||||
},
|
||||
);
|
||||
cliTest(
|
||||
"projects one section from a JSON file of inline layout Evidence",
|
||||
async ({ cli }) => {
|
||||
|
||||
@@ -7,6 +7,8 @@ import { z } from "zod";
|
||||
import { BinaryLayoutService } from "../../../src/application/binaryDiagnostics/BinaryLayoutService.js";
|
||||
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { createAnalysisProfile } from "../../../src/domain/analysisProfile.js";
|
||||
import { jsonObjectSchema } from "../../../src/domain/jsonValue.js";
|
||||
import { functionDossierSchema } from "../../../src/domain/hopperValues.js";
|
||||
import { ghidraFunctionDossier } from "../../../src/domain/ghidraValues.fixture.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
@@ -46,6 +48,115 @@ const connect = async (binaryLayout?: BinaryLayoutService) => {
|
||||
return { client, session };
|
||||
};
|
||||
|
||||
it("discovers an oversized native dossier by exact metadata and reads its retained view", async () => {
|
||||
const { client, session } = await connect();
|
||||
const provider = { id: "ghidra", name: "Ghidra", version: "12.1.4" };
|
||||
const profile = createAnalysisProfile(provider, { language: "fixture" });
|
||||
const parent = createEvidence(
|
||||
{ path: "/fixtures/large.exe", format: "pe", sha256: "a".repeat(64) },
|
||||
provider,
|
||||
{
|
||||
operation: "analyze_function",
|
||||
parameters: { procedure: "0x401000" },
|
||||
analysisProfile: profile,
|
||||
result: {
|
||||
...jsonObjectSchema.parse(ghidraFunctionDossier()),
|
||||
pseudocode: "x".repeat(6 * 1024 * 1024),
|
||||
},
|
||||
rawResult: null,
|
||||
},
|
||||
);
|
||||
const other = createEvidence(
|
||||
{ path: "/fixtures/other.exe", format: "pe", sha256: "b".repeat(64) },
|
||||
provider,
|
||||
{
|
||||
operation: "analyze_function",
|
||||
parameters: {},
|
||||
result: ghidraFunctionDossier(),
|
||||
},
|
||||
);
|
||||
for (const record of [parent, other]) {
|
||||
const retained = session.recordEvidence(record);
|
||||
if (!retained.ok) throw retained.error;
|
||||
}
|
||||
const broad = await client.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: {},
|
||||
});
|
||||
const broadError = parseMcpToolError(broad).error;
|
||||
expect(broadError.code).toBe("resource_constraint");
|
||||
expect(broadError.remediation?.action).toContain(
|
||||
"get_evidence_bundle and detail: summary",
|
||||
);
|
||||
const response = await client.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: {
|
||||
detail: "summary",
|
||||
filters: {
|
||||
operation: "analyze_function",
|
||||
target_sha256: "a".repeat(64),
|
||||
analysis_profile_digest: profile.digest,
|
||||
procedure_address: "0x401000",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(response.isError).not.toBe(true);
|
||||
const result = toolContract("get_evidence_bundle").outputSchema.parse(
|
||||
response.structuredContent,
|
||||
).result;
|
||||
expect(result).toMatchObject({
|
||||
kind: "evidence-bundle-summary",
|
||||
total_retained_records: 2,
|
||||
matching_records: 1,
|
||||
records: [
|
||||
{
|
||||
evidence_id: parent.evidence_id,
|
||||
analysis_profile_digest: profile.digest,
|
||||
retention: "complete-record",
|
||||
native_dossier: { available: true, procedure_address: "0x401000" },
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(JSON.stringify(response)).not.toContain("pseudocode");
|
||||
expect(
|
||||
JSON.parse(response.content.find((c) => c.type === "text")?.text ?? "null"),
|
||||
).toEqual(response.structuredContent);
|
||||
const page = await client.callTool({
|
||||
name: "inspect_analysis_view",
|
||||
arguments: {
|
||||
source: { kind: "retained-evidence", evidence_id: parent.evidence_id },
|
||||
view: { kind: "native", facet: "pseudocode", offset: 0, limit: 32 },
|
||||
},
|
||||
});
|
||||
expect(page.isError).not.toBe(true);
|
||||
expect(
|
||||
toolContract("inspect_analysis_view").outputSchema.parse(
|
||||
page.structuredContent,
|
||||
).normalized_result,
|
||||
).toMatchObject({
|
||||
item: { text: "x".repeat(32) },
|
||||
coverage: { total: 6 * 1024 * 1024, exhausted: false },
|
||||
});
|
||||
const empty = await client.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: {
|
||||
detail: "summary",
|
||||
filters: { evidence_id: `ev_${"e".repeat(64)}` },
|
||||
},
|
||||
});
|
||||
expect(
|
||||
toolContract("get_evidence_bundle").outputSchema.parse(
|
||||
empty.structuredContent,
|
||||
).result,
|
||||
).toMatchObject({ matching_records: 0, records: [] });
|
||||
await client.ping();
|
||||
const invalid = await client.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: { filters: { operation: "analyze_function" } },
|
||||
});
|
||||
expect(parseMcpToolError(invalid).error.code).toBe("invalid_request");
|
||||
});
|
||||
|
||||
it("advertises exact schemas and projects one layout section from retained Evidence", async () => {
|
||||
const layout = analysisViewLayoutFixture();
|
||||
const service = new BinaryLayoutService({
|
||||
|
||||
Reference in New Issue
Block a user