"use strict";
// Story 20.4 (v1.7) — wiring guard: OrchestrationLoop must consume
// ConsequenceForecaster.forecastWithBrain when OPENLIFE_BRAIN_FORECAST=on.
//
// The underlying forecastWithBrain contract is covered by
// test_consequence_forecast_brain.ts. This test exists to catch the
// specific regression where the method is shipped but never reached
// (which is what happened between v1.5 and v1.6).
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"));
// __dirname at runtime is the dist/ output directory. Walk back to the
// project root and into src/ to read the actual TypeScript source.
const repoRoot = path.resolve(__dirname, '..');
const loopPath = path.join(repoRoot, 'src', 'orchestrator', 'OrchestrationLoop.ts');
const source = fs.readFileSync(loopPath, 'utf-8');
const assertions = [
    {
        name: 'forecastWithBrain referenced in OrchestrationLoop',
        check: () => source.includes('forecastWithBrain'),
    },
    {
        name: 'OPENLIFE_BRAIN_FORECAST env branch present',
        check: () => /OPENLIFE_BRAIN_FORECAST\s*===\s*['"]on['"]/.test(source),
    },
    {
        name: 'env-gated branch awaits forecastWithBrain (must be await, not sync call)',
        check: () => /await\s+this\.consequenceForecaster\.forecastWithBrain\b/.test(source),
    },
    {
        name: 'default branch still calls the heuristic forecast (backward-compat)',
        check: () => /this\.consequenceForecaster\.forecast\s*\(/.test(source),
    },
    {
        name: 'brain enrichment is surfaced into the attempt trace',
        check: () => /forecast\.brain\.overallVerdict/.test(source),
    },
    {
        name: 'companion underlying-contract test exists (test_consequence_forecast_brain)',
        check: () => fs.existsSync(path.join(repoRoot, 'src', 'test_consequence_forecast_brain.ts')),
    },
];
let failed = 0;
for (const a of assertions) {
    const ok = a.check();
    console.log(`${ok ? '✓' : '✗'} ${a.name}`);
    if (!ok)
        failed++;
}
if (failed > 0) {
    console.error(`\nforecastWithBrain wiring guard FAILED: ${failed} assertion(s) missed.`);
    process.exit(1);
}
console.log('\n_OK_ forecastWithBrain wiring guard passed (Story 20.4)');
