refactor(test): keep coverage at behavioral boundaries (#474)
* refactor(test): keep coverage at behavioral boundaries * fix(ci): restore package workflow temp-root classification
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { parseConfig } from "../config.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTarget.js";
|
||||
import { silentLogger } from "../logger.js";
|
||||
import { HopperProvider } from "./HopperProvider.js";
|
||||
|
||||
describe("Hopper provider discovery", () => {
|
||||
it("reports bounded launcher availability without starting Hopper", () => {
|
||||
const available = provider(process.execPath).inspectAvailability();
|
||||
expect(available).toEqual({
|
||||
status: "available",
|
||||
code: null,
|
||||
reason: null,
|
||||
diagnostics: {
|
||||
launcher_path: process.execPath,
|
||||
platform: process.platform,
|
||||
},
|
||||
});
|
||||
|
||||
const missingPath = "/missing/rea-hopper-launcher";
|
||||
expect(provider(missingPath).inspectAvailability()).toEqual({
|
||||
status: "unavailable",
|
||||
code: "executable_missing",
|
||||
reason: `Hopper launcher is missing or not executable: ${missingPath}`,
|
||||
diagnostics: {
|
||||
launcher_path: missingPath,
|
||||
platform: process.platform,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("separates target kind, format, and architecture support", () => {
|
||||
const hopper = provider(process.execPath);
|
||||
expect(hopper.inspectTargetSupport(databaseTarget())).toMatchObject({
|
||||
status: "supported",
|
||||
});
|
||||
expect(
|
||||
hopper.inspectTargetSupport(executableTarget("elf", "x86_64")),
|
||||
).toMatchObject({ status: "supported" });
|
||||
expect(hopper.inspectTargetSupport(artifactTarget())).toMatchObject({
|
||||
status: "unsupported",
|
||||
code: "target_kind_unsupported",
|
||||
diagnostics: { target_kind: "archive", target_format: "asar" },
|
||||
});
|
||||
});
|
||||
|
||||
it("advertises the exact bounded byte-read limit", () => {
|
||||
const capabilities = provider(process.execPath).capabilities();
|
||||
expect(
|
||||
capabilities.find(({ operation }) => operation === "read_bytes"),
|
||||
).toMatchObject({
|
||||
available: true,
|
||||
pagination: "none",
|
||||
limits: {
|
||||
maxResults: null,
|
||||
maxPayloadBytes: 4_096,
|
||||
timeoutMs: null,
|
||||
},
|
||||
});
|
||||
expect(
|
||||
capabilities.find(
|
||||
({ operation }) => operation === "address_to_file_offset",
|
||||
),
|
||||
).toMatchObject({ available: true, pagination: "none" });
|
||||
});
|
||||
});
|
||||
|
||||
const provider = (launcherPath: string): HopperProvider => {
|
||||
const config = parseConfig({ HOPPER_LAUNCHER_PATH: launcherPath });
|
||||
if (!config.ok) throw config.error;
|
||||
return new HopperProvider(config.value, silentLogger);
|
||||
};
|
||||
|
||||
const databaseTarget = (): BinaryTarget => ({
|
||||
path: "/tmp/fixture.hop",
|
||||
sha256: "a".repeat(64),
|
||||
kind: "database",
|
||||
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 artifactTarget = (): BinaryTarget => ({
|
||||
path: "/tmp/app.asar",
|
||||
sha256: "c".repeat(64),
|
||||
kind: "archive",
|
||||
format: "asar",
|
||||
});
|
||||
Reference in New Issue
Block a user