"use 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 });
// src/test_catalog_reader.ts
const path = __importStar(require("path"));
const CatalogReader_1 = require("./cli/CatalogReader");
const ROOT = path.join(__dirname, '..');
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_catalog_reader: starting\n');
    console.log('[1] listAgentIds');
    const agents = (0, CatalogReader_1.listAgentIds)(ROOT);
    check('listAgentIds returns array', Array.isArray(agents));
    check('listAgentIds has > 0 entries', agents.length > 0, `got ${agents.length}`);
    check('entries are strings', agents.every(a => typeof a === 'string'));
    check('no test- entries', !agents.some(a => a.startsWith('test-')));
    console.log('\n[2] listSkillIds');
    const skills = (0, CatalogReader_1.listSkillIds)(ROOT);
    check('listSkillIds returns array', Array.isArray(skills));
    check('listSkillIds has > 0 entries', skills.length > 0, `got ${skills.length}`);
    console.log('\n[3] listSquadIds');
    const squads = (0, CatalogReader_1.listSquadIds)(ROOT);
    check('listSquadIds returns array', Array.isArray(squads));
    check('listSquadIds has > 0 entries', squads.length > 0, `got ${squads.length}`);
    console.log('\n[4] getEntryDetail — agent');
    const firstAgent = agents[0];
    const agentDetail = (0, CatalogReader_1.getEntryDetail)(ROOT, 'agents', firstAgent);
    check(`getEntryDetail(agents, ${firstAgent}) returns non-null`, agentDetail !== null);
    if (agentDetail) {
        check('agent detail has id', !!agentDetail.id);
        check('agent detail has name', !!agentDetail.name);
        check('agent detail has tags array', Array.isArray(agentDetail.tags));
    }
    console.log('\n[5] getEntryDetail — skill');
    const firstSkill = skills[0];
    const skillDetail = (0, CatalogReader_1.getEntryDetail)(ROOT, 'skills', firstSkill);
    check(`getEntryDetail(skills, ${firstSkill}) returns non-null`, skillDetail !== null);
    if (skillDetail) {
        check('skill detail has id', !!skillDetail.id);
        check('skill detail has name', !!skillDetail.name);
    }
    console.log('\n[6] getEntryDetail — unknown id returns null');
    const notFound = (0, CatalogReader_1.getEntryDetail)(ROOT, 'agents', '__nonexistent__');
    check('unknown id returns null', notFound === null);
    console.log('');
    console.log(`Results: ${passed} passed, ${failed} failed`);
    if (failed > 0) {
        console.error('TEST_CATALOG_READER_FAIL');
        process.exit(1);
    }
    console.log('✅ test_catalog_reader: all checks passed');
}
main().catch(err => { console.error(err); process.exit(1); });
