feat(native): inspect oversized retained function dossiers via bounded views
Add caller-selected native dossier facets with preserved Evidence identity, provenance, unknowns and transport recovery. Refs #1247 and #1065. Co-authored-by: jhuang-tw <77732008+jhuang-tw@users.noreply.github.com> Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,8 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
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";
|
||||
cliTest(
|
||||
"projects one section from a JSON file of inline layout Evidence",
|
||||
async ({ cli }) => {
|
||||
@@ -43,6 +45,48 @@ cliTest(
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"projects native function pseudocode without requiring Ghidra",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-native-view-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: { address: "0x401000" },
|
||||
result: ghidraFunctionDossier(),
|
||||
},
|
||||
);
|
||||
const input = join(root, "native-view.json");
|
||||
await writeFile(
|
||||
input,
|
||||
JSON.stringify({
|
||||
source: { kind: "inline", evidence: parent },
|
||||
view: { kind: "native", facet: "pseudocode", offset: 0, limit: 12 },
|
||||
}),
|
||||
);
|
||||
const result = await cli.run({
|
||||
arguments: ["inspect-analysis-view", input, "--json"],
|
||||
environment: { HOME: root, XDG_CONFIG_HOME: root, XDG_CACHE_HOME: root },
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.json).toMatchObject({
|
||||
operation: "inspect_analysis_view",
|
||||
normalized_result: {
|
||||
kind: "native",
|
||||
parent_evidence_id: parent.evidence_id,
|
||||
procedure_address: "0x401000",
|
||||
item: { text: "int fixture_", unit: "utf16-code-units" },
|
||||
},
|
||||
locations: [
|
||||
{ kind: "artifact-path", path: "/fixtures/native.exe" },
|
||||
{ kind: "address", address: "0x401000" },
|
||||
],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest("rejects malformed JSON before projection", async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-analysis-view-cli-bad-");
|
||||
const result = await cli.run({
|
||||
|
||||
@@ -6,7 +6,9 @@ import { z } from "zod";
|
||||
|
||||
import { BinaryLayoutService } from "../../../src/application/binaryDiagnostics/BinaryLayoutService.js";
|
||||
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { functionDossierSchema } from "../../../src/domain/hopperValues.js";
|
||||
import { ghidraFunctionDossier } from "../../../src/domain/ghidraValues.fixture.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
import {
|
||||
createJavaScriptApplicationGraph,
|
||||
@@ -109,6 +111,68 @@ it("advertises exact schemas and projects one layout section from retained Evide
|
||||
);
|
||||
});
|
||||
|
||||
it("delivers a bounded native dossier view over MCP without a Ghidra provider or lost connection", async () => {
|
||||
const { client, session } = await connect();
|
||||
const original = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
const parent = createEvidence(
|
||||
{
|
||||
path: "/fixtures/oversized-native.exe",
|
||||
format: "pe",
|
||||
sha256: "b".repeat(64),
|
||||
},
|
||||
{ id: "ghidra", name: "Ghidra", version: "12.1.4" },
|
||||
{
|
||||
operation: "analyze_function",
|
||||
parameters: { address: "0x401000" },
|
||||
result: { ...original, pseudocode: "X".repeat(11 * 1024 * 1024) },
|
||||
},
|
||||
);
|
||||
expect(session.recordEvidence(parent).ok).toBe(true);
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
(tool) => tool.name === "inspect_analysis_view",
|
||||
);
|
||||
if (advertised?.outputSchema === undefined)
|
||||
throw new Error("missing view schemas");
|
||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||
const inputSchema: Record<string, unknown> = advertised.inputSchema;
|
||||
const outputSchema: Record<string, unknown> = advertised.outputSchema;
|
||||
const arguments_ = {
|
||||
source: { kind: "retained-evidence", evidence_id: parent.evidence_id },
|
||||
view: { kind: "native", facet: "pseudocode", offset: 0, limit: 500 },
|
||||
};
|
||||
expect(ajv.validateSchema(inputSchema)).toBe(true);
|
||||
expect(ajv.validateSchema(outputSchema)).toBe(true);
|
||||
expect(
|
||||
ajv.validate(inputSchema, arguments_),
|
||||
JSON.stringify(ajv.errors),
|
||||
).toBe(true);
|
||||
const response = await client.callTool({
|
||||
name: "inspect_analysis_view",
|
||||
arguments: arguments_,
|
||||
});
|
||||
expect(response.isError).not.toBe(true);
|
||||
expect(
|
||||
ajv.validate(outputSchema, response.structuredContent),
|
||||
JSON.stringify(ajv.errors),
|
||||
).toBe(true);
|
||||
const parsed = toolContract("inspect_analysis_view").outputSchema.parse(
|
||||
response.structuredContent,
|
||||
);
|
||||
expect(parsed.normalized_result).toMatchObject({
|
||||
kind: "native",
|
||||
parent_evidence_id: parent.evidence_id,
|
||||
procedure_address: "0x401000",
|
||||
coverage: { examined: 500, next_offset: 500, total: 11 * 1024 * 1024 },
|
||||
});
|
||||
expect(parsed.evidence_links).toEqual([parent.evidence_id]);
|
||||
expect(parsed.locations).toEqual([
|
||||
{ kind: "artifact-path", path: "/fixtures/oversized-native.exe" },
|
||||
{ kind: "address", address: "0x401000" },
|
||||
]);
|
||||
expect(JSON.stringify(response.structuredContent).length).toBeLessThan(12000);
|
||||
await client.ping();
|
||||
});
|
||||
|
||||
it("retains an oversized selected observation and keeps subsequent views usable", async () => {
|
||||
const { client, session } = await connect();
|
||||
const analysis = analysisViewJavaScriptAnalysisWithSource();
|
||||
@@ -185,6 +249,71 @@ it("retains an oversized selected observation and keeps subsequent views usable"
|
||||
expect(summary.isError).not.toBe(true);
|
||||
});
|
||||
|
||||
it("retains an oversized native assembly row and permits a subsequent smaller view", async () => {
|
||||
const { client, session } = await connect();
|
||||
const row = "\0".repeat(1_000_000);
|
||||
const parent = createEvidence(
|
||||
{ path: "/fixtures/large-row.exe", format: "pe", sha256: "c".repeat(64) },
|
||||
{ id: "ghidra", name: "Ghidra", version: "12.1.4" },
|
||||
{
|
||||
operation: "analyze_function",
|
||||
parameters: {},
|
||||
result: {
|
||||
...functionDossierSchema.parse(ghidraFunctionDossier()),
|
||||
assembly: [row],
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(session.recordEvidence(parent).ok).toBe(true);
|
||||
const source = { kind: "retained-evidence", evidence_id: parent.evidence_id };
|
||||
const response = await client.callTool({
|
||||
name: "inspect_analysis_view",
|
||||
arguments: {
|
||||
source,
|
||||
view: { kind: "native", facet: "assembly", offset: 0, limit: 1 },
|
||||
},
|
||||
});
|
||||
expect(response.isError).toBe(true);
|
||||
const error = z
|
||||
.object({
|
||||
error: z.object({
|
||||
details: z.object({
|
||||
reported_limits: z.object({
|
||||
evidence_reference: z.object({
|
||||
kind: z.literal("retained-evidence"),
|
||||
evidence_id: z.string(),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.parse(parseMcpToolError(response));
|
||||
const retained = session.evidenceById(
|
||||
error.error.details.reported_limits.evidence_reference.evidence_id,
|
||||
);
|
||||
expect(retained?.normalized_result).toMatchObject({
|
||||
item: [row],
|
||||
parent_evidence_id: parent.evidence_id,
|
||||
});
|
||||
const next = await client.callTool({
|
||||
name: "inspect_analysis_view",
|
||||
arguments: {
|
||||
source,
|
||||
view: { kind: "native", facet: "pseudocode", offset: 0, limit: 12 },
|
||||
},
|
||||
});
|
||||
expect(next.isError).not.toBe(true);
|
||||
expect(
|
||||
toolContract("inspect_analysis_view").outputSchema.parse(
|
||||
next.structuredContent,
|
||||
).normalized_result,
|
||||
).toMatchObject({
|
||||
item: { text: "int fixture_" },
|
||||
parent_evidence_id: parent.evidence_id,
|
||||
});
|
||||
await client.ping();
|
||||
});
|
||||
|
||||
it("returns a JavaScript summary without graph payloads from a retained reference", async () => {
|
||||
const { client, session } = await connect();
|
||||
const parent = analysisViewJavaScriptEvidence();
|
||||
|
||||
Reference in New Issue
Block a user