"use strict";
/**
 * RED-GREEN tests for analyzeManifestRisks (Bug 2, 2026-06-02).
 *
 * The onboarding scan page must surface the governance risks an agent's
 * manifest.json *declares about itself* (unrestricted tools, disabled audit
 * logging, wildcard egress, PHI handling) — the "issues / missing items"
 * prompt. These are distinct from the code-based A01..A10 analyzers.
 *
 * node:test + node:assert/strict.
 */
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 owasp_agentic_scanner_1 = require("./owasp-agentic-scanner");
(0, node_test_1.describe)('analyzeManifestRisks (manifest-declared governance risks)', () => {
    (0, node_test_1.it)('flags disabled audit logging (HIGH)', () => {
        const f = (0, owasp_agentic_scanner_1.analyzeManifestRisks)({ agent_name: 'a', audit_logging: 'disabled' });
        assert.ok(f.some((x) => x.title.includes('Audit logging disabled') && x.severity === 'HIGH'));
    });
    (0, node_test_1.it)('flags unrestricted dangerous tools — shell_exec CRIT, network_request HIGH', () => {
        const f = (0, owasp_agentic_scanner_1.analyzeManifestRisks)({
            agent_name: 'a',
            tools: [
                { name: 'shell_exec', scope: 'unrestricted' },
                { name: 'network_request', scope: 'unrestricted' },
                { name: 'file_write', scope: 'filesystem_unrestricted' },
                { name: 'lookup', scope: 'read' }, // safe — not flagged
            ],
        });
        const shell = f.find((x) => x.title.includes('shell_exec'));
        const fileW = f.find((x) => x.title.includes('file_write'));
        const net = f.find((x) => x.title.includes('network_request'));
        assert.equal(shell?.severity, 'CRIT');
        assert.equal(fileW?.severity, 'CRIT');
        assert.equal(net?.severity, 'HIGH');
        assert.ok(!f.some((x) => x.title.includes('lookup')), 'read-scoped tool not flagged');
    });
    (0, node_test_1.it)('flags wildcard network egress (HIGH)', () => {
        const f = (0, owasp_agentic_scanner_1.analyzeManifestRisks)({ agent_name: 'a', allowed_domains: ['*'] });
        assert.ok(f.some((x) => x.title.includes('Unrestricted network egress') && x.severity === 'HIGH'));
    });
    (0, node_test_1.it)('flags PHI/PII exposure when handling declares logging (CRIT)', () => {
        const f = (0, owasp_agentic_scanner_1.analyzeManifestRisks)({
            agent_name: 'a',
            phi_handling: 'logs full patient details to local file',
        });
        assert.ok(f.some((x) => x.risk === 'A06-sensitive-disclosure' && x.severity === 'CRIT'));
    });
    (0, node_test_1.it)('flags PHI data-class tool + disabled audit as exposure (CRIT)', () => {
        const f = (0, owasp_agentic_scanner_1.analyzeManifestRisks)({
            agent_name: 'a',
            audit_logging: 'disabled',
            tools: [{ name: 'read_record', scope: 'read', data_class: 'PHI' }],
        });
        assert.ok(f.some((x) => x.risk === 'A06-sensitive-disclosure'));
    });
    (0, node_test_1.it)('flags a high concurrent-action ceiling (MED)', () => {
        const f = (0, owasp_agentic_scanner_1.analyzeManifestRisks)({ agent_name: 'a', max_concurrent_actions: 10 });
        assert.ok(f.some((x) => x.title.includes('concurrent-action ceiling') && x.severity === 'MED'));
    });
    (0, node_test_1.it)('a clean manifest produces no risk findings', () => {
        const f = (0, owasp_agentic_scanner_1.analyzeManifestRisks)({
            agent_name: 'safe',
            audit_logging: 'enabled',
            allowed_domains: ['api.example.com'],
            max_concurrent_actions: 2,
            tools: [{ name: 'lookup', scope: 'read', data_class: 'internal' }],
        });
        assert.deepEqual(f, []);
    });
    (0, node_test_1.it)('never throws on malformed / empty input', () => {
        assert.deepEqual((0, owasp_agentic_scanner_1.analyzeManifestRisks)(null), []);
        assert.deepEqual((0, owasp_agentic_scanner_1.analyzeManifestRisks)('nope'), []);
        assert.deepEqual((0, owasp_agentic_scanner_1.analyzeManifestRisks)({}), []);
        assert.deepEqual((0, owasp_agentic_scanner_1.analyzeManifestRisks)({ tools: 'not-an-array' }), []);
    });
});
//# sourceMappingURL=manifest-risk-analyzer.test.js.map