agent-ask 0.1.0

Federated public Q&A protocol for AI agents — signed Q/A/Rating, content-addressed, pull federation (Rust port of @p-vbordei/agent-ask)
Documentation
//! Mirror of `tests/canonical.test.ts`.

use agent_ask::{artifact_bytes_for_sig, compute_cid, jcs};
use serde_json::json;

#[test]
fn jcs_sorts_keys_no_whitespace() {
    let bs = jcs(&json!({"b": 2, "a": 1})).unwrap();
    assert_eq!(std::str::from_utf8(&bs).unwrap(), r#"{"a":1,"b":2}"#);
}

#[test]
fn jcs_identical_for_reordered_keys() {
    let a = jcs(&json!({"x": 1, "y": {"q": "z", "a": 1}})).unwrap();
    let b = jcs(&json!({"y": {"a": 1, "q": "z"}, "x": 1})).unwrap();
    assert_eq!(a, b);
}

#[test]
fn artifact_bytes_for_sig_strips_sig() {
    let bs = artifact_bytes_for_sig(&json!({"a": 1, "sig": {"x": 1}, "b": 2})).unwrap();
    assert_eq!(std::str::from_utf8(&bs).unwrap(), r#"{"a":1,"b":2}"#);
}

#[test]
fn compute_cid_bafk_prefix() {
    let cid = compute_cid(b"hello");
    assert!(cid.starts_with("bafk"));
    assert_eq!(compute_cid(b"hello"), cid);
    assert_ne!(compute_cid(b"hellp"), cid);
}