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);
}