"use strict";
// src/test_capability_index.ts
// Validates CapabilityIndex: builds a profile over all catalog agents and ranks
// them by relevance to a free-text query (replacing tag-only substring match).
Object.defineProperty(exports, "__esModule", { value: true });
const CapabilityIndex_1 = require("./orchestrator/CapabilityIndex");
let passed = 0;
let failed = 0;
function check(label, ok, detail) {
    if (ok) {
        console.log(`  ✓ ${label}`);
        passed++;
    }
    else {
        console.error(`  ✗ ${label}${detail ? ` — ${detail}` : ''}`);
        failed++;
    }
}
async function main() {
    console.log('test_capability_index: starting\n');
    const idx = new CapabilityIndex_1.CapabilityIndex();
    console.log('[1] index builds over catalog');
    check('index size > 50', idx.size > 50, `size=${idx.size}`);
    console.log('\n[2] search returns ranked, scored results');
    const r1 = idx.search('user experience research wireframe', 5);
    check('returns at least one match', r1.length > 0);
    check('results are sorted descending by score', r1.every((a, i) => i === 0 || r1[i - 1].score >= a.score));
    check('every result has score > 0', r1.every(a => a.score > 0));
    check('every result reports matched terms', r1.every(a => a.matched.length > 0));
    console.log('\n[3] relevance — a UX query surfaces a UX agent in top results');
    const uxIds = r1.map(a => a.id).join(',');
    check('top-5 includes a ux/design agent', /ux|design|research/i.test(uxIds), `got: ${uxIds}`);
    console.log('\n[4] relevance — a security query surfaces a security agent');
    const r2 = idx.search('security vulnerability penetration testing', 5);
    check('security query returns matches', r2.length > 0);
    check('top result mentions security domain', r2.length > 0 && r2[0].score > 0);
    console.log('\n[5] empty / stopword-only query returns nothing');
    check('empty query → []', idx.search('', 5).length === 0);
    check('stopwords-only query → []', idx.search('the and for with', 5).length === 0);
    console.log('\n[6] limit is respected');
    const r3 = idx.search('strategy', 3);
    check('respects limit=3', r3.length <= 3);
    console.log('\n[7] getProfile returns a structured profile');
    if (r1.length > 0) {
        const prof = idx.getProfile(r1[0].id);
        check('getProfile non-null for a known id', prof !== null);
        if (prof) {
            check('profile has id/name/role', !!prof.id && !!prof.name && !!prof.role);
            check('profile has a weighted term map', prof.terms.size > 0);
        }
    }
    check('getProfile unknown id → null', idx.getProfile('__nope__') === null);
    console.log('\n[8] determinism — same query twice yields same ranking');
    const a = idx.search('product strategy roadmap', 5).map(x => x.id).join(',');
    const b = idx.search('product strategy roadmap', 5).map(x => x.id).join(',');
    check('stable ordering across calls', a === b, `a=${a} b=${b}`);
    console.log('');
    console.log(`Results: ${passed} passed, ${failed} failed`);
    if (failed > 0) {
        console.error('TEST_CAPABILITY_INDEX_FAIL');
        process.exit(1);
    }
    console.log('✅ test_capability_index: all checks passed');
}
main().catch(err => { console.error(err); process.exit(1); });
