flexpool 0.2.0

The flexpool command line: check portfolios, scenarios and alarm journals, make secrets and tokens, probe a daemon.
//! CLI contract tests (001 US-4, 002 US-2). `check-config` is the daemon's: see flexpoold's tests.

#![allow(clippy::unwrap_used, reason = "tests fail loudly")]

use std::process::Command;

fn flexpool() -> Command {
    let mut c = Command::new(env!("CARGO_BIN_EXE_flexpool"));
    c.env_remove("FLEXPOOL_CONFIG");
    c
}

#[test]
fn version_prints_the_crate_version() {
    let out = flexpool().arg("version").output().unwrap();
    assert!(String::from_utf8_lossy(&out.stdout).contains(env!("CARGO_PKG_VERSION")));
}

#[test]
fn health_of_nothing_is_unhealthy() {
    let out = flexpool()
        .args(["health", "--url", "http://127.0.0.1:9/healthz"])
        .output()
        .unwrap();
    assert_eq!(out.status.code(), Some(1));
}

#[test]
fn scenario_run_is_deterministic_and_check_lists_problems() {
    let demo = concat!(env!("CARGO_MANIFEST_DIR"), "/../../scenarios/demo.toml");
    let a = flexpool().args(["scenario", "run", demo]).output().unwrap();
    let b = flexpool().args(["scenario", "run", demo]).output().unwrap();
    assert!(a.status.success());
    assert_eq!(a.stdout, b.stdout);
    assert!(
        String::from_utf8_lossy(&a.stdout)
            .contains("2025-10-01 12:00 +02:00  gate closed  da.gate")
    );
    let dir = tempfile::tempdir().unwrap();
    let bad = dir.path().join("bad.toml");
    std::fs::write(
        &bad,
        "name = \"x\"\nday = \"2025-02-30\"\n[market]\nsource = \"file\"\n",
    )
    .unwrap();
    let out = flexpool()
        .args(["scenario", "check"])
        .arg(&bad)
        .output()
        .unwrap();
    assert_eq!(out.status.code(), Some(2));
    let err = String::from_utf8_lossy(&out.stderr);
    assert!(
        err.contains("2 problem(s)") && err.contains("day") && err.contains("market.file"),
        "{err}"
    );
}