"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 fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const SquadAutoCreator_1 = require("./orchestrator/SquadAutoCreator");
const SubagentLifecycle_1 = require("./orchestrator/SubagentLifecycle");
function assert(condition, message) {
    if (!condition)
        throw new Error(message);
}
function cleanup(target) {
    if (fs.existsSync(target))
        fs.rmSync(target, { recursive: true, force: true });
}
async function main() {
    const root = path.join(process.cwd(), '.artifacts', 'test-orchestration-assets-lifecycle');
    const assetsDir = path.join(root, 'cloud-assets');
    const lifecycleFile = path.join(root, 'cloud-subagents.json');
    cleanup(root);
    fs.mkdirSync(root, { recursive: true });
    const creator = new SquadAutoCreator_1.SquadAutoCreator(assetsDir);
    creator.create('goal one', 'squad-test');
    creator.create('goal two', 'squad-test');
    const squadDir = path.join(assetsDir, 'squads', 'squad-test');
    assert(fs.existsSync(path.join(squadDir, 'principal-agent.json')), 'should create principal-agent.json');
    assert(fs.existsSync(path.join(squadDir, 'usage-index.json')), 'should create usage-index.json');
    assert(fs.existsSync(path.join(squadDir, 'workflow-initial.json')), 'should create workflow-initial.json');
    assert(fs.existsSync(path.join(squadDir, 'operational-note.json')), 'should create operational-note.json');
    assert(fs.existsSync(path.join(squadDir, 'versions')), 'should create versioned snapshots on repeated create');
    const lifecycle = new SubagentLifecycle_1.SubagentLifecycle(lifecycleFile);
    const item = lifecycle.create('Agent A', ['analyze']);
    const trial = lifecycle.transition(item.id, 'trial');
    assert(trial?.state === 'trial', 'should transition proposed -> trial');
    const active = lifecycle.transition(item.id, 'active');
    assert(active?.state === 'active', 'should transition trial -> active');
    const invalid = lifecycle.transition(item.id, 'proposed');
    assert(invalid === null, 'should reject invalid backward transition active -> proposed');
    const archived = lifecycle.transition(item.id, 'archived');
    assert(archived?.state === 'archived', 'should transition active -> archived');
    console.log('TEST_ORCHESTRATION_ASSETS_LIFECYCLE_OK');
}
main().catch((error) => {
    console.error(error.message || error);
    process.exit(1);
});
