opencode-ralph-loop-cli 0.1.0

Scaffolder CLI for OpenCode Ralph Loop plugin — one command setup
Documentation
use assert_cmd::Command;
use tempfile::TempDir;

fn cmd() -> Command {
    Command::cargo_bin("opencode-ralph-loop-cli").unwrap()
}

fn init_dir(dir: &TempDir) {
    cmd()
        .args(["init", "--path", dir.path().to_str().unwrap()])
        .assert()
        .success();
}

#[test]
fn scenario_check_clean_exit_0() {
    let dir = TempDir::new().unwrap();
    init_dir(&dir);

    cmd()
        .args(["check", "--path", dir.path().to_str().unwrap()])
        .assert()
        .success();
}

#[test]
fn scenario_8_drift_detected_nonzero_exit() {
    let dir = TempDir::new().unwrap();
    init_dir(&dir);

    let opencode = dir.path().join(".opencode");
    std::fs::write(opencode.join("plugins/ralph.ts"), b"modified content").unwrap();

    cmd()
        .args(["check", "--path", dir.path().to_str().unwrap()])
        .assert()
        .failure();
}

#[test]
fn scenario_8_drift_detected_json_modified() {
    let dir = TempDir::new().unwrap();
    init_dir(&dir);

    let opencode = dir.path().join(".opencode");
    std::fs::write(opencode.join("plugins/ralph.ts"), b"modified content").unwrap();

    let output = cmd()
        .args([
            "check",
            "--path",
            dir.path().to_str().unwrap(),
            "--output",
            "json",
            "--exit-zero",
        ])
        .output()
        .unwrap();

    let json: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
    let files = json["files"].as_array().unwrap();
    let ralph = files
        .iter()
        .find(|f| f["path"] == "plugins/ralph.ts")
        .unwrap();
    assert_eq!(ralph["action"].as_str().unwrap(), "modified");
}

#[test]
fn scenario_check_strict_exits_5_on_first_drift() {
    let dir = TempDir::new().unwrap();
    init_dir(&dir);

    let opencode = dir.path().join(".opencode");
    std::fs::write(opencode.join("plugins/ralph.ts"), b"modified content").unwrap();

    cmd()
        .args(["check", "--path", dir.path().to_str().unwrap(), "--strict"])
        .assert()
        .failure()
        .code(5);
}