use std::process::Command;

#[test]
fn module_f_cli_rejects_zero_workers() {
    let binary = env!("CARGO_BIN_EXE_tracer-bullet");
    let output = Command::new(binary)
        .args([
            "module-f-serve",
            "--listen-addr",
            "127.0.0.1:18081",
            "--workers",
            "0",
            "--target-path",
            "/tmp/module-f-cli-zero-workers",
            "--allow-file-fallback",
        ])
        .output()
        .expect("failed to run module-f command");

    assert!(
        !output.status.success(),
        "module-f should reject zero workers"
    );
    let stderr = String::from_utf8_lossy(&output.stderr);
    assert!(
        stderr.contains("workers must be > 0"),
        "stderr was: {stderr}"
    );
}

#[test]
fn module_f_cli_rejects_bad_listen_addr() {
    let binary = env!("CARGO_BIN_EXE_tracer-bullet");
    let output = Command::new(binary)
        .args([
            "module-f-serve",
            "--listen-addr",
            "not-an-addr",
            "--workers",
            "1",
            "--target-path",
            "/tmp/module-f-cli-bad-addr",
            "--allow-file-fallback",
        ])
        .output()
        .expect("failed to run module-f command");

    assert!(
        !output.status.success(),
        "module-f should reject invalid listen addr"
    );
    let stderr = String::from_utf8_lossy(&output.stderr);
    assert!(
        stderr.contains("invalid listen_addr"),
        "stderr was: {stderr}"
    );
}
