"use strict";
/**
 * RED-GREEN tests for org-reputation aggregator.
 *
 * @connexum/ai-governance  Credit-agency org reputation surface
 */
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 org_reputation_1 = require("./org-reputation");
const trust_score_three_dim_1 = require("./trust-score-three-dim");
const agentDims = (c) => ({
    scope_adherence: c,
    policy_compliance: c,
    anomaly_rate: c,
    incident_history: c,
    behavioral_consistency: c,
    composite: c,
});
const operatorDims = (c) => ({
    out_of_scope_ingestion: c,
    scope_violation_by_team: c,
    scope_violation_by_data_class: c,
    human_override_frequency: c,
    composite: c,
});
const buildDims = (c) => ({
    owasp_agentic_score: c,
    hook_coverage_count: 3,
    declared_capability_class_count: 4,
    has_human_in_loop: true,
    plugin_integrity_verified: true,
    proxy_routed: true,
    composite: c,
});
function makeAgent(id, composite, signal_count) {
    return {
        agent_id: id,
        score: (0, trust_score_three_dim_1.composeThreeDimensionalScore)({
            agent_activity: agentDims(composite),
            operator_activity: operatorDims(composite),
            agent_build_structure: buildDims(composite),
        }),
        signal_count,
    };
}
(0, node_test_1.describe)('org-reputation aggregator', () => {
    (0, node_test_1.it)('empty agents -> zero reputation, low confidence', () => {
        const rep = (0, org_reputation_1.computeOrgReputation)({
            org_id: 'org-x',
            agents: [],
            computed_at: '2026-05-12T00:00:00.000Z',
        });
        assert.equal(rep.score, 0);
        assert.equal(rep.confidence, 'low');
        assert.equal(rep.agent_count, 0);
        assert.equal(rep.based_on_signal_count, 0);
    });
    (0, node_test_1.it)('single agent: reputation equals agent composite (all dims same)', () => {
        const rep = (0, org_reputation_1.computeOrgReputation)({
            org_id: 'org-x',
            agents: [makeAgent('a', 80, 50)],
            computed_at: 't',
        });
        assert.equal(rep.score, 80);
        assert.equal(rep.axis_breakdown.agent_activity, 80);
        assert.equal(rep.axis_breakdown.operator_activity, 80);
        assert.equal(rep.axis_breakdown.agent_build_structure, 80);
    });
    (0, node_test_1.it)('confidence bands: 0 low / 1-9 low / 10-99 medium / 100+ high', () => {
        const make = (signals) => (0, org_reputation_1.computeOrgReputation)({
            org_id: 'org-x',
            agents: [makeAgent('a', 80, signals)],
            computed_at: 't',
        });
        assert.equal(make(0).confidence, 'low');
        assert.equal(make(9).confidence, 'low');
        assert.equal(make(10).confidence, 'medium');
        assert.equal(make(99).confidence, 'medium');
        assert.equal(make(100).confidence, 'high');
        assert.equal(make(1000).confidence, 'high');
    });
    (0, node_test_1.it)('weighted mean: high-signal agent dominates a low-signal outlier', () => {
        const rep = (0, org_reputation_1.computeOrgReputation)({
            org_id: 'org-x',
            agents: [
                makeAgent('a-loud', 60, 1000), // big weight, score 60
                makeAgent('b-quiet', 100, 1), // tiny weight, score 100
            ],
            computed_at: 't',
        });
        // Expected ~ (60*1001 + 100*2) / 1003 ~ 60.08 -> rounds to 60.
        assert.ok(rep.score <= 65, `expected near 60, got ${rep.score}`);
        assert.ok(rep.score >= 58);
    });
    (0, node_test_1.it)('agent count + total signals reported', () => {
        const rep = (0, org_reputation_1.computeOrgReputation)({
            org_id: 'org-x',
            agents: [makeAgent('a', 80, 5), makeAgent('b', 70, 15)],
            computed_at: 't',
        });
        assert.equal(rep.agent_count, 2);
        assert.equal(rep.based_on_signal_count, 20);
        assert.equal(rep.confidence, 'medium');
    });
    (0, node_test_1.it)('axis breakdown reflects independent dimension weighting', () => {
        // Agent A: agent=90, operator=60, build=80, sig=100
        // Agent B: agent=70, operator=80, build=60, sig=100
        const rep = (0, org_reputation_1.computeOrgReputation)({
            org_id: 'org-x',
            agents: [
                {
                    agent_id: 'a',
                    signal_count: 100,
                    score: (0, trust_score_three_dim_1.composeThreeDimensionalScore)({
                        agent_activity: agentDims(90),
                        operator_activity: operatorDims(60),
                        agent_build_structure: buildDims(80),
                    }),
                },
                {
                    agent_id: 'b',
                    signal_count: 100,
                    score: (0, trust_score_three_dim_1.composeThreeDimensionalScore)({
                        agent_activity: agentDims(70),
                        operator_activity: operatorDims(80),
                        agent_build_structure: buildDims(60),
                    }),
                },
            ],
            computed_at: 't',
        });
        // Equal weights -> simple means
        assert.equal(rep.axis_breakdown.agent_activity, 80); // mean(90,70)
        assert.equal(rep.axis_breakdown.operator_activity, 70); // mean(60,80)
        assert.equal(rep.axis_breakdown.agent_build_structure, 70); // mean(80,60)
    });
    (0, node_test_1.it)('zero-signal agent still contributes weight +1 (prevents gaming via dormant agents)', () => {
        // Only zero-signal agents; without the +1, weights would be all-zero
        // and we'd divide by zero. With +1 they all get equal weight.
        const rep = (0, org_reputation_1.computeOrgReputation)({
            org_id: 'org-x',
            agents: [makeAgent('a', 100, 0), makeAgent('b', 50, 0)],
            computed_at: 't',
        });
        assert.equal(rep.score, 75); // (100 + 50) / 2
        assert.equal(rep.based_on_signal_count, 0);
        assert.equal(rep.confidence, 'low');
    });
    (0, node_test_1.it)('result is pure (same input -> same output)', () => {
        const agents = [makeAgent('a', 80, 50), makeAgent('b', 70, 30)];
        const r1 = (0, org_reputation_1.computeOrgReputation)({ org_id: 'org-x', agents, computed_at: 't' });
        const r2 = (0, org_reputation_1.computeOrgReputation)({ org_id: 'org-x', agents, computed_at: 't' });
        assert.deepEqual(r1, r2);
    });
});
//# sourceMappingURL=org-reputation.test.js.map