car-multi 0.36.0

Multi-agent coordination patterns for Common Agent Runtime
//! Cross-platform verify-command builders for foreman tests.
//!
//! The foreman gate runs a `verify_command` **directly** as program+args
//! (`Command::new(program).args(args)` in `gate::run_verify_command`), not
//! through a shell. POSIX `true`/`false` are binaries that don't exist on
//! Windows, and `sh -c …` needs a `sh` on PATH — so fixtures build the
//! shell-neutral equivalent for the current target.
#![cfg(test)]

/// A verify command that always succeeds (exit 0).
pub(crate) fn pass() -> Vec<String> {
    if cfg!(windows) {
        vec!["cmd".into(), "/C".into(), "exit 0".into()]
    } else {
        vec!["true".into()]
    }
}

/// A verify command that always fails (exit 1).
pub(crate) fn fail() -> Vec<String> {
    if cfg!(windows) {
        vec!["cmd".into(), "/C".into(), "exit 1".into()]
    } else {
        vec!["false".into()]
    }
}

/// A verify command that succeeds iff **every** file in `files` exists in the
/// verify cwd — POSIX `test -f a && test -f b …`, cmd a chained
/// `if not exist a exit 1 & … & exit 0`.
pub(crate) fn files_exist(files: &[&str]) -> Vec<String> {
    if cfg!(windows) {
        let mut script = String::new();
        for f in files {
            // `exit` (not `exit /b`) terminates cmd /C with the code, short-
            // circuiting the `&` chain on the first missing file.
            script.push_str(&format!("if not exist {f} exit 1 & "));
        }
        script.push_str("exit 0");
        vec!["cmd".into(), "/C".into(), script]
    } else {
        let test = files
            .iter()
            .map(|f| format!("test -f {f}"))
            .collect::<Vec<_>>()
            .join(" && ");
        vec!["sh".into(), "-c".into(), test]
    }
}