import { describe, expect, test } from "bun:test";
import { getPlatformPackage, getBinaryPath } from "./platform.js";
describe("getPlatformPackage", () => {
test("returns darwin-arm64 for macOS ARM64", () => {
const input = { platform: "darwin", arch: "arm64" };
const result = getPlatformPackage(input);
expect(result).toBe("oh-my-opencode-darwin-arm64");
});
test("returns darwin-x64 for macOS Intel", () => {
const input = { platform: "darwin", arch: "x64" };
const result = getPlatformPackage(input);
expect(result).toBe("oh-my-opencode-darwin-x64");
});
test("returns linux-x64 for Linux x64 with glibc", () => {
const input = { platform: "linux", arch: "x64", libcFamily: "glibc" };
const result = getPlatformPackage(input);
expect(result).toBe("oh-my-opencode-linux-x64");
});
test("returns linux-arm64 for Linux ARM64 with glibc", () => {
const input = { platform: "linux", arch: "arm64", libcFamily: "glibc" };
const result = getPlatformPackage(input);
expect(result).toBe("oh-my-opencode-linux-arm64");
});
test("returns linux-x64-musl for Alpine x64", () => {
const input = { platform: "linux", arch: "x64", libcFamily: "musl" };
const result = getPlatformPackage(input);
expect(result).toBe("oh-my-opencode-linux-x64-musl");
});
test("returns linux-arm64-musl for Alpine ARM64", () => {
const input = { platform: "linux", arch: "arm64", libcFamily: "musl" };
const result = getPlatformPackage(input);
expect(result).toBe("oh-my-opencode-linux-arm64-musl");
});
test("returns windows-x64 for Windows", () => {
const input = { platform: "win32", arch: "x64" };
const result = getPlatformPackage(input);
expect(result).toBe("oh-my-opencode-windows-x64");
});
test("throws error for Linux with null libcFamily", () => {
const input = { platform: "linux", arch: "x64", libcFamily: null };
expect(() => getPlatformPackage(input)).toThrow("Could not detect libc");
});
test("throws error for Linux with undefined libcFamily", () => {
const input = { platform: "linux", arch: "x64", libcFamily: undefined };
expect(() => getPlatformPackage(input)).toThrow("Could not detect libc");
});
});
describe("getBinaryPath", () => {
test("returns path without .exe for Unix platforms", () => {
const pkg = "oh-my-opencode-darwin-arm64";
const platform = "darwin";
const result = getBinaryPath(pkg, platform);
expect(result).toBe("oh-my-opencode-darwin-arm64/bin/oh-my-opencode");
});
test("returns path with .exe for Windows", () => {
const pkg = "oh-my-opencode-windows-x64";
const platform = "win32";
const result = getBinaryPath(pkg, platform);
expect(result).toBe("oh-my-opencode-windows-x64/bin/oh-my-opencode.exe");
});
test("returns path without .exe for Linux", () => {
const pkg = "oh-my-opencode-linux-x64";
const platform = "linux";
const result = getBinaryPath(pkg, platform);
expect(result).toBe("oh-my-opencode-linux-x64/bin/oh-my-opencode");
});
});