"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 });
/*
 * Story 3.6 — multi-host install docs parity regression test.
 *
 * Asserts:
 * 1. INSTALL.md mentions all three hosts (claude-code, gemini-cli, codex)
 * 2. INSTALL.md mentions `openlife init`, `openlife system setup`, `openlife system uninstall`
 * 3. INSTALL.md mentions at least one host-detection env var (CLAUDECODE, GEMINI_CONFIG_DIR, CODEX_HOME)
 * 4. README.md links to INSTALL.md
 * 5. docs/install/{claude-code,gemini-cli,codex}.md all exist
 * 6. Each per-host doc has > 500 characters (not a stub-of-a-stub)
 * 7. Each per-host doc mentions its own host name
 * 8. gemini-cli + codex docs mention `HOST_NOT_YET_SUPPORTED` or "reserved for v1.1" so the
 *    deferral is explicit and the doc cannot drift into claiming support that does not exist.
 */
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
function assert(cond, msg) {
    if (!cond)
        throw new Error(`ASSERTION_FAILED: ${msg}`);
}
const ROOT = path.resolve(__dirname, '..');
const INSTALL_MD = path.join(ROOT, 'INSTALL.md');
const README_MD = path.join(ROOT, 'README.md');
const INSTALL_DOCS_DIR = path.join(ROOT, 'docs', 'install');
function readFile(file) {
    assert(fs.existsSync(file), `${file} must exist`);
    return fs.readFileSync(file, 'utf-8');
}
function testInstallMdMentionsAllHosts() {
    const content = readFile(INSTALL_MD);
    for (const host of ['claude-code', 'gemini-cli', 'codex']) {
        assert(content.includes(host), `INSTALL.md must mention host "${host}"`);
    }
}
function testInstallMdMentionsKeyCommands() {
    const content = readFile(INSTALL_MD);
    for (const cmd of ['openlife init', 'openlife system setup', 'openlife system uninstall']) {
        assert(content.includes(cmd), `INSTALL.md must mention command "${cmd}"`);
    }
}
function testInstallMdMentionsDetectionEnvVar() {
    const content = readFile(INSTALL_MD);
    const envVars = ['CLAUDECODE', 'GEMINI_CONFIG_DIR', 'CODEX_HOME'];
    const found = envVars.filter((v) => content.includes(v));
    assert(found.length >= 1, `INSTALL.md must mention at least one host-detection env var (one of ${envVars.join(', ')}); got 0`);
}
function testReadmeLinksToInstallMd() {
    const content = readFile(README_MD);
    // Accept any of: bare link, markdown link, or relative reference
    const linkPatterns = ['INSTALL.md', '(INSTALL.md)', '[INSTALL.md]'];
    const matched = linkPatterns.some((p) => content.includes(p));
    assert(matched, 'README.md must link to INSTALL.md');
}
function testPerHostDocsExist() {
    for (const host of ['claude-code', 'gemini-cli', 'codex']) {
        const file = path.join(INSTALL_DOCS_DIR, `${host}.md`);
        assert(fs.existsSync(file), `docs/install/${host}.md must exist`);
    }
}
function testPerHostDocsSubstantive() {
    for (const host of ['claude-code', 'gemini-cli', 'codex']) {
        const file = path.join(INSTALL_DOCS_DIR, `${host}.md`);
        const content = readFile(file);
        assert(content.length > 500, `docs/install/${host}.md too short (${content.length} chars) — should be > 500`);
        assert(content.includes(host), `docs/install/${host}.md must mention its own host name "${host}"`);
    }
}
function testReservedHostsAreExplicit() {
    for (const host of ['gemini-cli', 'codex']) {
        const file = path.join(INSTALL_DOCS_DIR, `${host}.md`);
        const content = readFile(file);
        const hasDeferralMarker = content.includes('HOST_NOT_YET_SUPPORTED') ||
            /reserved for v1\.1/i.test(content);
        assert(hasDeferralMarker, `docs/install/${host}.md must explicitly mark deferral (HOST_NOT_YET_SUPPORTED or "reserved for v1.1")`);
    }
}
async function main() {
    testInstallMdMentionsAllHosts();
    testInstallMdMentionsKeyCommands();
    testInstallMdMentionsDetectionEnvVar();
    testReadmeLinksToInstallMd();
    testPerHostDocsExist();
    testPerHostDocsSubstantive();
    testReservedHostsAreExplicit();
    console.log('TEST_MULTI_HOST_DOCS_PARITY_OK');
}
main().catch((err) => {
    console.error('TEST_MULTI_HOST_DOCS_PARITY_FAIL:', err?.message || err);
    process.exit(1);
});
