"use strict";
// src/test_matrix_rain.ts
// Smoke tests for the Matrix theme + rain renderer.
// - banner renders deterministic plain-text shape under stripAnsi
// - inventory panel borders align (top/bottom widths match)
// - rain.start() in non-TTY returns no-op handle (no interval leak)
// - sampleFrame() produces requested dimensions
Object.defineProperty(exports, "__esModule", { value: true });
const ChatBanner_1 = require("./cli/ChatBanner");
const MatrixRain_1 = require("./cli/MatrixRain");
const MatrixTheme_1 = require("./cli/MatrixTheme");
let failed = 0;
function check(label, condition, detail) {
    if (condition) {
        console.log(`✅ ${label}`);
    }
    else {
        console.error(`❌ ${label}${detail ? ` — ${detail}` : ''}`);
        failed++;
    }
}
// 1. Banner contains the OPENLIFE letters
{
    const plain = (0, MatrixTheme_1.stripAnsi)((0, ChatBanner_1.openlifeBanner)());
    check('banner contains OPENLIFE letters (5 rows of █)', plain.includes('██████  ██████  ███████ ███    ██ ██      ██ ███████ ███████'));
    check('banner has horizon line', plain.includes('▁'));
}
// 2. Inventory panel borders align
{
    const stats = { version: 'v1.7.12', model: 'openai-cli/gpt-5.5', sessionId: 'TEST_SESSION', cwd: '/tmp', agents: 1, squads: 2, skills: 3, mcps: 4 };
    const plain = (0, MatrixTheme_1.stripAnsi)((0, ChatBanner_1.inventoryPanel)(stats));
    const lines = plain.split('\n').filter(Boolean);
    const top = lines[0];
    const bot = lines[lines.length - 1];
    check('panel top and bottom widths match', top.length === bot.length, `top=${top.length} bot=${bot.length}`);
    check('panel shows model', plain.includes('openai-cli/gpt-5.5'));
    check('panel shows catalog counts', plain.includes('Agents (1)') && plain.includes('Skills (3)'));
}
// 3. bootOutput composes banner + panel + welcome
{
    const stats = { version: 'v1.7.12', model: 'm', sessionId: 's', cwd: '/c', agents: 0, squads: 0, skills: 0, mcps: 0 };
    const plain = (0, MatrixTheme_1.stripAnsi)((0, ChatBanner_1.bootOutput)(stats));
    check('bootOutput contains banner OPENLIFE marker', plain.includes('██████'));
    check('bootOutput contains welcome line', plain.includes('Welcome to OpenLife'));
    check('bootOutput contains divider line', plain.includes('━'));
}
// 4. Rain in non-TTY env returns no-op handle
{
    // We're running under node test runner — stdout.isTTY is false.
    const handle = (0, MatrixRain_1.startRain)({ row: 1, col: 1, width: 10, height: 4 });
    check('rain.isRunning() returns false in non-TTY', handle.isRunning() === false);
    // stop() must be safe to call without state
    handle.stop();
    check('rain.stop() in non-TTY is a no-op (no throw)', true);
}
// 5. sampleFrame produces requested dimensions
{
    const frame = (0, MatrixRain_1.sampleFrame)(10, 5);
    const rows = frame.split('\n');
    check('sampleFrame produces correct number of rows', rows.length === 5);
    // Each row is at most 10 visible chars (after stripAnsi)
    const plainRowLengths = rows.map(r => (0, MatrixTheme_1.stripAnsi)(r).length);
    check('sampleFrame rows are at most width chars', plainRowLengths.every(n => n <= 10), `lengths=${plainRowLengths.join(',')}`);
}
if (failed > 0) {
    console.error(`\n${failed} check(s) failed.`);
    process.exit(1);
}
console.log('\nTEST_MATRIX_RAIN_OK');
