test(hopper): bind string assertions to observed source extents

Remove OS-based assumptions about long and non-ASCII string recognition. Require the dedicated fragmented fixture, independently verify full source bytes, and reject gaps, overlaps, incomplete reads and corrupted decoding. Report unrecognized native strings explicitly and retain the actual procedure count.

Verified through 14 verifier regressions and the complete macOS arm64 Hopper 6.6.0-demo CLI/MCP lane with cleanup.
This commit is contained in:
morluto
2026-10-14 07:12:10 +08:00
parent b1b0211c28
commit 02987d8e8c
5 changed files with 203 additions and 59 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ volatile int rea_c_global = 7;
/* Keep the full-size literal even when a loader does not type it as a string. */
__attribute__((used)) const char rea_long_literal[] =
"REA_LONG_LITERAL_" REA_LONG_1024 REA_LONG_1024 REA_LONG_1024 REA_LONG_1024 "needle";
/* Linux Hopper 6.4.2 recognizes this extent and splits it into native objects. */
/* Verified Hopper loaders recognize this extent and split it into native objects. */
__attribute__((used)) const char rea_fragmented_literal[] =
"REA_FRAGMENTED_LITERAL_" REA_LONG_256 REA_LONG_256 "fragment_tail";
__attribute__((used)) const char rea_utf8_literal[] = "REA_UTF8_é_😀";
@@ -1,6 +1,9 @@
import { expect, it } from "vitest";
import { verifyHopperStringObjects } from "../../../../scripts/lib/real-hopper-search.mjs";
import {
verifyHopperStringFragments,
verifyHopperStringObjects,
} from "../../../../scripts/lib/real-hopper-search.mjs";
const value = "REA_UTF8_é_😀";
const address = "0x402020";
@@ -22,6 +25,100 @@ const expectation = {
recognitionOptional: true,
};
const fragments = [
{
...item,
value: "REA_",
string: { ...item.string, termination: "missing" as const, byte_length: 4 },
},
{
...item,
address: "0x402024",
value: value.slice(4),
string: { ...item.string, byte_length: bytes.length - 4 },
},
] as const;
const fragmentBytes = async (
name: string,
args: Record<string, unknown> = {},
) => {
if (name !== "read_bytes") throw new Error(`Unmodeled call: ${name}`);
const offset =
args.address === expectation.symbol
? 0
: Number(BigInt(String(args.address)) - BigInt(address));
return {
address: `0x${(BigInt(address) + BigInt(offset)).toString(16)}`,
complete: true,
bytes_hex: bytes
.subarray(offset, offset + Number(args.length))
.toString("hex"),
};
};
it("verifies contiguous native fragments against the complete source bytes", async () => {
const result = await verifyHopperStringFragments(
fragmentBytes,
fragments,
expectation,
);
expect(result.recognition).toEqual({
address,
state: "observed",
decodedObject: "verified",
});
expect(result.sourceBytes).toBe(bytes.length);
});
it("reports unrecognized source bytes without accepting identical text at another address", async () => {
const elsewhere = [{ ...item, address: "0x403000" }];
const result = await verifyHopperStringFragments(
fragmentBytes,
elsewhere,
expectation,
);
expect(result.recognition).toEqual({
address,
state: "not_observed",
decodedObject: "unverified",
});
await expect(
verifyHopperStringFragments(fragmentBytes, elsewhere, {
...expectation,
recognitionOptional: false,
}),
).rejects.toThrow(/typed string fragments/u);
});
it.each([
["gap", [fragments[0], { ...fragments[1], address: "0x402025" }]],
["overlap", [fragments[0], { ...fragments[1], address: "0x402023" }]],
["missing prefix", [fragments[1]]],
["wrong decoded value", [{ ...item, value: "X" + value.slice(1) }]],
["missing tail", [fragments[0]]],
])(
"rejects %s even when fragment recognition is optional",
async (_label, inventory) => {
await expect(
verifyHopperStringFragments(fragmentBytes, inventory, expectation),
).rejects.toThrow();
},
);
it("rejects incomplete source bytes even with no native string objects", async () => {
await expect(
verifyHopperStringFragments(
async (name: string, args: Record<string, unknown> = {}) => ({
...(await fragmentBytes(name, args)),
complete: false,
}),
[],
expectation,
),
).rejects.toThrow();
});
it("keeps source identity and unknown decoding when the same text exists elsewhere", async () => {
const report = await verifyHopperStringObjects(
fixtureCall(),