use std::io::Write;
use std::process::{Command, Stdio};

#[test]
fn repl_subcommand_accepts_lines_and_exits_on_quit() {
    let mut child = Command::new(env!("CARGO_BIN_EXE_gonidium"))
        .arg("repl")
        .stdin(Stdio::piped())
        .stdout(Stdio::piped())
        .spawn()
        .expect("spawn gonidium repl");

    {
        let stdin = child.stdin.as_mut().expect("stdin");
        stdin
            .write_all(b"x: f32\nx + 1\n:q\n")
            .expect("write repl input");
    }

    let output = child.wait_with_output().expect("wait repl");
    assert!(output.status.success(), "repl should exit successfully");

    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("inputs: (none)") && stdout.contains("input x: f32"),
        "repl output should include header and input confirmation, got:\n{stdout}"
    );
    assert!(
        stdout.contains("last diag: L301") || stdout.contains("lower-implicit-promotion"),
        "repl output should include a promotion diagnostic summary, got:\n{stdout}"
    );
}
