/**
 * 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.
 */
import { describe, it } from 'node:test';
import * as assert from 'node:assert/strict';
import { analyzeManifestRisks } from './owasp-agentic-scanner.js';
describe('analyzeManifestRisks (manifest-declared governance risks)', () => {
    it('flags disabled audit logging (HIGH)', () => {
        const f = analyzeManifestRisks({ agent_name: 'a', audit_logging: 'disabled' });
        assert.ok(f.some((x) => x.title.includes('Audit logging disabled') && x.severity === 'HIGH'));
    });
    it('flags unrestricted dangerous tools — shell_exec CRIT, network_request HIGH', () => {
        const f = 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');
    });
    it('flags wildcard network egress (HIGH)', () => {
        const f = analyzeManifestRisks({ agent_name: 'a', allowed_domains: ['*'] });
        assert.ok(f.some((x) => x.title.includes('Unrestricted network egress') && x.severity === 'HIGH'));
    });
    it('flags PHI/PII exposure when handling declares logging (CRIT)', () => {
        const f = 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'));
    });
    it('flags PHI data-class tool + disabled audit as exposure (CRIT)', () => {
        const f = 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'));
    });
    it('flags a high concurrent-action ceiling (MED)', () => {
        const f = analyzeManifestRisks({ agent_name: 'a', max_concurrent_actions: 10 });
        assert.ok(f.some((x) => x.title.includes('concurrent-action ceiling') && x.severity === 'MED'));
    });
    it('a clean manifest produces no risk findings', () => {
        const f = 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, []);
    });
    it('never throws on malformed / empty input', () => {
        assert.deepEqual(analyzeManifestRisks(null), []);
        assert.deepEqual(analyzeManifestRisks('nope'), []);
        assert.deepEqual(analyzeManifestRisks({}), []);
        assert.deepEqual(analyzeManifestRisks({ tools: 'not-an-array' }), []);
    });
});
//# sourceMappingURL=manifest-risk-analyzer.test.js.map