haematite-cli 0.21.1

The haematite command: serve a store, its door and Studio, answer MCP, query with jq, and host the store's assistant seat
Documentation
//! `haematite mcp-pass`'s arguments and the header line it writes.

use super::{header, parse};

fn words(line: &str) -> impl Iterator<Item = String> {
    line.split_whitespace()
        .map(str::to_owned)
        .collect::<Vec<_>>()
        .into_iter()
}

#[test]
fn the_header_line_is_one_json_object_carrying_the_bearer_pass() -> Result<(), serde_json::Error> {
    let line = header("pass-1")?;
    assert!(line.ends_with('\n'));
    assert_eq!(line.matches('\n').count(), 1);
    let object: serde_json::Value = serde_json::from_str(&line)?;
    assert_eq!(
        object,
        serde_json::json!({ "Authorization": "Bearer pass-1" })
    );
    Ok(())
}

#[test]
fn each_proof_is_taken_with_an_issuer_and_an_agent() {
    for line in [
        "--lys-agent https://lys.example agent-1 --credential-file /c",
        "--lys-agent https://lys.example agent-1 --key-file /k",
        "--lys-agent https://lys.example agent-1 --run-pass-env LYS_AGENT_PASS --timeout-ms 5000",
    ] {
        assert!(parse(words(line)).is_ok(), "{line}");
    }
}

#[test]
fn a_missing_or_doubled_proof_or_agent_is_refused_with_the_usage() {
    for line in [
        "",
        "--lys-agent https://lys.example agent-1",
        "--credential-file /c",
        "--lys-agent https://lys.example agent-1 --credential-file /c --key-file /k",
        "--lys-agent https://lys.example agent-1 --run-pass-env",
        "--lys-agent https://lys.example agent-1 --credential-file relative",
        "--lys-agent http://lys.example agent-1 --credential-file /c",
        "--lys-agent https://lys.example agent-1 --credential-file /c --timeout-ms 0",
        "--lys-agent https://lys.example agent-1 --credential-file /c --socket /s",
    ] {
        assert!(parse(words(line)).is_err(), "{line:?} was taken");
    }
}