"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ServiceCompletionPolicy_1 = require("./orchestrator/ServiceCompletionPolicy");
const ExecutionState_1 = require("./orchestrator/ExecutionState");
function assert(condition, message) {
    if (!condition)
        throw new Error(message);
}
async function main() {
    const policy = new ServiceCompletionPolicy_1.ServiceCompletionPolicy();
    const criteria = policy.enforceCriteria(['Resultado útil']);
    assert(criteria.includes('Provisionamento concluído'), 'must enforce provisioning criterion');
    assert(criteria.includes('Operação real documentada'), 'must enforce operational criterion');
    const incomplete = (0, ExecutionState_1.createExecutionState)('t1', 'goal', 'u1');
    incomplete.plan = ['a', 'b'];
    incomplete.successCriteria = ['x'];
    const reportIncomplete = policy.evaluate(incomplete);
    assert(reportIncomplete.complete === false, 'should detect incomplete service');
    const complete = (0, ExecutionState_1.createExecutionState)('t2', 'goal', 'u1');
    complete.plan = ['analisar', 'executar', 'validar'];
    complete.successCriteria = policy.enforceCriteria(['resultado']);
    complete.attempts.push({ role: 'executor', summary: 'exec ok', status: 'success', at: new Date().toISOString(), artifactPath: '.artifacts/a.txt' });
    complete.attempts.push({ role: 'reviewer', summary: 'review ok', status: 'success', at: new Date().toISOString() });
    complete.artifacts.push('.artifacts/a.txt');
    complete.serviceEvidence = [
        { type: 'provisioning', status: 'passed', summary: 'provisioned', at: new Date().toISOString(), artifactPath: '.artifacts/provision.txt' },
        { type: 'integration', status: 'passed', summary: 'integrated', at: new Date().toISOString(), artifactPath: '.artifacts/integration.txt' },
        { type: 'e2e', status: 'passed', summary: 'e2e passed', at: new Date().toISOString(), artifactPath: '.artifacts/e2e.txt' },
        { type: 'observability', status: 'passed', summary: 'observability captured', at: new Date().toISOString(), artifactPath: '.artifacts/observability.txt' },
        { type: 'operation', status: 'passed', summary: 'operation documented', at: new Date().toISOString(), artifactPath: '.artifacts/operation.txt', command: 'openlife service run t2' },
    ];
    const reportComplete = policy.evaluate(complete);
    assert(reportComplete.complete === true, 'should pass complete service report');
    console.log('TEST_SERVICE_COMPLETION_POLICY_OK');
}
main().catch((error) => {
    console.error(error.message || error);
    process.exit(1);
});
