supercode-cli 0.4.8

supercode — a lightweight, fully-customizable AI coding agent CLI in Rust. Any model via OpenRouter; natively continues Claude Code and Codex sessions.
//! Real-binary regression coverage for fail-loud config fallback. Config is
//! intentionally tolerant at startup, but an existing file must never become
//! defaults without an actionable stderr diagnostic.

use std::path::{Path, PathBuf};
use std::process::{Command, Output, Stdio};

fn bin() -> PathBuf {
    PathBuf::from(env!("CARGO_BIN_EXE_supercode"))
}

fn fresh_home(tag: &str) -> PathBuf {
    static NONCE: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
    let dir = std::env::temp_dir().join(format!(
        "supercode-config-diagnostics-{tag}-{}-{}",
        std::process::id(),
        NONCE.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
    ));
    std::fs::create_dir_all(&dir).unwrap();
    dir
}

fn chat_eof(home: &Path) -> Output {
    Command::new(bin())
        .env("SUPERCODE_HOME", home)
        .env_remove("OPENROUTER_API_KEY")
        .env_remove("OPENAI_API_KEY")
        .env_remove("ANTHROPIC_API_KEY")
        .args([
            "--api-key",
            "x",
            "--base-url",
            "http://127.0.0.1:1",
            "--no-project-context",
            "chat",
        ])
        .stdin(Stdio::null())
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .output()
        .expect("spawn supercode")
}

fn stderr(out: &Output) -> String {
    String::from_utf8_lossy(&out.stderr).into_owned()
}

#[test]
fn malformed_user_toml_warns_before_falling_back() {
    let home = fresh_home("malformed");
    let path = home.join("config.toml");
    const SECRET: &str = "TOP_SECRET_CONFIG_VALUE";
    std::fs::write(&path, format!("model = \"{SECRET}\n[experimental]\n")).unwrap();

    let out = chat_eof(&home);
    assert!(out.status.success(), "{}", stderr(&out));
    let err = stderr(&out);
    assert!(err.contains("warning: failed to parse config"), "{err}");
    assert_eq!(
        err.matches("warning: failed to parse config").count(),
        1,
        "one malformed file must produce exactly one startup warning: {err}"
    );
    assert!(err.contains(path.to_str().unwrap()), "{err}");
    assert!(err.contains("ignoring this file"), "{err}");
    assert!(
        !err.contains(SECRET),
        "parser diagnostics must never echo config contents: {err}"
    );

    std::fs::remove_dir_all(home).ok();
}

#[test]
fn unknown_capability_module_warning_reaches_real_cli() {
    let home = fresh_home("unknown-module");
    std::fs::write(
        home.join("config.toml"),
        "[experimental]\nmodule_registry = true\n\
         [capabilities.not_a_real_module]\nenabled = true\n",
    )
    .unwrap();

    let out = chat_eof(&home);
    assert!(out.status.success(), "{}", stderr(&out));
    let err = stderr(&out);
    assert!(err.contains("warning:"), "{err}");
    assert!(err.contains("not_a_real_module"), "{err}");

    std::fs::remove_dir_all(home).ok();
}