"use strict";
/**
 * test_doctor_sandbox_check.ts — Story 18.1 (v1.6)
 *
 * Asserts SystemDoctor's new `runtime:process-sandbox` check:
 *   1. Returns a DoctorCheck shape.
 *   2. ok=true on the current Node runner (the wrapper falls back
 *      gracefully on Node 18 and reports enforcement state honestly
 *      on Node 20+).
 *   3. detail string contains the Node major version so operators can
 *      tell at a glance whether enforcement is active.
 *   4. The check appears in runRuntimeChecks() output.
 *
 * The test spawns a real `node -e` subprocess via ProcessSandbox —
 * it's an integration-style probe but stays fast (<200ms).
 */
Object.defineProperty(exports, "__esModule", { value: true });
const SystemDoctor_1 = require("./orchestrator/SystemDoctor");
function assertTrue(cond, label) {
    if (!cond)
        throw new Error(`ASSERT_FAILED[${label}]`);
}
async function main() {
    const doctor = new SystemDoctor_1.SystemDoctor();
    const checks = await doctor.runRuntimeChecks();
    const sandboxCheck = checks.find((c) => c.name === 'runtime:process-sandbox');
    assertTrue(!!sandboxCheck, '[18.1] runtime:process-sandbox check is emitted');
    assertTrue(typeof sandboxCheck.ok === 'boolean', '[18.1] check has boolean ok');
    assertTrue(typeof sandboxCheck.detail === 'string' && sandboxCheck.detail.length > 0, '[18.1] check has non-empty detail');
    // Detail should mention the Node major version so operators see at a glance.
    assertTrue(/Node\s+\d+/.test(sandboxCheck.detail), `[18.1] detail mentions Node version (got: ${sandboxCheck.detail})`);
    // On the test runner the wrapper should at minimum spawn a child successfully —
    // graceful downgrade on Node 18 still produces ok=true. The only failure path
    // we expect here is a wrapper bug (spawn failed or enforced flag inconsistent).
    if (!sandboxCheck.ok) {
        throw new Error(`[18.1] sandbox check failed unexpectedly: ${sandboxCheck.detail}`);
    }
    console.log(`[18.1] runtime:process-sandbox = ${sandboxCheck.ok ? '✅' : '❌'} ${sandboxCheck.detail}`);
    console.log('TEST_DOCTOR_SANDBOX_CHECK_OK');
}
main().catch((err) => {
    console.error('[doctor-sandbox-check] FAILED:', err instanceof Error ? err.message : err);
    process.exit(1);
});
