mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 14:35:45 +00:00
test(ghidra): consolidate inventory Evidence and byte coverage (#12922)
This commit is contained in:
1 parent
d1242fa30b
commit
9c3ab4a0df
3 files changed
+73
-68
No files matched your search
@@ -10,30 +10,26 @@ const patternSchema = z
|
||||
.strictObject(bytePatternFields)
|
||||
.superRefine(validateBytePattern);
|
||||
|
||||
it.each(["0x20", "overlay:0x10", "invalid"])(
|
||||
"rejects a match outside reported searched coverage: %s",
|
||||
(address) => {
|
||||
const page = {
|
||||
matches: [
|
||||
{ address, segment: ".text", file_offset: null, procedure: null },
|
||||
],
|
||||
searched: {
|
||||
blocks: [{ segment: ".text", start: "0x10", end: "0x1f", bytes: 16 }],
|
||||
bytes: 16,
|
||||
skipped_uninitialized: [],
|
||||
skipped_not_loaded: [],
|
||||
skipped_overlays: [],
|
||||
},
|
||||
complete: true,
|
||||
next_cursor: null,
|
||||
};
|
||||
expect(byteSearchResultSchema.safeParse(page).success).toBe(false);
|
||||
page.matches[0]!.address = "0x10";
|
||||
expect(byteSearchResultSchema.safeParse(page).success).toBe(true);
|
||||
page.matches[0]!.segment = ".bss";
|
||||
expect(byteSearchResultSchema.safeParse(page).success).toBe(false);
|
||||
},
|
||||
);
|
||||
it.each([
|
||||
["outside the range", "0x20", ".text"],
|
||||
["in another address space", "overlay:0x10", ".text"],
|
||||
["without a coordinate", "invalid", ".text"],
|
||||
["in another segment", "0x10", ".bss"],
|
||||
])("rejects a match %s", (_label, address, segment) => {
|
||||
const page = {
|
||||
matches: [{ address, segment, file_offset: null, procedure: null }],
|
||||
searched: {
|
||||
blocks: [{ segment: ".text", start: "0x10", end: "0x1f", bytes: 16 }],
|
||||
bytes: 16,
|
||||
skipped_uninitialized: [],
|
||||
skipped_not_loaded: [],
|
||||
skipped_overlays: [],
|
||||
},
|
||||
complete: true,
|
||||
next_cursor: null,
|
||||
};
|
||||
expect(byteSearchResultSchema.safeParse(page).success).toBe(false);
|
||||
});
|
||||
|
||||
it.each(["", "overlay:"])(
|
||||
"accepts matches at both inclusive coverage boundaries in address space %s",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { nativeLoadImageObservationFixture } from "../../tests/fixtures/nativeLoadImage.js";
|
||||
import {
|
||||
@@ -205,41 +204,6 @@ describe("provider-owned overview boundary", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the independent segment permissions and provenance behind an overview", () => {
|
||||
const reported = {
|
||||
...overview,
|
||||
segments: [
|
||||
{
|
||||
name: ".text",
|
||||
start: "0x1000",
|
||||
end: "0x100f",
|
||||
readable: true,
|
||||
writable: false,
|
||||
executable: true,
|
||||
permissions: { available: true, source: "ghidra-memory-block" },
|
||||
provenance: "ghidra-memory-block",
|
||||
address_space: "ram",
|
||||
image_base: "0x1000",
|
||||
initialized: true,
|
||||
overlay: false,
|
||||
sections: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
const parsed = parseGhidraInventoryResult(
|
||||
"read_binary_inventory_summary",
|
||||
reported,
|
||||
null,
|
||||
);
|
||||
if (!parsed.ok) throw parsed.error;
|
||||
expect(parsed.value.rawResult).toEqual(reported);
|
||||
expect(parsed.value.value).toMatchObject({
|
||||
procedure_count: 0,
|
||||
string_count: 0,
|
||||
segments: [{ name: ".text", start: "0x1000", end: "0x100f" }],
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ procedure_count: -1 },
|
||||
{ string_count: 1.5 },
|
||||
@@ -458,13 +422,17 @@ it.each([
|
||||
throw new Error("Expected an address fixture");
|
||||
Reflect.set(object as object, field, address.replace("%3A", "%3a"));
|
||||
const result = parseGhidraInventoryResult("search_bytes", value, null);
|
||||
if (result.ok) throw new Error("Expected canonical-address refusal");
|
||||
expect(result.error.cause).toBeInstanceOf(z.ZodError);
|
||||
if (!(result.error.cause instanceof z.ZodError))
|
||||
throw new Error("Expected field schema issues");
|
||||
expect(result.error.cause.issues).toContainEqual(
|
||||
expect.objectContaining({ path: [...path] }),
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "AnalysisOutputError",
|
||||
diagnostics: {
|
||||
contract_issues: expect.arrayContaining([
|
||||
expect.objectContaining({ path: [...path] }),
|
||||
]),
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -4,7 +4,11 @@ import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
import { EnhancedTools } from "../../../src/application/EnhancedTools.js";
|
||||
import { SUPPORTED_GHIDRA_VERSION } from "../../../src/ghidra/GhidraReleasePolicy.js";
|
||||
import { connectGhidraMcp, sessionEvidence } from "./ghidraMcpHarness.js";
|
||||
import {
|
||||
connectGhidraMcp,
|
||||
ghidraFixtureResult,
|
||||
sessionEvidence,
|
||||
} from "./ghidraMcpHarness.js";
|
||||
import { ghidraProducerIdentity } from "../../../src/ghidra/GhidraProducerIdentity.js";
|
||||
import { functionDossierSchema } from "../../../src/domain/native/functionDossier.js";
|
||||
import { functionComparisonResultSchema } from "../../../src/domain/functionComparisonSchemas.js";
|
||||
@@ -591,6 +595,41 @@ it("rejects Ghidra naming replies whose outcomes and reasons disagree", async ()
|
||||
}
|
||||
});
|
||||
|
||||
const expectOverviewSourceEvidence = (
|
||||
session: Parameters<typeof sessionEvidence>[0],
|
||||
links: readonly string[],
|
||||
) => {
|
||||
expect(links).toHaveLength(1);
|
||||
const [overviewSourceId] = links;
|
||||
if (overviewSourceId === undefined)
|
||||
throw new Error("Expected the provider Evidence link");
|
||||
const overviewSource = session.evidenceById(overviewSourceId);
|
||||
expect(overviewSource).toMatchObject({
|
||||
operation: "read_binary_inventory_summary",
|
||||
provider: { id: "ghidra" },
|
||||
});
|
||||
expect(overviewSource?.raw_result).toEqual(
|
||||
ghidraFixtureResult("read_binary_inventory_summary", {}),
|
||||
);
|
||||
expect(overviewSource?.normalized_result).toEqual({
|
||||
document: "fixture",
|
||||
image_base: "0x400000",
|
||||
segment_count: 1,
|
||||
procedure_count: 1,
|
||||
string_count: 2,
|
||||
segments: [
|
||||
{
|
||||
name: ".text",
|
||||
start: "0x401000",
|
||||
end: "0x401100",
|
||||
length: 256,
|
||||
image_base: "0x400000",
|
||||
address_space: "ram",
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
describe("Ghidra MCP evidence parity", () => {
|
||||
it("preserves provider evidence, composed parity, and capability routing", async () => {
|
||||
const harness = await connectGhidraMcp("ghidra-parity");
|
||||
@@ -664,6 +703,8 @@ describe("Ghidra MCP evidence parity", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expectOverviewSourceEvidence(session, mcpOverview.evidence_links);
|
||||
|
||||
const pseudocode = sessionEvidence(
|
||||
session,
|
||||
(
|
||||
|
||||
Reference in new issue
Block a user