Files
reverse-engineering-anything/tests/fixtures/fakeHopperReplies.mjs
T
morluto 2237f936f0 fix(test): serve fake Hopper segments in the bridge's reply contract (#10734)
* fix(test): serve fake Hopper segments in the bridge's reply contract

#10662 validates every Hopper bridge reply. The fake Hopper behind the darwin packaged-CLI baseline still served list_segments without permissions, provenance and sections, so 'rea analyze --provider hopper' failed as unreadable output on every PR that ran that lane. The fixture's replies move to fakeHopperReplies.mjs, list_segments takes the real bridge's shape, and a test checks every served reply against the contract table.

* test(hopper): derive the fake reply method list from one keyed factory object

The contract test iterated a hand-kept method list beside the reply switch, so
a reply added without updating the list would go unchecked. Replies are now
factories in one keyed object; fakeHopperReply looks them up by key and
FAKE_HOPPER_REPLY_METHODS is the object's keys, so every served reply is
validated against its contract.

* test(hopper): serve containing-procedure and reference replies from the keyed factories
2026-11-15 13:54:20 +08:00

120 lines
3.3 KiB
JavaScript

/**
* Successful bridge replies the fake Hopper serves. Each must satisfy the
* reply contract REA applies to the real bridge
* (src/hopper/HopperReplyContracts.ts).
*/
/** The one procedure the fake reports, in the bridge's identity shape. */
const FIXTURE_PROCEDURE = Object.freeze({
address: "0x1000",
name: "fixture",
symbol: null,
classification: null,
body: Object.freeze({
available: false,
reason: "The fixture has no function body-extent observation.",
}),
});
/**
* Reply factories keyed by bridge method. The keys are the single list of
* methods the fake answers, so the contract test covers every reply. A
* factory may read the request's params; without them it answers the
* default request.
*/
export const FAKE_HOPPER_REPLIES = Object.freeze({
list_segments: () => [
{
name: "__TEXT",
start: "0x1000",
end: "0x2000",
// The real bridge cannot read permissions from Hopper's public API.
readable: null,
writable: null,
executable: null,
permissions: {
available: false,
reason:
"Hopper's public Python API does not expose segment or section permissions",
},
provenance: "hopper-public-python-api",
sections: [],
},
],
list_documents: () => ["fixture"],
list_procedures: () => [{ address: "0x1000", value: "fixture" }],
list_strings: () => [{ address: "0x1000", value: "fixture" }],
procedure_pseudo_code: () => "return 0;",
rea_caller_scan_target: () => ({
target: FIXTURE_PROCEDURE,
instructions: ["0x1000"],
instructions_complete: true,
}),
rea_caller_base: () => ({
target: FIXTURE_PROCEDURE,
instructions: ["0x1000"],
instructions_complete: true,
callers: [],
callers_complete: true,
}),
rea_caller_scan_page: () => ({
start: 0,
next: 0,
total: 0,
oversized: false,
items: [],
}),
analyze_function: () => ({
procedure: {
address: "0x1000",
name: "fixture",
classification: null,
body: {
available: false,
reason: "The fixture has no function body-extent observation.",
},
signature: null,
locals: [],
},
pseudocode: "return 0;",
assembly: ["ret"],
comments: [],
callers: [],
callees: [],
incoming_references: [],
outgoing_references: [],
referenced_strings: [],
referenced_names: [],
basic_blocks: [{ start: "0x1000", end: "0x1001", successors: [] }],
native_api: null,
native_value_flow: null,
limitations: [],
}),
search_strings: () => [],
search_procedures: () => [],
xrefs: () => ["0x1000"],
resolve_containing_procedure: (params = {}) => ({
query_address:
typeof params.address === "string" ? params.address : "0x1000",
found: true,
procedure: FIXTURE_PROCEDURE,
}),
procedure_references: (params = {}) => ({
procedure: FIXTURE_PROCEDURE,
direction: params.direction === "incoming" ? "incoming" : "outgoing",
reference_kinds_available: false,
unresolved_calls: [],
references: [],
}),
});
export const fakeHopperReply = (method, params = {}) =>
Object.hasOwn(FAKE_HOPPER_REPLIES, method)
? FAKE_HOPPER_REPLIES[method](params)
: undefined;
/** Every method fakeHopperReply answers, derived from the factories. */
export const FAKE_HOPPER_REPLY_METHODS = Object.freeze(
Object.keys(FAKE_HOPPER_REPLIES),
);