fix(hopper): resolve FAT loaders and original file coordinates

This commit is contained in:
morluto
2026-10-09 05:12:36 +08:00
parent b2d5bc1109
commit 35f1ddd6bc
13 changed files with 489 additions and 112 deletions
@@ -32,29 +32,8 @@ describe("Hopper analysis profiles", () => {
});
it.each([
[target("mach-o", "arm64"), ["-l", "Mach-O", "--aarch64"]],
[target("elf", "x86_64"), ["-l", "ELF", "--intel-64"]],
[target("pe", "x86"), ["-l", "WinPE", "--intel-32"]],
[
{
path: "/tmp/fixture",
sha256: "a".repeat(64),
kind: "executable",
format: "mach-o",
architecture: "arm64",
availableArchitectures: ["x86_64", "arm64"] as const,
} satisfies BinaryTarget,
["-l", "FAT", "--aarch64", "-l", "Mach-O"],
],
[
{
path: "/tmp/fixture.hop",
sha256: "b".repeat(64),
kind: "database",
format: "analysis-database",
} satisfies BinaryTarget,
[],
],
] as const)("derives complete non-interactive options", (input, expected) => {
expect(hopperLoaderArgsForTarget(input)).toEqual({
ok: true,
@@ -63,54 +42,6 @@ describe("Hopper analysis profiles", () => {
expect("loaderArgs" in input).toBe(false);
});
it("commits launcher build and configured overrides without target coupling", async () => {
directory = await createTestTempDirectory("rea-hopper-profile-");
const launcher = join(directory, "hopper");
await writeFile(launcher, "Hopper build A");
const input = target("mach-o", "arm64");
const derived = await resolveHopperAnalysisProfile(input, {
launcherPath: launcher,
loaderArgsOverride: [],
provider: HOPPER_PROVIDER_IDENTITY,
});
const overridden = await resolveHopperAnalysisProfile(input, {
launcherPath: launcher,
loaderArgsOverride: ["-l", "Mach-O", "--intel-64"],
provider: HOPPER_PROVIDER_IDENTITY,
});
if (
!derived.ok ||
derived.value.profile === null ||
!overridden.ok ||
overridden.value.profile === null
)
throw new Error("fixture profiles did not resolve");
expect(derived.value.compatibility).toEqual({
loaderArgs: ["-l", "Mach-O", "--aarch64"],
});
expect(overridden.value.compatibility).toEqual({
loaderArgs: ["-l", "Mach-O", "--intel-64"],
});
expect(overridden.value.profile.digest).not.toBe(
derived.value.profile.digest,
);
expect(derived.value.profile.provider.version).toMatch(
/^launcher-sha256:[a-f0-9]{64}$/u,
);
await writeFile(launcher, "Hopper build B");
const changedBuild = await resolveHopperAnalysisProfile(input, {
launcherPath: launcher,
loaderArgsOverride: [],
provider: HOPPER_PROVIDER_IDENTITY,
});
if (!changedBuild.ok || changedBuild.value.profile === null)
throw new Error("changed fixture profile did not resolve");
expect(changedBuild.value.profile.provider.version).not.toBe(
derived.value.profile.provider.version,
);
});
it("keeps compatibility output but declines cache identity when version is unresolved", async () => {
const resolved = await resolveHopperAnalysisProfile(
target("elf", "x86_64"),