// acceptance grid for macos-version.ts.
//
// Pure two-export module: parseSwVers extracts ProductName + ProductVersion
// from `sw_vers` stdout; isSupportedMacosVersion checks whether the version's
// major component is ≥ 14 (the floor Tasks 838/839 require for modern
// `launchctl bootstrap gui/$UID …` and Apple-Silicon Homebrew). No I/O — the
// caller spawns `sw_vers` and feeds stdout in, mirroring apt-resolve.ts.
//
// Runs via Node's built-in test runner; no vitest. Compiles to
// dist/__tests__/macos-version.test.js so `node --test dist/__tests__/*.test.js`
// picks it up after build.
import test from "node:test";
import assert from "node:assert/strict";
import { parseSwVers, isSupportedMacosVersion, } from "../macos-version.js";
// ---------------------------------------------------------------------------
// Real fixtures — captured from `sw_vers` on actual macOS hosts. The trailing
// newline matches subprocess stdout exactly; parseSwVers must tolerate it.
// ---------------------------------------------------------------------------
const SW_VERS_MACOS_14_4_1 = `ProductName: macOS
ProductVersion: 14.4.1
BuildVersion: 23E224
`;
const SW_VERS_MACOS_13_7_1 = `ProductName: macOS
ProductVersion: 13.7.1
BuildVersion: 22H313
`;
const SW_VERS_MACOS_14_0 = `ProductName: macOS
ProductVersion: 14.0
BuildVersion: 23A344
`;
const SW_VERS_MACOS_15_2 = `ProductName: macOS
ProductVersion: 15.2
BuildVersion: 24C101
`;
const SW_VERS_MACOS_12_7_6 = `ProductName: macOS
ProductVersion: 12.7.6
BuildVersion: 21H1320
`;
// ---------------------------------------------------------------------------
// parseSwVers — extracts ProductName + ProductVersion; null on malformed.
// ---------------------------------------------------------------------------
test("parseSwVers extracts product + version from macOS 14.4.1 fixture", () => {
    const r = parseSwVers(SW_VERS_MACOS_14_4_1);
    assert.deepEqual(r, { product: "macOS", version: "14.4.1" });
});
test("parseSwVers extracts product + version from macOS 13.7.1 fixture", () => {
    const r = parseSwVers(SW_VERS_MACOS_13_7_1);
    assert.deepEqual(r, { product: "macOS", version: "13.7.1" });
});
test("parseSwVers handles macOS 14.0 (no patch component)", () => {
    const r = parseSwVers(SW_VERS_MACOS_14_0);
    assert.deepEqual(r, { product: "macOS", version: "14.0" });
});
test("parseSwVers handles macOS 12.7.6 (legacy three-component)", () => {
    const r = parseSwVers(SW_VERS_MACOS_12_7_6);
    assert.deepEqual(r, { product: "macOS", version: "12.7.6" });
});
test("parseSwVers returns null on empty stdout (spawn failed)", () => {
    assert.equal(parseSwVers(""), null);
});
test("parseSwVers returns null on stdout missing ProductVersion line", () => {
    // Defensive: future `sw_vers` schema change must not silently produce
    // `{ product: "macOS", version: undefined }` — we want a hard null so the
    // caller refuses with the malformed-stdout diagnostic.
    assert.equal(parseSwVers("ProductName: macOS\nBuildVersion: 23E224\n"), null);
});
test("parseSwVers returns null on stdout missing ProductName line", () => {
    assert.equal(parseSwVers("ProductVersion: 14.4.1\nBuildVersion: 23E224\n"), null);
});
test("parseSwVers returns null on totally unrelated stdout", () => {
    assert.equal(parseSwVers("hello world\n"), null);
});
// ---------------------------------------------------------------------------
// isSupportedMacosVersion — boundary at major ≥ 14.
// ---------------------------------------------------------------------------
test("isSupportedMacosVersion: 14.0 → true (boundary, exactly the floor)", () => {
    assert.equal(isSupportedMacosVersion("14.0"), true);
});
test("isSupportedMacosVersion: 14.4.1 → true (current shipping macOS 14)", () => {
    assert.equal(isSupportedMacosVersion("14.4.1"), true);
});
test("isSupportedMacosVersion: 15.2 → true (future macOS 15)", () => {
    assert.equal(isSupportedMacosVersion(parseSwVers(SW_VERS_MACOS_15_2)?.version ?? ""), true);
});
test("isSupportedMacosVersion: 13.7.1 → false (one minor below floor)", () => {
    assert.equal(isSupportedMacosVersion("13.7.1"), false);
});
test("isSupportedMacosVersion: 12.7.6 → false (well below floor)", () => {
    assert.equal(isSupportedMacosVersion("12.7.6"), false);
});
test("isSupportedMacosVersion: empty string → false (parse failure surrogate)", () => {
    assert.equal(isSupportedMacosVersion(""), false);
});
test("isSupportedMacosVersion: garbage string → false (no leading integer)", () => {
    assert.equal(isSupportedMacosVersion("not a version"), false);
});
