use cm_files::{BlobError, BlobStore, LocalBlobStore}; fn store() -> (LocalBlobStore, std::path::PathBuf) { let root = std::env::temp_dir().join(format!("tc-blobs-{}", uuid::Uuid::now_v7())); (LocalBlobStore::new(root.clone()), root) } #[tokio::test] async fn put_get_delete_round_trip() { let (store, _root) = store(); store .put("ws1/documents/agent1/report.md", b"# Q2 Report") .await .unwrap(); let bytes = store.get("ws1/documents/agent1/report.md").await.unwrap(); assert_eq!(bytes, b"# Q2 Report"); store .delete("ws1/documents/agent1/report.md") .await .unwrap(); let gone = store.get("ws1/documents/agent1/report.md").await; assert!(matches!(gone, Err(BlobError::NotFound))); } #[tokio::test] async fn nested_keys_create_directories() { let (store, _root) = store(); store.put("a/b/c/d/deep.txt", b"x").await.unwrap(); assert_eq!(store.get("a/b/c/d/deep.txt").await.unwrap(), b"x"); } #[tokio::test] async fn overwrite_replaces_content() { let (store, _root) = store(); store.put("k", b"one").await.unwrap(); store.put("k", b"two").await.unwrap(); assert_eq!(store.get("k").await.unwrap(), b"two"); } #[tokio::test] async fn path_traversal_is_rejected() { let (store, root) = store(); let escape = store.put("../outside.txt", b"nope").await; assert!(matches!(escape, Err(BlobError::InvalidKey(_)))); let sneaky = store.put("ok/../../outside.txt", b"nope").await; assert!(matches!(sneaky, Err(BlobError::InvalidKey(_)))); let absolute = store.put("/etc/passwd", b"nope").await; assert!(matches!(absolute, Err(BlobError::InvalidKey(_)))); assert!(!root.parent().unwrap().join("outside.txt").exists()); } #[tokio::test] async fn deleting_missing_blobs_is_not_found() { let (store, _root) = store(); assert!(matches!( store.delete("never-existed").await, Err(BlobError::NotFound) )); }