// Tests for the brand-level premium bundle gate (Task 344).
//
// The gate normalises `brand.shipsPremiumBundles` and partitions the
// on-disk bundle list into shipped/skipped/missing. The bundle.js script
// uses it; tests are ephemeral per the sprint workflow.
import test from "node:test";
import assert from "node:assert/strict";
// @ts-expect-error - sibling .mjs without type declarations
import { normalisePremiumGate, partitionBundles } from "../../scripts/premium-bundle-gate.mjs";
test("normalisePremiumGate: undefined → mode 'none'", () => {
    const gate = normalisePremiumGate(undefined);
    assert.equal(gate.mode, "none");
    assert.equal(gate.allow.size, 0);
});
test("normalisePremiumGate: null → mode 'none'", () => {
    const gate = normalisePremiumGate(null);
    assert.equal(gate.mode, "none");
});
test("normalisePremiumGate: string[] → mode 'allowlist'", () => {
    const gate = normalisePremiumGate(["real-agent", "venture-studio"]);
    assert.equal(gate.mode, "allowlist");
    assert.ok(gate.allow.has("real-agent"));
    assert.ok(gate.allow.has("venture-studio"));
});
test("normalisePremiumGate: boolean true is rejected (legacy form)", () => {
    assert.throws(() => normalisePremiumGate(true, "/brands/x/brand.json"), /boolean 'true' no longer accepted/);
});
test("normalisePremiumGate: boolean false is rejected (must omit instead)", () => {
    assert.throws(() => normalisePremiumGate(false, "/brands/x/brand.json"), /boolean 'false' no longer accepted/);
});
test("normalisePremiumGate: non-array non-bool throws", () => {
    assert.throws(() => normalisePremiumGate("real-agent"));
    assert.throws(() => normalisePremiumGate({}));
});
test("normalisePremiumGate: array with non-kebab entry throws", () => {
    assert.throws(() => normalisePremiumGate(["Real-Agent"]), /invalid entry/);
    assert.throws(() => normalisePremiumGate([""]), /invalid entry/);
    assert.throws(() => normalisePremiumGate([42]), /invalid entry/);
});
test("partitionBundles: mode 'none' ships nothing; everything on disk is skipped", () => {
    const gate = normalisePremiumGate(undefined);
    const result = partitionBundles(gate, ["real-agent", "venture-studio"]);
    assert.deepEqual(result.shipped, []);
    assert.deepEqual(result.skipped, ["real-agent", "venture-studio"]);
    assert.deepEqual(result.missing, []);
});
test("partitionBundles: allowlist filters on-disk set", () => {
    const gate = normalisePremiumGate(["venture-studio"]);
    const result = partitionBundles(gate, ["real-agent", "teaching", "venture-studio", "writer-craft"]);
    assert.deepEqual(result.shipped, ["venture-studio"]);
    assert.deepEqual(result.skipped, ["real-agent", "teaching", "writer-craft"]);
    assert.deepEqual(result.missing, []);
});
test("partitionBundles: allowlist entry with no matching directory is missing", () => {
    const gate = normalisePremiumGate(["real-agent", "nope"]);
    const result = partitionBundles(gate, ["real-agent", "teaching"]);
    assert.deepEqual(result.shipped, ["real-agent"]);
    assert.deepEqual(result.missing, ["nope"]);
});
