// Task 033 — install-invariant for OnboardingState seed.
//
// The installer re-reads Neo4j after seed-neo4j.sh to verify the
// OnboardingState node landed. The parser turns cypher-shell's plain-
// format output into a tri-state outcome consumed by the loud-fail
// branch in src/index.ts. These tests fence the three outcomes the
// installer logs name: present / missing / unreachable.
import test from "node:test";
import assert from "node:assert/strict";
import { classifyOnboardingReadBack } from "../onboarding-readback.js";
test("non-zero exit → unreachable, with stderr tail captured", () => {
    const outcome = classifyOnboardingReadBack({
        status: 1,
        stdout: "",
        stderr: "Connection refused: bolt://localhost:7687",
    });
    assert.equal(outcome.kind, "unreachable");
    if (outcome.kind === "unreachable") {
        assert.match(outcome.stderrTail, /Connection refused/);
    }
});
test("header row only (no match) → missing", () => {
    // cypher-shell --format plain emits the column header even when zero rows
    // matched. The seed-or-fail contract treats header-only as the loud-fail.
    const outcome = classifyOnboardingReadBack({
        status: 0,
        stdout: "currentStep\n",
        stderr: "",
    });
    assert.equal(outcome.kind, "missing");
});
test("data row present → present, currentStep relayed verbatim", () => {
    const outcome = classifyOnboardingReadBack({
        status: 0,
        stdout: "currentStep\n0\n",
        stderr: "",
    });
    assert.equal(outcome.kind, "present");
    if (outcome.kind === "present") {
        assert.equal(outcome.currentStep, "0");
    }
});
test("empty stdout + zero exit → missing (defensive: cypher-shell flushed nothing)", () => {
    const outcome = classifyOnboardingReadBack({
        status: 0,
        stdout: "",
        stderr: "",
    });
    assert.equal(outcome.kind, "missing");
});
test("trailing whitespace tolerated on present row", () => {
    const outcome = classifyOnboardingReadBack({
        status: 0,
        stdout: "currentStep\n0  \n\n",
        stderr: "",
    });
    assert.equal(outcome.kind, "present");
    if (outcome.kind === "present") {
        assert.equal(outcome.currentStep, "0");
    }
});
