import { describe, expect, it } from "vitest"; import { parseConfig } from "../src/config.js"; describe("runtime configuration", () => { it("allows target-free startup and defaults to Hopper's documented launcher", () => { const empty = parseConfig({}); expect(empty.ok).toBe(true); if (empty.ok) expect(empty.value.hopperTargetPath).toBeUndefined(); const result = parseConfig({ HOPPER_TARGET_PATH: "/usr/bin/true" }); expect(result.ok).toBe(true); if (result.ok) { expect(result.value.hopperLauncherPath).toContain("/MacOS/hopper"); expect(result.value.hopperTargetKind).toBe("executable"); expect(result.value.hopperLoaderArgs).toEqual([]); expect(result.value.logLevel).toBe("info"); } }); it("parses database kind and loader arguments", () => { expect( parseConfig({ HOPPER_TARGET_PATH: "/fixture/sample.hop", HOPPER_TARGET_KIND: "database", HOPPER_LOADER_ARGS_JSON: '["-l","FAT","--aarch64","-l","Mach-O"]', }), ).toEqual({ ok: true, value: { hopperLauncherPath: "/Applications/Hopper Disassembler.app/Contents/MacOS/hopper", hopperTargetPath: "/fixture/sample.hop", hopperTargetKind: "database", hopperLoaderArgs: ["-l", "FAT", "--aarch64", "-l", "Mach-O"], logLevel: "info", processExecutionPolicy: { enabled: false, executableRoots: [], workingRoots: [], allowedEnvironment: [], }, }, }); }); it.each(["not-json", "{}", '["ok",1]'])( "rejects invalid loader args: %s", (encoded) => { expect( parseConfig({ HOPPER_TARGET_PATH: "/tmp/a", HOPPER_LOADER_ARGS_JSON: encoded, }).ok, ).toBe(false); }, ); it("parses supported log levels and rejects unknown levels", () => { const configured = parseConfig({ REA_LOG_LEVEL: "debug" }); expect(configured.ok && configured.value.logLevel).toBe("debug"); expect(parseConfig({ REA_LOG_LEVEL: "verbose" }).ok).toBe(false); }); });