// Acceptance gate for the founder-side `--tier <enum>` installer flag (Task 240).
// Pure-module coverage: validation rules, mode-mismatch rejection, config merge.
// Wiring through index.ts argv is exercised by manual install per task verification §1.
import test from "node:test";
import assert from "node:assert/strict";
import { validateTierFlag, applyTierToAccountConfig, isValidTier, } from "../tier-flag.js";
test("validateTierFlag accepts solo|family|pro when commercialMode is false", () => {
    assert.equal(validateTierFlag("solo", false), "solo");
    assert.equal(validateTierFlag("family", false), "family");
    assert.equal(validateTierFlag("pro", false), "pro");
});
test("validateTierFlag rejects values outside the enum", () => {
    assert.throws(() => validateTierFlag("enterprise", false), /--tier value must be one of: solo, family, pro/);
    assert.throws(() => validateTierFlag("max", false), /--tier value must be one of: solo, family, pro/);
});
test("validateTierFlag rejects empty or flag-shaped value", () => {
    assert.throws(() => validateTierFlag(undefined, false), /--tier requires a value/);
    assert.throws(() => validateTierFlag("", false), /--tier requires a value/);
    assert.throws(() => validateTierFlag("--hostname", false), /--tier requires a value/);
});
test("validateTierFlag rejects --tier when brand is commercial-mode", () => {
    assert.throws(() => validateTierFlag("family", true), /Commercial mode — use --entitlement-base64/);
    // Mode mismatch fires before enum check — operator gets the redirect, not "invalid enum".
    assert.throws(() => validateTierFlag("enterprise", true), /Commercial mode — use --entitlement-base64/);
});
test("applyTierToAccountConfig stamps tier and preserves every other key", () => {
    const before = {
        accountId: "abc-123",
        enabledPlugins: ["whatsapp", "outlook"],
        outputStyle: "default",
        thinkingView: "default",
    };
    const after = applyTierToAccountConfig(before, "family");
    assert.equal(after.tier, "family");
    assert.equal(after.accountId, "abc-123");
    assert.deepEqual(after.enabledPlugins, ["whatsapp", "outlook"]);
    assert.equal(after.outputStyle, "default");
    assert.equal(after.thinkingView, "default");
    // Input not mutated — caller can safely roundtrip.
    assert.equal(before.tier, undefined);
});
test("applyTierToAccountConfig overwrites a previously-stamped tier", () => {
    const after = applyTierToAccountConfig({ tier: "solo", accountId: "x" }, "pro");
    assert.equal(after.tier, "pro");
    assert.equal(after.accountId, "x");
});
test("isValidTier narrows correctly", () => {
    assert.equal(isValidTier("solo"), true);
    assert.equal(isValidTier("family"), true);
    assert.equal(isValidTier("pro"), true);
    assert.equal(isValidTier("enterprise"), false);
    assert.equal(isValidTier(""), false);
});
