test(hopper): consolidate host and launcher selection coverage (#12934)

This commit is contained in:
morluto authored and GitHub committed 2026-11-20 22:08:53 +00:00
1 parent 48e1af5990
commit 6d895a9e8b
3 files changed
+49 -76

No files matched your search

-36
View File
@@ -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<string, string | undefined> = {}) => {
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");
},
);
});
+37 -35
View File
@@ -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",
@@ -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",
]),