mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +00:00
fix(ghidra): name the failing fields when a bridge reply misses its contract (#10749)
This commit is contained in:
1 parent
2e1e6593f2
commit
441aa170d3
4 files changed
+63
-6
No files matched your search
@@ -44,6 +44,29 @@ const parseFunctionValueFixture = (
|
||||
return parsed.ok ? { ok: true as const, value: parsed.value.value } : parsed;
|
||||
};
|
||||
|
||||
it("names the failing fields when a function reply or its envelope misses its contract", () => {
|
||||
const dossier = ghidraFunctionDossier() as Record<string, JsonValue>;
|
||||
const envelope = parseGhidraFunctionResult("analyze_function", {
|
||||
value: dossier,
|
||||
limitations: "none",
|
||||
});
|
||||
expect(envelope.ok ? undefined : envelope.error.diagnostics).toMatchObject({
|
||||
contract_issues: expect.arrayContaining([
|
||||
expect.objectContaining({ path: ["limitations"], code: "invalid_type" }),
|
||||
]),
|
||||
});
|
||||
|
||||
const reply = parseGhidraFunctionResult("analyze_function", {
|
||||
value: { ...dossier, pseudocode: 7 },
|
||||
limitations: [],
|
||||
});
|
||||
expect(reply.ok ? undefined : reply.error.diagnostics).toMatchObject({
|
||||
contract_issues: expect.arrayContaining([
|
||||
expect.objectContaining({ path: ["pseudocode"], received: "number" }),
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ghidra unresolved call locations", () => {
|
||||
it("rejects a noncanonical unresolved call site rather than retaining unverifiable location evidence", () => {
|
||||
expect(
|
||||
|
||||
@@ -48,6 +48,7 @@ import {
|
||||
} from "../domain/relationshipCoverage.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
||||
import { outputContractDiagnostics } from "../domain/native/nativeProviderOutput.js";
|
||||
import {
|
||||
ghidraIdentifierSchema,
|
||||
ghidraInputAddressSchema,
|
||||
@@ -409,7 +410,12 @@ export const parseGhidraFunctionResult = (
|
||||
new AnalysisOutputError(
|
||||
operation,
|
||||
"Ghidra bridge returned an invalid function observation envelope for this operation",
|
||||
envelope.success ? undefined : { cause: envelope.error },
|
||||
envelope.success
|
||||
? undefined
|
||||
: {
|
||||
cause: envelope.error,
|
||||
diagnostics: outputContractDiagnostics(envelope.error, value),
|
||||
},
|
||||
),
|
||||
);
|
||||
observation = envelope.data;
|
||||
@@ -452,7 +458,13 @@ export const parseGhidraFunctionResult = (
|
||||
new AnalysisOutputError(
|
||||
operation,
|
||||
"Ghidra bridge output did not match the function-analysis contract",
|
||||
{ cause: parsed.error },
|
||||
{
|
||||
cause: parsed.error,
|
||||
diagnostics: outputContractDiagnostics(
|
||||
parsed.error,
|
||||
observation.value,
|
||||
),
|
||||
},
|
||||
),
|
||||
);
|
||||
};
|
||||
@@ -97,6 +97,26 @@ it.each(["list_procedures", "search_procedures"] as const)(
|
||||
},
|
||||
);
|
||||
|
||||
it("names the failing fields when an inventory reply misses its contract", () => {
|
||||
const parsed = parseGhidraInventoryResult(
|
||||
"list_procedures",
|
||||
[{ address: 16, value: "secret-name" }],
|
||||
null,
|
||||
);
|
||||
|
||||
const error = parsed.ok ? undefined : parsed.error;
|
||||
expect(error?.diagnostics).toMatchObject({
|
||||
contract_issues: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
path: [0, "address"],
|
||||
code: "invalid_type",
|
||||
received: "number",
|
||||
}),
|
||||
]),
|
||||
});
|
||||
expect(JSON.stringify(error?.diagnostics)).not.toContain("secret-name");
|
||||
});
|
||||
|
||||
describe("native load-image result projection", () => {
|
||||
it("omits raw bridge output when the observation keeps every reported fact", () => {
|
||||
const observations = JSON.parse(
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
AnalysisOutputError,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import { projectBinaryOverview } from "../domain/native/nativeSegments.js";
|
||||
import { outputContractDiagnostics } from "../domain/native/nativeProviderOutput.js";
|
||||
import {
|
||||
availableFunctionBodySchema,
|
||||
functionBodyEntryAgrees,
|
||||
@@ -391,7 +392,7 @@ export function parseGhidraInventoryResult(
|
||||
const parsed = resultSchemas.inspect_native_load_image.safeParse(value);
|
||||
return parsed.success
|
||||
? ok({ value: normalizeNativeLoadImageObservation(parsed.data) })
|
||||
: err(inventoryOutputFailure(operation, parsed.error));
|
||||
: err(inventoryOutputFailure(operation, parsed.error, value));
|
||||
}
|
||||
if (operation === "set_address_name" || operation === "set_addresses_names") {
|
||||
return parseGhidraAddressNameResult(operation, value, namingRequest);
|
||||
@@ -406,15 +407,16 @@ export function parseGhidraInventoryResult(
|
||||
? { rawResult: value }
|
||||
: {}),
|
||||
})
|
||||
: err(inventoryOutputFailure(operation, parsed.error));
|
||||
: err(inventoryOutputFailure(operation, parsed.error, value));
|
||||
}
|
||||
|
||||
const inventoryOutputFailure = (
|
||||
operation: GhidraInventoryOperation,
|
||||
cause: unknown,
|
||||
cause: z.ZodError,
|
||||
value: JsonValue,
|
||||
): AnalysisOutputError =>
|
||||
new AnalysisOutputError(
|
||||
operation,
|
||||
"Ghidra bridge output did not match the inventory contract",
|
||||
{ cause },
|
||||
{ cause, diagnostics: outputContractDiagnostics(cause, value) },
|
||||
);
|
||||
Reference in new issue
Block a user