Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

2.5 KB
Raw Blame
import { mkdtemp, mkdir, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, posix, relative } from "node:path";
import { describe, expect, it } from "vitest";

import {
  macHopperCanonicalLauncherCandidates,
  macHopperLauncherCandidates,
  macHopperRenamedLauncherCandidates,
} from "./MacHopperPaths.js";

describe("macOS Hopper launcher paths", () => {
  const home = "/fixture/home";

  it("keeps canonical system and user candidates ahead of renamed bundles", () => {
    expect(macHopperCanonicalLauncherCandidates(home)).toEqual([
      "/Applications/Hopper Disassembler.app/Contents/MacOS/hopper",
      "/fixture/home/Applications/Hopper Disassembler.app/Contents/MacOS/hopper",
    ]);
    expect(
      macHopperRenamedLauncherCandidates(
        home,
        new Map([
          [
            "/Applications",
            ["Hopper z.app", "Hopper a.app", "Hopper Disassembler.app"],
          ],
          ["/fixture/home/Applications", ["Hopper User.app"]],
        ]),
      ),
    ).toEqual([
      "/Applications/Hopper a.app/Contents/MacOS/hopper",
      "/Applications/Hopper z.app/Contents/MacOS/hopper",
      "/fixture/home/Applications/Hopper User.app/Contents/MacOS/hopper",
    ]);
  });

  it("always includes the installer's canonical user destination", () => {
    expect(macHopperLauncherCandidates(home)).toContain(
      "/fixture/home/Applications/Hopper Disassembler.app/Contents/MacOS/hopper",
    );
  });

  it("finds renamed user bundles through the runtime filesystem scan", async () => {
    // Keep native ownership for all I/O, including UNC temporary directories.
    // On Windows, a checkout-relative home models POSIX separators without
    // discarding the drive/share or normalizing a UNC prefix through posix.join.
    const root =
      process.platform === "win32" ? join(process.cwd(), "build") : tmpdir();
    await mkdir(root, { recursive: true });
    const temporary = await mkdtemp(join(root, "rea-hopper-paths-"));
    const home =
      process.platform === "win32"
        ? relative(process.cwd(), temporary).replaceAll("\\", "/")
        : temporary;
    const appDirectory = join(temporary, "Applications", "Hopper Preview.app");
    try {
      await mkdir(appDirectory, { recursive: true });
      expect([...macHopperLauncherCandidates(home)]).toContain(
        posix.join(
          home,
          "Applications/Hopper Preview.app/Contents/MacOS/hopper",
        ),
      );
    } finally {
      await rm(temporary, { recursive: true, force: true });
    }
  });
});