liminal-server 0.28.9

Standalone server for the liminal messaging bus
Documentation
use super::{check_sender, validate_inbox};
use crate::agents::config::AgentsConfig;

#[test]
fn malformed_inbox_errors_never_carry_the_payload() {
    for payload in [
        b"sensitive-fixture-value".as_slice(),
        br#"{"secret":"sensitive-fixture-value"}"#.as_slice(),
    ] {
        let error = validate_inbox(&AgentsConfig::default(), payload);
        assert!(error.is_err());
        if let Err(error) = error {
            assert!(!error.to_string().contains("sensitive-fixture-value"));
        }
    }
    assert!(validate_inbox(&AgentsConfig::default(), br#"{"text":"message data"}"#).is_ok());
}

#[test]
fn inbox_bytes_are_refused_before_parsing_at_the_configured_bound() {
    let bounds = AgentsConfig {
        max_event_bytes: 4,
        ..AgentsConfig::default()
    };
    let error = validate_inbox(&bounds, b"12345");
    let refused = error.is_err_and(|error| {
        error.to_string() == "auth.lys.agents.max_event_bytes: limit 4, count 5"
    });
    assert!(refused);
}

#[test]
fn an_inbox_message_may_name_its_sender_beside_its_one_message() {
    let config = AgentsConfig::default();
    assert!(validate_inbox(&config, br#"{"text":"hello","from":"assistant"}"#).is_ok());
    assert!(validate_inbox(&config, br#"{"from":"assistant"}"#).is_err());
    assert!(validate_inbox(&config, br#"{"text":"a","command":{"name":"b"}}"#).is_err());
    assert!(validate_inbox(&config, br#"{"text":"hello","from":7}"#).is_err());
    assert!(validate_inbox(&config, br#"{"text":"hello","reply_to":"agents.x.inbox"}"#).is_err());
}

#[test]
fn the_exchange_refuses_a_sender_claim_that_is_not_the_holder_and_leaves_the_bytes() {
    // The bytes are delivered as sent (AGT-001), so the exchange checks the claim and never
    // rewrites it.
    assert!(check_sender(br#"{"text":"hello","from":"checker"}"#, Some("checker")).is_ok());
    assert!(check_sender(br#"{"text":"hello"}"#, Some("checker")).is_ok());
    assert!(
        check_sender(
            br#"{"text":"hello","from":"someone-else"}"#,
            Some("checker")
        )
        .is_err()
    );
    assert!(check_sender(br#"{"text":"hello","from":"checker"}"#, None).is_err());
}