liminal-cli 0.3.20

The liminal command: serve the network, maintain its stores, or serve its discovery MCP over stdio
Documentation
//! ACCESS-013 R4 through the binary on a gated exchange: a ticket whose station nobody placed
//! listens its own inbox, the exchange places the station on its identity, and a message a
//! second holder sends there reaches the ticket's channel.

use super::channel_test_support::{
    Exchange, Host, TestResult, child_result, finish_results, require,
};
use super::channel_wire_test_support::Publisher;
use liminal::protocol::Frame;
use liminal_sdk::lys_pass_credential;
use serde_json::json;

#[test]
fn access013_a_ticket_s_first_inbox_listen_places_its_station_and_receives() -> TestResult {
    let exchange = Exchange::start()?;
    let mut host = Host::start(&exchange.seat("gamma", None)?, None)?;
    let outcome = receive_on_a_placed_inbox(&exchange, &mut host);
    let closed = host.close();
    let quiet = match &closed {
        Ok((_, stderr)) => require(
            !stderr.contains("is not listened"),
            &format!("the ticket's own inbox must listen at once: {stderr}"),
        ),
        Err(_) => Ok(()),
    };
    let finished = exchange.finish();
    finish_results([outcome, quiet, child_result(closed), finished])
}

fn receive_on_a_placed_inbox(exchange: &Exchange, host: &mut Host) -> TestResult {
    host.initialize()?;
    let listened = host.tool("listen", &json!({"subject":"agents.gamma.inbox"}))?;
    require(
        listened["isError"] == false,
        &format!("a ticket's first listen on its own inbox must place its station: {listened}"),
    )?;
    let credential = lys_pass_credential(&exchange.pass("sender")?);
    let mut publisher = Publisher::connect(&exchange.address, &credential)?;
    let content = "{\"text\":\"a station placed on its own identity\"}\n";
    let answer = publisher.publish("agents.gamma.inbox", content.as_bytes().to_vec())?;
    require(
        matches!(answer, Frame::PublishAck { .. }),
        &format!("a holder granted publish on the placed inbox must be accepted: {answer:?}"),
    )?;
    exchange.pump()?;
    let notification = host.read()?;
    require(
        notification["params"]["content"] == content
            && notification["params"]["meta"]["subject"] == "agents.gamma.inbox",
        &format!("the message must reach the ticket's channel: {notification}"),
    )
}