haematite-cli 0.21.0

The haematite command: serve a store, its door and Studio, answer MCP, query with jq, and host the store's assistant seat
use super::refused_by_store;
use crate::client::Refusal;

type TestResult = Result<(), Box<dyn std::error::Error>>;

#[test]
fn store_refusals_carry_http_status_and_retry_advice() -> TestResult {
    for (code, status) in [
        ("busy", 503),
        ("storage_unavailable", 503),
        ("lys_could_not_be_asked", 503),
        ("permission_refused", 403),
        ("discard_access_refused", 403),
        ("counts_access_refused", 403),
        ("embed_rewalk_access_refused", 403),
        ("branch_missing", 404),
        ("collection_missing", 404),
        ("document_missing", 404),
        ("branch_unknown", 404),
        ("relation_missing", 404),
        ("counts_branch_missing", 404),
        ("invalid_params", 400),
        ("vector_dimension_missing", 400),
    ] {
        let refused = Refusal {
            code: code.to_owned(),
            message: "fixture refusal".to_owned(),
            path: Some("/branch".to_owned()),
            verified: None,
        };
        let mut bytes = Vec::new();
        refused_by_store(&refused).write(&mut bytes)?;
        let text = String::from_utf8(bytes)?;
        assert!(
            text.starts_with(&format!("HTTP/1.1 {status} ")),
            "{code}: {text}"
        );
        assert_eq!(
            text.contains("Retry-After: 1"),
            status == 503,
            "{code}: {text}"
        );
        assert!(text.contains("fixture refusal"));
        assert!(text.contains("/branch"));
    }
    Ok(())
}