"use strict";
/**
 * Regression: OpenLife chat surface must not return canned/automatic replies.
 * The main ask/Gatekeeper path should invoke the configured model executor even
 * for greetings; deterministic status commands remain explicit operational paths.
 */
function assertTrue(cond, label) {
    if (!cond)
        throw new Error(`ASSERT_FAILED[${label}]`);
}
function installBrainMock(mock) {
    const brainPath = require.resolve('./orchestrator/Brain');
    const orig = require.cache[brainPath];
    require.cache[brainPath] = {
        ...orig,
        exports: {
            Brain: class {
                isAnyProviderAvailable() { return true; }
                async thinkFast(_systemPrompt, userMessage) {
                    mock.invocations += 1;
                    mock.lastUserMessage = userMessage;
                    return mock.reply;
                }
                async think(_systemPrompt, userMessage) {
                    mock.invocations += 1;
                    mock.lastUserMessage = userMessage;
                    return mock.reply;
                }
            },
        },
    };
    return () => {
        if (orig)
            require.cache[brainPath] = orig;
        else
            delete require.cache[brainPath];
    };
}
async function main() {
    process.env.OPENLIFE_OUTCOME_SIMULATION = 'off';
    const mock = { invocations: 0, reply: 'MODEL_REPLY_FROM_GPT55_PATH' };
    const restore = installBrainMock(mock);
    try {
        const { IntentClassifier } = require('./orchestrator/IntentClassifier');
        const { Gatekeeper } = require('./orchestrator/Gatekeeper');
        const classifier = new IntentClassifier();
        const gatekeeper = new Gatekeeper();
        const greeting = 'ola';
        const task = await classifier.classify(greeting);
        const response = await gatekeeper.routeTask(task, greeting, 'no-auto-test');
        assertTrue(response === 'MODEL_REPLY_FROM_GPT55_PATH', 'greeting response comes from Brain/model path');
        assertTrue(mock.invocations === 1, `Brain invoked exactly once for greeting (got ${mock.invocations})`);
        assertTrue(mock.lastUserMessage === greeting, 'original greeting passed to model');
        assertTrue(!/OpenLife online|Como posso ajudar|OPENLIFE ONLINE|Intenção desconhecida/.test(response), 'no canned chat text returned');
    }
    finally {
        restore();
    }
    console.log('TEST_NO_AUTOMATIC_MESSAGES_OK');
}
main().catch((err) => {
    console.error(err);
    process.exit(1);
});
