mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 14:35:45 +00:00
test(ghidra): consolidate literal search boundary coverage (#12925)
* test(ghidra): consolidate literal search boundary coverage * test(ghidra): prove primary-name Unicode folding independently
This commit is contained in:
1 parent
41e9997289
commit
5f9e931365
3 files changed
+114
-96
No files matched your search
@@ -7055,63 +7055,57 @@ it("keeps saved project reports as shared historical Evidence without applying f
|
||||
).toEqual([history.evidence_id]);
|
||||
});
|
||||
|
||||
it.each(["search_procedures", "search_strings"] as const)(
|
||||
"%s applies shared folding after validation and preserves native source rows",
|
||||
async (operation) => {
|
||||
const rows = [
|
||||
{ address: "0x1000", value: "ſource" },
|
||||
{ address: "0x1001", value: "SOURCE" },
|
||||
{ address: "0x1002", value: "İource" },
|
||||
{ address: "0x1003", value: "unrelated" },
|
||||
].map((row) => ({
|
||||
...row,
|
||||
...(operation === "search_procedures"
|
||||
? { procedure: { external: false, thunk: false, thunk_target: null } }
|
||||
: {
|
||||
string: {
|
||||
encoding: "UTF-8",
|
||||
termination: "present_or_not_required",
|
||||
byte_length: Buffer.byteLength(row.value, "utf8") + 1,
|
||||
},
|
||||
}),
|
||||
}));
|
||||
const ghidra = provider(installationHost(), () => ({
|
||||
start: () => Promise.resolve(ok(sessionInfo())),
|
||||
callTool: () => Promise.resolve(ok(jsonValueSchema.parse(rows))),
|
||||
close: () => Promise.resolve(ok(null)),
|
||||
}));
|
||||
const client = await createElfClient(ghidra);
|
||||
try {
|
||||
const result = await client.execute(operation, { pattern: "source" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.result).toEqual(rows.slice(0, 2));
|
||||
expect(result.value.rawResult).toEqual(rows);
|
||||
expect(result.value.limitations).toContain(
|
||||
GHIDRA_LITERAL_CANDIDATES_LIMITATION,
|
||||
);
|
||||
const regex = await client.execute(operation, {
|
||||
pattern: "source",
|
||||
mode: "regex",
|
||||
});
|
||||
if (!regex.ok) throw regex.error;
|
||||
expect(regex.value.result).toEqual(rows);
|
||||
expect(regex.value.limitations).not.toContain(
|
||||
GHIDRA_LITERAL_CANDIDATES_LIMITATION,
|
||||
);
|
||||
const sensitive = await client.execute(operation, {
|
||||
pattern: "source",
|
||||
case_sensitive: true,
|
||||
});
|
||||
if (!sensitive.ok) throw sensitive.error;
|
||||
expect(sensitive.value.result).toEqual(rows);
|
||||
expect(sensitive.value.limitations).not.toContain(
|
||||
GHIDRA_LITERAL_CANDIDATES_LIMITATION,
|
||||
);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
it("filters string candidates and preserves their raw Evidence", async () => {
|
||||
const operation = "search_strings";
|
||||
const rows = [
|
||||
{ address: "0x1000", value: "ſource" },
|
||||
{ address: "0x1001", value: "SOURCE" },
|
||||
{ address: "0x1002", value: "İource" },
|
||||
{ address: "0x1003", value: "unrelated" },
|
||||
].map((row) => ({
|
||||
...row,
|
||||
string: {
|
||||
encoding: "UTF-8",
|
||||
termination: "present_or_not_required",
|
||||
byte_length: Buffer.byteLength(row.value, "utf8") + 1,
|
||||
},
|
||||
}));
|
||||
const ghidra = provider(installationHost(), () => ({
|
||||
start: () => Promise.resolve(ok(sessionInfo())),
|
||||
callTool: () => Promise.resolve(ok(jsonValueSchema.parse(rows))),
|
||||
close: () => Promise.resolve(ok(null)),
|
||||
}));
|
||||
const client = await createElfClient(ghidra);
|
||||
try {
|
||||
const result = await client.execute(operation, { pattern: "source" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.result).toEqual(rows.slice(0, 2));
|
||||
expect(result.value.rawResult).toEqual(rows);
|
||||
expect(result.value.limitations).toContain(
|
||||
GHIDRA_LITERAL_CANDIDATES_LIMITATION,
|
||||
);
|
||||
const regex = await client.execute(operation, {
|
||||
pattern: "source",
|
||||
mode: "regex",
|
||||
});
|
||||
if (!regex.ok) throw regex.error;
|
||||
expect(regex.value.result).toEqual(rows);
|
||||
expect(regex.value.limitations).not.toContain(
|
||||
GHIDRA_LITERAL_CANDIDATES_LIMITATION,
|
||||
);
|
||||
const sensitive = await client.execute(operation, {
|
||||
pattern: "source",
|
||||
case_sensitive: true,
|
||||
});
|
||||
if (!sensitive.ok) throw sensitive.error;
|
||||
expect(sensitive.value.result).toEqual(rows);
|
||||
expect(sensitive.value.limitations).not.toContain(
|
||||
GHIDRA_LITERAL_CANDIDATES_LIMITATION,
|
||||
);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
});
|
||||
|
||||
describe("Windows Ghidra readiness repair", () => {
|
||||
it("carries the native readiness repair into candidate capabilities and explicit selection", async () => {
|
||||
|
||||
@@ -17,6 +17,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { GhidraClient } from "../../../src/ghidra/GhidraClient.js";
|
||||
import { GhidraProvider } from "../../../src/ghidra/GhidraProvider.js";
|
||||
import { GHIDRA_LITERAL_CANDIDATES_LIMITATION } from "../../../src/ghidra/GhidraLiteralSearch.js";
|
||||
import { ghidraProducerIdentity } from "../../../src/ghidra/GhidraProducerIdentity.js";
|
||||
import { parseConfig } from "../../../src/config/parseConfig.js";
|
||||
import { silentLogger } from "../../../src/logger.js";
|
||||
@@ -659,7 +660,7 @@ it("returns a procedure once with the exact-entry names its search matched", asy
|
||||
...(matched_aliases === undefined ? {} : { matched_aliases }),
|
||||
});
|
||||
let output = jsonValueSchema.parse([
|
||||
row("0x1012a0", "audit_alias", ["audit_primary"]),
|
||||
row("0x1012a0", "source_item_alias", ["source_item_primary"]),
|
||||
]);
|
||||
const requests: unknown[] = [];
|
||||
const harness = await connectGhidraMcp(
|
||||
@@ -682,7 +683,7 @@ it("returns a procedure once with the exact-entry names its search matched", asy
|
||||
try {
|
||||
// The bridge owns exact and regex matching over its entry symbols.
|
||||
const exact = await search({
|
||||
pattern: "audit_primary",
|
||||
pattern: "source_item_primary",
|
||||
case_sensitive: true,
|
||||
});
|
||||
expect(exact.normalized_result).toEqual(output);
|
||||
@@ -694,32 +695,67 @@ it("returns a procedure once with the exact-entry names its search matched", asy
|
||||
// Node owns Unicode folding: the bridge's non-ASCII candidates are kept
|
||||
// only when they match, for secondary names as for primary names.
|
||||
output = jsonValueSchema.parse([
|
||||
row("0x1012a0", "audit_alias", ["audit_primary", "Äudit_label"]),
|
||||
row("0x101300", "ÄUDIT_only", ["ünrelated"]),
|
||||
row("0x101340", "FUN_00101340", ["AUDİT_x", "AUDIT_label"]),
|
||||
row("0x101380", "Audit_plain"),
|
||||
row("0x1012a0", "source_item_alias", [
|
||||
"source_item_primary",
|
||||
"Śource_item_label",
|
||||
]),
|
||||
row("0x101300", "ŚOURCE_ITEM_only", ["ünrelated"]),
|
||||
row("0x101340", "FUN_00101340", ["SOURCE_İTEM_x", "SOURCE_ITEM_label"]),
|
||||
row("0x101380", "ſource_item_plain"),
|
||||
]);
|
||||
const folded = await search({ pattern: "audit" });
|
||||
const folded = await search({ pattern: "source_item" });
|
||||
expect(folded.normalized_result).toEqual([
|
||||
row("0x1012a0", "audit_alias", ["audit_primary"]),
|
||||
row("0x101340", "FUN_00101340", ["AUDIT_label"]),
|
||||
row("0x101380", "Audit_plain"),
|
||||
row("0x1012a0", "source_item_alias", ["source_item_primary"]),
|
||||
row("0x101340", "FUN_00101340", ["SOURCE_ITEM_label"]),
|
||||
row("0x101380", "ſource_item_plain"),
|
||||
]);
|
||||
expect(folded.raw_result).toEqual(output);
|
||||
expect(folded.limitations).toContain(GHIDRA_LITERAL_CANDIDATES_LIMITATION);
|
||||
expect(exact.limitations).not.toContain(
|
||||
GHIDRA_LITERAL_CANDIDATES_LIMITATION,
|
||||
);
|
||||
expect(requests).toEqual([
|
||||
expect.objectContaining({ pattern: "audit_primary" }),
|
||||
expect.objectContaining({ pattern: "audit", case_sensitive: false }),
|
||||
expect.objectContaining({ pattern: "source_item_primary" }),
|
||||
expect.objectContaining({
|
||||
pattern: "source_item",
|
||||
case_sensitive: false,
|
||||
}),
|
||||
]);
|
||||
|
||||
// An empty alias list is not a match report.
|
||||
output = jsonValueSchema.parse([row("0x1012a0", "audit_alias", [])]);
|
||||
const malformed = await harness.mcp.callTool({
|
||||
name: "search_procedures",
|
||||
arguments: { pattern: "audit_", mode: "regex" },
|
||||
});
|
||||
expect(parseMcpToolError(malformed)).toMatchObject({
|
||||
error: { code: "unreadable_output" },
|
||||
output = jsonValueSchema.parse([row("0x101380", "ſource_item_plain")]);
|
||||
const regex = await search({
|
||||
pattern: "^ſource_item_plain$",
|
||||
mode: "regex",
|
||||
});
|
||||
expect(regex.normalized_result).toEqual(output);
|
||||
expect(regex.raw_result).toBeNull();
|
||||
expect(regex.limitations).not.toContain(
|
||||
GHIDRA_LITERAL_CANDIDATES_LIMITATION,
|
||||
);
|
||||
|
||||
const invalidRows = [
|
||||
{
|
||||
arguments: { pattern: "source_", mode: "regex" },
|
||||
value: row("0x1012a0", "source_item_alias", []),
|
||||
},
|
||||
{
|
||||
arguments: { pattern: "source_item" },
|
||||
value: {
|
||||
...row("0x101440", "unrelated"),
|
||||
procedure: { external: null },
|
||||
},
|
||||
},
|
||||
];
|
||||
for (const invalid of invalidRows) {
|
||||
output = jsonValueSchema.parse([invalid.value]);
|
||||
const malformed = await harness.mcp.callTool({
|
||||
name: "search_procedures",
|
||||
arguments: invalid.arguments,
|
||||
});
|
||||
expect(parseMcpToolError(malformed)).toMatchObject({
|
||||
error: { code: "unreadable_output" },
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
await harness.close();
|
||||
}
|
||||
|
||||
@@ -2678,28 +2678,16 @@ it.each(["search_procedures", "search_strings"] as const)(
|
||||
],
|
||||
};
|
||||
await expect(client.callTool(operation, query)).resolves.toEqual(expected);
|
||||
await expect(client.callToolIfReady(operation, query)).resolves.toEqual(
|
||||
expected,
|
||||
);
|
||||
for (const pattern of ["ſOURCE", "Σ"]) {
|
||||
await expect(
|
||||
client.callTool(operation, { ...query, pattern }),
|
||||
).resolves.toEqual(expected);
|
||||
for (const pattern of ["ſOURCE", "Σ"])
|
||||
await expect(
|
||||
client.callToolIfReady(operation, { ...query, pattern }),
|
||||
).resolves.toEqual(expected);
|
||||
}
|
||||
const regex = await client.callTool(operation, { ...query, mode: "regex" });
|
||||
expect(regex.ok && Array.isArray(regex.value) && regex.value.length).toBe(
|
||||
4,
|
||||
);
|
||||
const sensitive = await client.callTool(operation, {
|
||||
...query,
|
||||
case_sensitive: true,
|
||||
});
|
||||
expect(
|
||||
sensitive.ok && Array.isArray(sensitive.value) && sensitive.value.length,
|
||||
).toBe(4);
|
||||
await expect(
|
||||
client.callTool(operation, { ...query, mode: "regex" }),
|
||||
).resolves.toEqual(expected);
|
||||
await expect(
|
||||
client.callToolIfReady(operation, { ...query, case_sensitive: true }),
|
||||
).resolves.toEqual(expected);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user