From 6d895a9e8b7615e441fc0230382ae3af798ffb1f Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:08:53 -0500 Subject: [PATCH] test(hopper): consolidate host and launcher selection coverage (#12934) --- src/cliHostInputs.test.ts | 36 ---------- src/hopper/HopperProviderDiscovery.test.ts | 72 ++++++++++--------- .../HopperLauncherDiscovery.test.ts | 17 +++-- 3 files changed, 49 insertions(+), 76 deletions(-) delete mode 100644 src/cliHostInputs.test.ts diff --git a/src/cliHostInputs.test.ts b/src/cliHostInputs.test.ts deleted file mode 100644 index 4feebb910e..0000000000 --- a/src/cliHostInputs.test.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { describe, expect, it } from "vitest"; - -import { HopperProvider } from "./hopper/HopperProvider.js"; -import { silentLogger } from "./logger.js"; -import { parseConfig } from "./config/parseConfig.js"; - -const config = (env: Record = {}) => { - const parsed = parseConfig(env); - if (!parsed.ok) throw new Error("expected valid configuration"); - return parsed.value; -}; - -describe("host platform is injected, not read from the ambient process", () => { - it("reports Hopper as unsupported for a platform it cannot run on", () => { - const provider = new HopperProvider(config(), silentLogger, {}, "win32"); - const availability = provider.inspectAvailability(); - expect(availability).toMatchObject({ - status: "unavailable", - code: "unsupported_host", - }); - expect(JSON.stringify(availability)).toContain("win32"); - }); - - it.each(["darwin", "linux"] as const)( - "does not gate Hopper as unsupported on %s", - (platform) => { - const provider = new HopperProvider( - config({ hopper_launcher_path: "/nonexistent/hopper-launcher" }), - silentLogger, - {}, - platform, - ); - expect(provider.inspectAvailability().code).not.toBe("unsupported_host"); - }, - ); -}); diff --git a/src/hopper/HopperProviderDiscovery.test.ts b/src/hopper/HopperProviderDiscovery.test.ts index aca9393a4d..8b8ad98617 100644 --- a/src/hopper/HopperProviderDiscovery.test.ts +++ b/src/hopper/HopperProviderDiscovery.test.ts @@ -11,29 +11,35 @@ import { silentLogger } from "../logger.js"; import { HopperProvider } from "./HopperProvider.js"; describe("Hopper provider discovery", () => { - it.skipIf(process.platform === "win32")( - "reports bounded launcher availability without starting Hopper", - () => { - const available = provider(process.execPath).inspectAvailability(); + it.each(["darwin", "linux"] as const)( + "reports launcher availability for an injected %s host", + async (platform) => { + const available = provider( + process.execPath, + platform, + ).inspectAvailability(); expect(available).toEqual({ status: "available", code: null, reason: null, diagnostics: { launcher_path: process.execPath, - platform: process.platform, + platform, }, }); - const missingPath = "/missing/rea-hopper-launcher"; - expect(provider(missingPath).inspectAvailability()).toEqual({ + const home = await createTestTempDirectory( + "rea-hopper-missing-launcher-", + ); + const missingPath = join(home, "missing"); + expect(provider(missingPath, platform).inspectAvailability()).toEqual({ status: "unavailable", code: "executable_missing", reason: `Hopper launcher is missing or not executable: ${missingPath}`, remediation: expect.stringContaining("HOPPER_LAUNCHER_PATH"), diagnostics: { launcher_path: missingPath, - platform: process.platform, + platform, }, }); }, @@ -80,6 +86,17 @@ describe("Hopper provider discovery", () => { }, ); + it("rejects an injected Windows host even with a selected executable", () => { + expect( + provider(process.execPath, "win32").inspectAvailability(), + ).toMatchObject({ + status: "unavailable", + code: "unsupported_host", + diagnostics: { platform: "win32", launcher_path: process.execPath }, + remediation: expect.stringContaining("REA_ANALYSIS_PROVIDER"), + }); + }); + it.runIf(process.platform === "win32")( "reports Hopper integration as unsupported on Windows", () => { @@ -96,9 +113,9 @@ describe("Hopper provider discovery", () => { expect(hopper.inspectTargetSupport(databaseTarget())).toMatchObject({ status: "supported", }); - expect( - hopper.inspectTargetSupport(executableTarget("elf", "x86_64")), - ).toMatchObject({ status: "supported" }); + expect(hopper.inspectTargetSupport(executableTarget)).toMatchObject({ + status: "supported", + }); expect(hopper.inspectTargetSupport(artifactTarget())).toMatchObject({ status: "unsupported", code: "target_kind_unsupported", @@ -125,7 +142,7 @@ describe("Hopper provider discovery", () => { const provider = ( launcherPath: string, - platform: NodeJS.Platform = process.platform, + platform?: NodeJS.Platform, ): HopperProvider => { const config = parseConfig({ HOPPER_LAUNCHER_PATH: launcherPath }); if (!config.ok) throw config.error; @@ -139,29 +156,14 @@ const databaseTarget = (): BinaryTarget => ({ format: "analysis-database", }); -const executableTarget = ( - format: "mach-o" | "elf" | "pe", - architecture: "x86" | "x86_64" | "arm" | "arm64", -): BinaryTarget => - format === "pe" - ? { - path: "/tmp/fixture", - sha256: "b".repeat(64), - kind: "executable", - format, - architecture, - availableArchitectures: [architecture], - executableRole: "application", - managed: false, - } - : { - path: "/tmp/fixture", - sha256: "b".repeat(64), - kind: "executable", - format, - architecture, - availableArchitectures: [architecture], - }; +const executableTarget: BinaryTarget = { + path: "/tmp/fixture", + sha256: "b".repeat(64), + kind: "executable", + format: "elf", + architecture: "x86_64", + availableArchitectures: ["x86_64"], +}; const artifactTarget = (): BinaryTarget => ({ path: "/tmp/app.asar", diff --git a/src/hopperPaths/HopperLauncherDiscovery.test.ts b/src/hopperPaths/HopperLauncherDiscovery.test.ts index 4ffdbf5c87..1b5c99527f 100644 --- a/src/hopperPaths/HopperLauncherDiscovery.test.ts +++ b/src/hopperPaths/HopperLauncherDiscovery.test.ts @@ -9,12 +9,18 @@ describe("default Linux Hopper launcher", () => { (path: string): boolean => paths.includes(path); - it.each([["/opt/hopper-v4/bin/hopper"], ["/usr/bin/hopper"]])( - "selects an existing system launcher %s", - (path) => { + it.each([ + [ + "/opt/hopper-v4/bin/hopper", + ["/usr/bin/hopper", "/opt/hopper-v4/bin/hopper"], + ], + ["/usr/bin/hopper", ["/usr/bin/hopper"]], + ])( + "selects system launcher %s when those candidates exist", + (expected, present) => { expect( - defaultHopperLauncherPath("linux", home, withExecutables([path])), - ).toBe(path); + defaultHopperLauncherPath("linux", home, withExecutables(present)), + ).toBe(expected); }, ); @@ -25,6 +31,7 @@ describe("default Linux Hopper launcher", () => { home, withExecutables([ "/opt/hopper/bin/Hopper", + `${home}/.local/share/rea/hopper/bin/Hopper`, "/opt/hopper-v4/bin/hopper", "/usr/bin/hopper", ]),