use anyhow::Result;
use bc_components::ARID;
use bc_envelope::Envelope;
use bc_ur::prelude::*;
mod cli_common;
use cli_common::*;
fn ensure_tags_registered() { bc_components::register_tags(); }
#[test]
#[ignore] fn test_mainline_put_get_roundtrip() -> Result<()> {
ensure_tags_registered();
let arid = ARID::new();
let envelope = Envelope::new("Test message for CLI");
let arid_ur = arid.ur_string();
let envelope_ur = envelope.ur_string();
let put_output = run_cli(&["put", &arid_ur, &envelope_ur])?;
assert!(
put_output.contains("Stored envelope") || put_output.contains("✓"),
"Put should indicate success: {}",
put_output
);
let get_output = run_cli(&["get", &arid_ur])?;
assert_eq!(
get_output, envelope_ur,
"Retrieved envelope should match original"
);
Ok(())
}
#[test]
#[ignore] fn test_mainline_write_once() -> Result<()> {
ensure_tags_registered();
let arid = ARID::new();
let envelope1 = Envelope::new("First message");
let envelope2 = Envelope::new("Second message");
let arid_ur = arid.ur_string();
let envelope1_ur = envelope1.ur_string();
let envelope2_ur = envelope2.ur_string();
run_cli(&["put", &arid_ur, &envelope1_ur])?;
run_cli_expect_error(&["put", &arid_ur, &envelope2_ur])?;
Ok(())
}
#[test]
#[ignore] fn test_mainline_get_nonexistent() -> Result<()> {
ensure_tags_registered();
let arid = ARID::new();
let arid_ur = arid.ur_string();
let result = run_cli(&["get", &arid_ur]);
assert!(result.is_err(), "Getting non-existent ARID should fail");
Ok(())
}
#[test]
#[ignore] fn test_ipfs_put_get_roundtrip() -> Result<()> {
ensure_tags_registered();
if run_cli(&["check", "--storage", "ipfs"]).is_err() {
println!("Skipping test: IPFS daemon not available");
return Ok(());
}
let arid = ARID::new();
let envelope = Envelope::new("Test message for IPFS");
let arid_ur = arid.ur_string();
let envelope_ur = envelope.ur_string();
run_cli(&["put", "--storage", "ipfs", &arid_ur, &envelope_ur])?;
let get_output = run_cli(&["get", "--storage", "ipfs", &arid_ur])?;
assert_eq!(
get_output, envelope_ur,
"Retrieved envelope should match original"
);
Ok(())
}
#[test]
#[ignore] fn test_storage_backend_isolation() -> Result<()> {
ensure_tags_registered();
let arid = ARID::new();
let envelope = Envelope::new("Backend isolation test");
let arid_ur = arid.ur_string();
let envelope_ur = envelope.ur_string();
run_cli(&["put", "--storage", "mainline", &arid_ur, &envelope_ur])?;
let result = run_cli(&["get", "--storage", "ipfs", &arid_ur]);
assert!(
result.is_err(),
"Getting from different storage backend should fail"
);
Ok(())
}