"use strict";
/**
 * capability-catalog-bundle-licensing.test.ts
 *
 * Tests for bundledPackIds() and the extended isUnlicensed() in capability-catalog.ts.
 *
 * Thomas Layer 0 directive 2026-05-22 01:00 (clarification):
 *   License-layer bundling — ISO 27001 + GDPR are licensed at the org level
 *   when the customer buys a group pack. isUnlicensed() must accept these
 *   capabilities without raising an "unlicensed" rejection, even if the packs
 *   are not in the explicit licensedPacks[] list.
 *
 * Test IDs:
 *   CB-1   bundledPackIds('hipaa', usGroup) → ['iso_27001']
 *   CB-2   bundledPackIds('eu-mdr', euGroup) → ['iso_27001', 'gdpr']
 *   CB-3   bundledPackIds excludes parentPackId itself from the result
 *   CB-4   isUnlicensed: HIPAA capability is not unlicensed when hipaa is licensed
 *   CB-5   isUnlicensed: ISO 27001 capability NOT unlicensed for US group (bundled)
 *   CB-6   isUnlicensed: GDPR capability IS unlicensed for US group (not bundled)
 *   CB-7   isUnlicensed: GDPR capability NOT unlicensed for EU group (bundled)
 *   CB-8   isUnlicensed: base capabilities are never unlicensed (no group needed)
 *   CB-9   isUnlicensed: unknown capability returns false (graceful degrade)
 *   CB-10  bundledPackIds: without group, only iso_27001 is returned (no gdpr)
 *
 * Step 5 RED→GREEN:
 *   RED  (before): bundledPackIds did not exist; isUnlicensed did not accept group arg.
 *   GREEN (after): all CB tests pass.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = require("node:test");
const strict_1 = __importDefault(require("node:assert/strict"));
const capability_catalog_js_1 = require("../capability-catalog.js");
// ---------------------------------------------------------------------------
// Minimal VerticalGroup fixtures (no DB access needed)
// ---------------------------------------------------------------------------
function makePack(id, jurisdiction) {
    return {
        id,
        name: id,
        shortName: id,
        description: '',
        jurisdiction,
        vertical: 'Healthcare',
        priority: 'P1',
        status: 'ACTIVE',
        frameworkCategory: 'sector-specific',
        keyRequirements: [],
        aiRelevance: '',
        crossIndustry: false,
        pricing: { tier: '6000', monthlyUsd: 500, annualUsd: 5100 },
    };
}
const US_HEALTHCARE_GROUP = {
    groupKey: 'healthcare-us',
    vertical: 'Healthcare',
    jurisdiction: 'US',
    displayName: 'US Healthcare',
    description: '',
    packs: [makePack('hipaa', 'US'), makePack('hitech', 'US')],
    priceAnnualUsd: 4000,
    includedBaselinePacks: ['iso27001'],
};
const EU_HEALTHCARE_GROUP = {
    groupKey: 'healthcare-eu',
    vertical: 'Healthcare',
    jurisdiction: 'EU',
    displayName: 'EU Healthcare',
    description: '',
    packs: [makePack('eu-mdr', 'EU'), makePack('eu_ai_act', 'EU')],
    priceAnnualUsd: 4000,
    includedBaselinePacks: ['iso27001', 'gdpr'],
};
// ---------------------------------------------------------------------------
// CB-1: bundledPackIds for US group
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('CB-1: bundledPackIds for US group', () => {
    (0, node_test_1.it)('returns ["iso_27001"] for hipaa + US group', () => {
        strict_1.default.deepEqual((0, capability_catalog_js_1.bundledPackIds)('hipaa', US_HEALTHCARE_GROUP), ['iso_27001']);
    });
    (0, node_test_1.it)('returns ["iso_27001"] for hitech + US group', () => {
        strict_1.default.deepEqual((0, capability_catalog_js_1.bundledPackIds)('hitech', US_HEALTHCARE_GROUP), ['iso_27001']);
    });
});
// ---------------------------------------------------------------------------
// CB-2: bundledPackIds for EU group
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('CB-2: bundledPackIds for EU group', () => {
    (0, node_test_1.it)('returns ["iso_27001", "gdpr"] for eu-mdr + EU group', () => {
        strict_1.default.deepEqual((0, capability_catalog_js_1.bundledPackIds)('eu-mdr', EU_HEALTHCARE_GROUP), ['iso_27001', 'gdpr']);
    });
    (0, node_test_1.it)('returns ["iso_27001", "gdpr"] for eu_ai_act + EU group', () => {
        strict_1.default.deepEqual((0, capability_catalog_js_1.bundledPackIds)('eu_ai_act', EU_HEALTHCARE_GROUP), ['iso_27001', 'gdpr']);
    });
});
// ---------------------------------------------------------------------------
// CB-3: bundledPackIds excludes the parentPackId
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('CB-3: bundledPackIds excludes parentPackId', () => {
    (0, node_test_1.it)('excludes iso_27001 when parentPackId is iso_27001', () => {
        const result = (0, capability_catalog_js_1.bundledPackIds)('iso_27001', US_HEALTHCARE_GROUP);
        strict_1.default.equal(result.includes('iso_27001'), false);
    });
    (0, node_test_1.it)('excludes gdpr when parentPackId is gdpr in EU group', () => {
        const result = (0, capability_catalog_js_1.bundledPackIds)('gdpr', EU_HEALTHCARE_GROUP);
        strict_1.default.equal(result.includes('gdpr'), false);
        strict_1.default.equal(result.includes('iso_27001'), true);
    });
});
// ---------------------------------------------------------------------------
// CB-4: isUnlicensed — HIPAA capability passes when hipaa is licensed
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('CB-4: isUnlicensed — HIPAA capability is not unlicensed', () => {
    (0, node_test_1.it)('phi_redaction is licensed when hipaa is in licensedPacks', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('phi_redaction', ['hipaa'], US_HEALTHCARE_GROUP), false);
    });
    (0, node_test_1.it)('minimum_necessary_rule is licensed when hipaa is in licensedPacks', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('minimum_necessary_rule', ['hipaa'], US_HEALTHCARE_GROUP), false);
    });
});
// ---------------------------------------------------------------------------
// CB-5: isUnlicensed — ISO 27001 capability NOT unlicensed for US group (bundled)
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('CB-5: isUnlicensed — ISO 27001 bundled for US group', () => {
    (0, node_test_1.it)('isms_policy_gate is NOT unlicensed for US group with hipaa licensed (iso_27001 bundled)', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('isms_policy_gate', ['hipaa'], US_HEALTHCARE_GROUP), false);
    });
    (0, node_test_1.it)('access_control_policy is NOT unlicensed for US group (iso_27001 bundled)', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('access_control_policy', ['hipaa'], US_HEALTHCARE_GROUP), false);
    });
    (0, node_test_1.it)('cryptography_policy is NOT unlicensed for US group (iso_27001 bundled)', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('cryptography_policy', ['hipaa'], US_HEALTHCARE_GROUP), false);
    });
});
// ---------------------------------------------------------------------------
// CB-6: isUnlicensed — GDPR capability IS unlicensed for US group
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('CB-6: isUnlicensed — GDPR capability unlicensed for US group', () => {
    (0, node_test_1.it)('data_subject_request IS unlicensed for US group (gdpr not bundled)', () => {
        const result = (0, capability_catalog_js_1.isUnlicensed)('data_subject_request', ['hipaa'], US_HEALTHCARE_GROUP);
        strict_1.default.notEqual(result, false);
        strict_1.default.equal(typeof result, 'object');
        strict_1.default.equal(result.packId, 'gdpr');
    });
    (0, node_test_1.it)('right_to_erasure IS unlicensed for US group', () => {
        const result = (0, capability_catalog_js_1.isUnlicensed)('right_to_erasure', ['hipaa'], US_HEALTHCARE_GROUP);
        strict_1.default.notEqual(result, false);
        strict_1.default.equal(result.packId, 'gdpr');
    });
});
// ---------------------------------------------------------------------------
// CB-7: isUnlicensed — GDPR capability NOT unlicensed for EU group (bundled)
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('CB-7: isUnlicensed — GDPR capability bundled for EU group', () => {
    (0, node_test_1.it)('data_subject_request is NOT unlicensed for EU group (gdpr bundled)', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('data_subject_request', ['hipaa'], EU_HEALTHCARE_GROUP), false);
    });
    (0, node_test_1.it)('right_to_erasure is NOT unlicensed for EU group', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('right_to_erasure', ['hipaa'], EU_HEALTHCARE_GROUP), false);
    });
    (0, node_test_1.it)('consent_management is NOT unlicensed for EU group', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('consent_management', ['hipaa'], EU_HEALTHCARE_GROUP), false);
    });
});
// ---------------------------------------------------------------------------
// CB-8: isUnlicensed — base capabilities always return false
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('CB-8: isUnlicensed — base capabilities never unlicensed', () => {
    (0, node_test_1.it)('tool_use_logging (base) is never unlicensed without group', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('tool_use_logging', [], undefined), false);
    });
    (0, node_test_1.it)('tool_use_logging (base) is never unlicensed with US group', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('tool_use_logging', [], US_HEALTHCARE_GROUP), false);
    });
    (0, node_test_1.it)('audit_chain_integrity (base) is never unlicensed', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('audit_chain_integrity', [], undefined), false);
    });
    (0, node_test_1.it)('circuit_breaker (base) is never unlicensed', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('circuit_breaker', [], undefined), false);
    });
});
// ---------------------------------------------------------------------------
// CB-9: isUnlicensed — unknown capability returns false (graceful degrade)
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('CB-9: isUnlicensed — unknown capability gracefully degrades', () => {
    (0, node_test_1.it)('returns false for an unknown capability with no group', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('capability_not_in_catalog_xyz', [], undefined), false);
    });
    (0, node_test_1.it)('returns false for an unknown capability with a group', () => {
        strict_1.default.equal((0, capability_catalog_js_1.isUnlicensed)('capability_not_in_catalog_xyz', ['hipaa'], US_HEALTHCARE_GROUP), false);
    });
});
// ---------------------------------------------------------------------------
// CB-10: bundledPackIds — without group, only iso_27001 is returned
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('CB-10: bundledPackIds without group', () => {
    (0, node_test_1.it)('returns ["iso_27001"] when no group is provided', () => {
        strict_1.default.deepEqual((0, capability_catalog_js_1.bundledPackIds)('hipaa', undefined), ['iso_27001']);
    });
    (0, node_test_1.it)('does NOT return gdpr when no group is provided', () => {
        strict_1.default.equal((0, capability_catalog_js_1.bundledPackIds)('hipaa', undefined).includes('gdpr'), false);
    });
    (0, node_test_1.it)('returns empty array when parentPackId is iso_27001 and no group', () => {
        strict_1.default.deepEqual((0, capability_catalog_js_1.bundledPackIds)('iso_27001', undefined), []);
    });
});
//# sourceMappingURL=capability-catalog-bundle-licensing.test.js.map