"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 });
const assert_1 = require("assert");
const child_process_1 = require("child_process");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const runJson = (args) => {
    const r = (0, child_process_1.spawnSync)('node', ['bin/openlife.js', ...args], { cwd: process.cwd(), encoding: 'utf-8' });
    assert_1.strict.equal(r.status, 0, `${args.join(' ')} failed: ${r.stderr || r.stdout}`);
    return JSON.parse(r.stdout);
};
const catalog = runJson(['catalog', 'doctor']);
assert_1.strict.equal(catalog.ok, true);
assert_1.strict.equal(catalog.warnings.length, 0, 'catalog doctor should not warn about demo/test assets after cleanup');
assert_1.strict.ok(catalog.summary.agents.total >= 300, `expected >=300 agents, got ${catalog.summary.agents.total}`);
const strictPayload = runJson(['catalog', 'doctor', '--strict']);
assert_1.strict.equal(strictPayload.strict, true);
assert_1.strict.equal(strictPayload.ok, true);
assert_1.strict.ok(catalog.summary.squads.total >= 40, `expected >=40 squads, got ${catalog.summary.squads.total}`);
const mediaDoctor = runJson(['media', 'doctor']);
assert_1.strict.equal(mediaDoctor.ok, true);
assert_1.strict.equal(mediaDoctor.checks.some((c) => c.name === 'media:prefer-gemini-default' && c.ok), true);
const agents = runJson(['agents', 'list']);
assert_1.strict.ok(agents.total >= 300, `expected runtime agents >=300, got ${agents.total}`);
assert_1.strict.ok(String(agents.source).includes('.catalog/agents'));
const swarm = runJson(['swarm', 'run', 'teste de superfície evolutiva']);
assert_1.strict.equal(swarm.ok, true);
assert_1.strict.ok(fs.existsSync(swarm.artifactPath));
assert_1.strict.deepEqual(swarm.pipeline, ['planner', 'executor', 'reviewer', 'synthesizer']);
const aiobuilder = runJson(['aiobuilder', 'validate-catalog']);
assert_1.strict.equal(aiobuilder.ok, true);
assert_1.strict.ok(aiobuilder.agents.total >= 300);
const serviceId = `surface-${Date.now()}`;
const service = runJson(['service', 'create', serviceId, '--objective', 'Teste de superfície service-centric']);
assert_1.strict.equal(service.ok, true);
const services = runJson(['service', 'list']);
assert_1.strict.ok(Array.isArray(services));
assert_1.strict.ok(services.some((s) => s.serviceId === serviceId));
const task = runJson(['task', 'run', 'validar task run', '--service', serviceId]);
assert_1.strict.equal(task.ok, true);
assert_1.strict.ok(task.taskId);
const taskPath = path.join(process.cwd(), '.artifacts', 'missions', `${task.taskId}.json`);
assert_1.strict.ok(fs.existsSync(taskPath));
console.log('TEST_OPENLIFE_EVOLUTION_SURFACE_OK');
