"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 slug = `quantum-biofabrication-${Date.now()}`;
const goal = `orquestrar ${slug} com pesquisa, agente especialista, squad e skill operacional`;
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 route = runJson(['route', 'intent', goal, '--auto-create', '--min-score', '999', '--create-prefix', slug, '--limit', '3']);
assert_1.strict.equal(route.ok, true);
assert_1.strict.equal(route.autoCreate.enabled, true);
assert_1.strict.ok(route.autoCreate.created.length >= 3, 'should create agent, squad and skill drafts when coverage is insufficient');
assert_1.strict.ok(route.autoCreate.created.some((x) => x.type === 'agent'));
assert_1.strict.ok(route.autoCreate.created.some((x) => x.type === 'squad'));
assert_1.strict.ok(route.autoCreate.created.some((x) => x.type === 'skill'));
assert_1.strict.ok(route.autoCreate.created.some((x) => x.id.includes('squad')), 'slug normalization must preserve the letter u in squad');
for (const item of route.autoCreate.created) {
    assert_1.strict.ok(fs.existsSync(item.path), `created path missing: ${item.path}`);
    const body = fs.readFileSync(item.path, 'utf-8');
    assert_1.strict.ok(body.includes('source: aiobuilder-auto-route'));
    assert_1.strict.ok(body.includes(goal));
}
const strict = runJson(['catalog', 'doctor', '--strict']);
assert_1.strict.equal(strict.ok, true);
assert_1.strict.equal(strict.summary.agents.demo + strict.summary.agents.test, 0);
assert_1.strict.equal(strict.summary.squads.demo + strict.summary.squads.test, 0);
assert_1.strict.equal(strict.summary.skills.demo + strict.summary.skills.test, 0);
for (const item of route.autoCreate.created) {
    fs.rmSync(path.dirname(item.path), { recursive: true, force: true });
}
console.log('TEST_OPENLIFE_AUTO_CREATOR_ROUTING_OK');
