haematite-cli 0.21.8

The haematite command: serve a store, its door and Studio, answer MCP, query with jq, and host the store's assistant seat
Documentation
use super::config::Harness;
use serde_json::json;
use std::os::unix::fs::PermissionsExt as _;

fn private_home() -> anyhow::Result<tempfile::TempDir> {
    Ok(tempfile::Builder::new()
        .permissions(std::fs::Permissions::from_mode(0o700))
        .tempdir()?)
}

#[test]
fn r1_rows_13_14_catalogue_and_executable_boundary() -> anyhow::Result<()> {
    for id in ["claude-code", "codex", "gemini-cli", "opencode", "pi"] {
        super::catalogue::validate(id)?;
    }
    assert!(super::catalogue::validate("cdx").is_err());
    assert!(super::catalogue::executable(std::path::Path::new("./relative")).is_err());
    assert!(super::catalogue::executable(std::path::Path::new("/tmp")).is_err());
    let executable = std::env::current_exe()?;
    assert_eq!(super::catalogue::executable(&executable)?, executable);
    Ok(())
}

#[test]
fn r1_bounds_are_positive_and_no_policy_key_is_accepted() -> anyhow::Result<()> {
    let directory = private_home()?;
    let base = json!({"id":"codex","home":directory.path(),"program":"/bin/true","args":[]});
    let harness: Harness = serde_json::from_value(base.clone())?;
    harness.validate()?;
    assert_eq!(harness.prompt_queue, 32);
    assert_eq!(harness.pending_permissions, 1024);
    for key in [
        "prompt_queue",
        "content_bytes",
        "acp_frame_bytes",
        "pending_permissions",
        "write_queue",
        "stream_queue",
        "issuer_response_bytes",
        "session_list",
        "title_chars",
    ] {
        let mut invalid = base.clone();
        invalid[key] = json!(0);
        let harness: Harness = serde_json::from_value(invalid)?;
        assert!(harness.validate().is_err(), "zero {key} accepted");
    }
    for key in ["permission", "permission_policy", "auto_approve"] {
        let mut invalid = base.clone();
        invalid[key] = json!("allow-once");
        assert!(serde_json::from_value::<Harness>(invalid).is_err());
    }
    Ok(())
}

#[test]
fn r4_channel_bounds_are_rejected_before_the_runtime_can_panic() -> anyhow::Result<()> {
    let directory = private_home()?;
    for field in ["write_queue", "stream_queue"] {
        let mut value =
            json!({"id":"codex","home":directory.path(),"program":"/bin/true","args":[]});
        value[field] = json!(usize::MAX);
        let harness: Harness = serde_json::from_value(value)?;
        let refusal = harness
            .validate()
            .err()
            .ok_or_else(|| anyhow::anyhow!("oversized {field} reached the runtime"))?;
        assert!(
            refusal.to_string().contains(field),
            "refusal did not name {field}"
        );
    }
    Ok(())
}