"use strict";
// src/test_semantic_routing.ts
// Phase 3: CapabilityRouter selects agents by semantic relevance over the
// catalog (via CapabilityIndex), not the hardcoded ai-builder priority set.
Object.defineProperty(exports, "__esModule", { value: true });
const CapabilityRouter_1 = require("./orchestrator/CapabilityRouter");
const AgentRegistry_1 = require("./orchestrator/AgentRegistry");
const IntentClassifier_1 = require("./orchestrator/IntentClassifier");
let passed = 0;
let failed = 0;
function check(label, ok, detail) {
    if (ok) {
        console.log(`  ✓ ${label}`);
        passed++;
    }
    else {
        console.error(`  ✗ ${label}${detail ? ` — ${detail}` : ''}`);
        failed++;
    }
}
function task(intent) {
    return { intent };
}
async function main() {
    console.log('test_semantic_routing: starting\n');
    const router = new CapabilityRouter_1.CapabilityRouter(new AgentRegistry_1.AgentRegistry());
    console.log('[1] route shape is preserved (backward compatible)');
    const r = router.route(task(IntentClassifier_1.TaskIntent.ENGINEERING_BUILD), 'build a secure auth API');
    check('capabilities is array', Array.isArray(r.capabilities));
    check('agents is array', Array.isArray(r.agents));
    check('rationale present', typeof r.rationale === 'string' && r.rationale.length > 0);
    check('mode is valid', ['single', 'review_loop', 'parallel'].includes(r.mode));
    console.log('\n[2] a rich query selects via semantic path');
    check('selection is semantic for a descriptive query', r.selection === 'semantic', `got ${r.selection}`);
    check('selected at least one agent', r.agents.length > 0);
    console.log('\n[3] different queries select different agents (not the fixed 5)');
    const sec = router.route(task(IntentClassifier_1.TaskIntent.ENGINEERING_BUILD), 'penetration testing and vulnerability assessment');
    const ux = router.route(task(IntentClassifier_1.TaskIntent.RESEARCH_ANALYSIS), 'user experience research and wireframes');
    const secIds = sec.agents.map(a => a.id).join(',');
    const uxIds = ux.agents.map(a => a.id).join(',');
    check('security query and ux query yield different agent sets', secIds !== uxIds, `sec=[${secIds}] ux=[${uxIds}]`);
    console.log('\n[4] empty input still routes (no crash, falls back)');
    const empty = router.route(task(IntentClassifier_1.TaskIntent.ENGINEERING_BUILD));
    check('empty-input route returns agents', Array.isArray(empty.agents));
    check('empty-input selection is a known fallback', ['capability', 'priority-fallback', 'semantic'].includes(empty.selection || ''));
    console.log('');
    console.log(`Results: ${passed} passed, ${failed} failed`);
    if (failed > 0) {
        console.error('TEST_SEMANTIC_ROUTING_FAIL');
        process.exit(1);
    }
    console.log('✅ test_semantic_routing: all checks passed');
}
main().catch(err => { console.error(err); process.exit(1); });
