"use strict";
/**
 * RED-GREEN tests for F-NEW-PRODUCT-BUILD-SCORE-DIMENSION (W1.8 of
 * F-NEW-PRODUCT-AGENT-VISIBILITY-CLUSTER-2026-05-12).
 *
 * @connexum/ai-governance  F-NEW-PRODUCT-BUILD-SCORE-DIMENSION
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = require("node:test");
const assert = __importStar(require("node:assert/strict"));
const build_structure_score_1 = require("./build-structure-score");
const owasp_agentic_scanner_1 = require("./owasp-agentic-scanner");
const capability_classes_1 = require("./capability-classes");
const base = (over = {}) => ({
    agentId: 'agent-test',
    tools: [],
    hooks: { preToolUse: true, postToolUse: true, postResponse: true },
    llmProvider: 'connexum-proxy/anthropic',
    pluginIntegrityVerified: true,
    rateLimitsConfigured: true,
    declaredApprovalGates: [],
    declaredForbiddenCapabilities: [capability_classes_1.CAPABILITY_CLASS.MCP],
    ...over,
});
(0, node_test_1.describe)('F-NEW-PRODUCT-BUILD-SCORE-DIMENSION', () => {
    (0, node_test_1.it)('clean manifest produces a near-perfect composite', () => {
        const manifest = base({
            declaredForbiddenCapabilities: [capability_classes_1.CAPABILITY_CLASS.MCP],
            declaredApprovalGates: [
                { capability: capability_classes_1.CAPABILITY_CLASS.SHELL_EXEC, reviewer: 'sre' },
            ],
        });
        const scan = (0, owasp_agentic_scanner_1.scanAgent)(manifest);
        const dims = (0, build_structure_score_1.extractBuildStructureDimensions)(manifest, scan);
        assert.equal(dims.owasp_agentic_score, 100);
        assert.equal(dims.hook_coverage_count, 3);
        assert.equal(dims.has_human_in_loop, true);
        assert.equal(dims.plugin_integrity_verified, true);
        assert.equal(dims.proxy_routed, true);
        // 2 capability classes declared (out of 7 known) caps the cap-coverage contribution.
        // Math: 100*0.35 + 100*0.20 + round(2/7*100)*0.15 + 100*0.10 + 100*0.10 + 100*0.10 = 89.
        // A manifest that declares all 7 capability classes plus has all hooks + human-in-loop
        // + plugin-verified + proxy-routed would hit 100.
        assert.ok(dims.composite >= 85, `composite should be near 100, got ${dims.composite}`);
    });
    (0, node_test_1.it)('Lethal Trifecta manifest produces a low composite', () => {
        const manifest = base({
            tools: ['WebFetch', 'Bash'],
            pluginIntegrityVerified: false,
            llmProvider: 'anthropic/claude-sonnet-4-6',
            declaredForbiddenCapabilities: [],
            declaredApprovalGates: [],
        });
        const scan = (0, owasp_agentic_scanner_1.scanAgent)(manifest);
        const dims = (0, build_structure_score_1.extractBuildStructureDimensions)(manifest, scan);
        assert.ok(dims.owasp_agentic_score < 30, `owasp score should be low, got ${dims.owasp_agentic_score}`);
        assert.equal(dims.has_human_in_loop, false);
        assert.equal(dims.plugin_integrity_verified, false);
        assert.equal(dims.proxy_routed, false);
        assert.ok(dims.composite < 50, `composite should be POOR/CRIT band, got ${dims.composite}`);
    });
    (0, node_test_1.it)('hook_coverage_count counts each wired hook', () => {
        const cases = [
            { hooks: { preToolUse: false, postToolUse: false, postResponse: false }, expected: 0 },
            { hooks: { preToolUse: true, postToolUse: false, postResponse: false }, expected: 1 },
            { hooks: { preToolUse: true, postToolUse: true, postResponse: false }, expected: 2 },
            { hooks: { preToolUse: true, postToolUse: true, postResponse: true }, expected: 3 },
        ];
        for (const c of cases) {
            const manifest = base({ hooks: c.hooks });
            const scan = (0, owasp_agentic_scanner_1.scanAgent)(manifest);
            const dims = (0, build_structure_score_1.extractBuildStructureDimensions)(manifest, scan);
            assert.equal(dims.hook_coverage_count, c.expected, `hooks=${JSON.stringify(c.hooks)}`);
        }
    });
    (0, node_test_1.it)('declared_capability_class_count merges forbids and approval gates without duplicates', () => {
        const manifest = base({
            declaredForbiddenCapabilities: [capability_classes_1.CAPABILITY_CLASS.MCP, capability_classes_1.CAPABILITY_CLASS.WEB_FETCH],
            declaredApprovalGates: [
                { capability: capability_classes_1.CAPABILITY_CLASS.WEB_FETCH, reviewer: 'sec' }, // duplicate
                { capability: capability_classes_1.CAPABILITY_CLASS.SHELL_EXEC, reviewer: 'sre' },
            ],
        });
        const scan = (0, owasp_agentic_scanner_1.scanAgent)(manifest);
        const dims = (0, build_structure_score_1.extractBuildStructureDimensions)(manifest, scan);
        assert.equal(dims.declared_capability_class_count, 3); // mcp + web-fetch + shell-exec
    });
    (0, node_test_1.it)('proxy_routed flips true only when llmProvider starts with connexum-proxy/', () => {
        const proxyManifest = base({ llmProvider: 'connexum-proxy/anthropic' });
        const directManifest = base({ llmProvider: 'anthropic/claude-sonnet-4-6' });
        const dimsP = (0, build_structure_score_1.extractBuildStructureDimensions)(proxyManifest, (0, owasp_agentic_scanner_1.scanAgent)(proxyManifest));
        const dimsD = (0, build_structure_score_1.extractBuildStructureDimensions)(directManifest, (0, owasp_agentic_scanner_1.scanAgent)(directManifest));
        assert.equal(dimsP.proxy_routed, true);
        assert.equal(dimsD.proxy_routed, false);
    });
    (0, node_test_1.it)('composite formula is reproducible from inputs alone (auditor-grade transparency)', () => {
        const manifest = base({
            tools: ['Bash'], // triggers A08
            declaredApprovalGates: [{ capability: capability_classes_1.CAPABILITY_CLASS.SHELL_EXEC, reviewer: 'sre' }],
            declaredForbiddenCapabilities: [],
        });
        const scan = (0, owasp_agentic_scanner_1.scanAgent)(manifest);
        const dims = (0, build_structure_score_1.extractBuildStructureDimensions)(manifest, scan);
        // Recompute by hand:
        //   owasp_agentic_score * 0.35   (varies by what scan returns)
        //   3/3 hooks => 100 * 0.20 = 20
        //   1 cap / 7 caps => round(14.28) * 0.15 = 2.14 -> 2 after round
        //   has_human_in_loop=true: 100 * 0.10 = 10
        //   plugin_integrity=true:  100 * 0.10 = 10
        //   proxy_routed=true:      100 * 0.10 = 10
        // total = round(owasp*0.35 + 20 + 2.14 + 10 + 10 + 10)
        const owasp = scan.buildStructureScore;
        const capCovPct = Math.round((1 / 7) * 100);
        const expected = Math.round(owasp * 0.35 + 20 + capCovPct * 0.15 + 10 + 10 + 10);
        assert.equal(dims.composite, expected);
    });
});
//# sourceMappingURL=build-structure-score.test.js.map