// wedge — acceptance grid for platform-detect.ts.
//
// Pure two-export module: detectPlatform classifies any process.platform value
// into the ternary the installer cares about; requireSupportedPlatform throws on
// unsupported with the literal refusal message that follow-up tasks (838/839/840)
// will surface in install logs. Caller injects the platform value so tests run
// identically on Linux CI and Mac developer boxes — no process.platform reads
// inside the module under test.
import test from "node:test";
import assert from "node:assert/strict";
import { detectPlatform, requireSupportedPlatform, } from "../platform-detect.js";
// ---------------------------------------------------------------------------
// detectPlatform — ternary classifier over Node's process.platform values.
// ---------------------------------------------------------------------------
test("detectPlatform: linux maps to linux", () => {
    assert.equal(detectPlatform("linux"), "linux");
});
test("detectPlatform: darwin maps to darwin", () => {
    assert.equal(detectPlatform("darwin"), "darwin");
});
test("detectPlatform: win32 maps to unsupported", () => {
    assert.equal(detectPlatform("win32"), "unsupported");
});
test("detectPlatform: every other Node platform maps to unsupported", () => {
    // Lock the set so a future Node version that adds a new platform string
    // doesn't accidentally fall into 'linux' or 'darwin' via a typo.
    for (const p of ["freebsd", "openbsd", "sunos", "aix", "cygwin", "netbsd", "android", "haiku"]) {
        assert.equal(detectPlatform(p), "unsupported", `${p} must be unsupported`);
    }
});
// ---------------------------------------------------------------------------
// requireSupportedPlatform — return narrowed value or throw with literal msg.
// ---------------------------------------------------------------------------
test("requireSupportedPlatform: linux returns 'linux'", () => {
    assert.equal(requireSupportedPlatform("linux"), "linux");
});
test("requireSupportedPlatform: darwin returns 'darwin'", () => {
    assert.equal(requireSupportedPlatform("darwin"), "darwin");
});
test("requireSupportedPlatform: win32 throws with the literal refusal message", () => {
    assert.throws(() => requireSupportedPlatform("win32"), {
        message: "[create-maxy] platform=win32 — refusing: only linux and darwin are supported",
    });
});
test("requireSupportedPlatform: refusal message embeds the actual platform string", () => {
    // The platform token in the message is load-bearing for log-grep diagnostics
    // spec calls out `[create-maxy] platform=darwin macos=<v> — refusing`
    // as the failure signature for macOS-14 pre-flight. Pin the token verbatim.
    assert.throws(() => requireSupportedPlatform("freebsd"), /^Error: \[create-maxy\] platform=freebsd — refusing: only linux and darwin are supported$/);
});
