Polish: tests for Phase 6c fixes + RefStore::list #84

Merged
osobh merged 1 commits from polish-store-tests into main 2026-07-14 20:09:11 +00:00
2 changed files with 92 additions and 0 deletions
Showing only changes of commit 5dd5d2d00f - Show all commits
+31
View File
@@ -655,4 +655,35 @@ mod tests {
assert_eq!(store.get(&key).await.unwrap(), Some([0xAA; 32]));
assert_eq!(store.get_stamped(&key).await.unwrap(), Some(s));
}
#[tokio::test]
async fn list_empty_when_no_refs() {
let (_tmp, store) = open();
assert!(store.list().await.unwrap().is_empty());
}
#[tokio::test]
async fn list_returns_sorted_pairs_from_both_layers() {
// Coverage for Phase 6e RefStore::list(). Legacy + stamped
// union, stamped-wins on key collision (modern writes),
// sorted by key for stable output across nodes.
let (_tmp, store) = open();
let k1 = [0x10u8; 32];
let k2 = [0x20u8; 32];
let k3 = [0x30u8; 32];
store.put(&k1, &[0xAA; 32]).await.unwrap(); // legacy-only
store.put_stamped(&k2, stamped(0xBB, 1, 1)).await.unwrap(); // stamped-only
// k3: legacy value + newer stamped value → stamped wins.
store.put(&k3, &[0xCC; 32]).await.unwrap();
store.put_stamped(&k3, stamped(0xDD, 2, 2)).await.unwrap();
let out = store.list().await.unwrap();
assert_eq!(out.len(), 3);
assert_eq!(out[0].0, k1);
assert_eq!(out[0].1, [0xAA; 32]);
assert_eq!(out[1].0, k2);
assert_eq!(out[1].1, [0xBB; 32]);
assert_eq!(out[2].0, k3);
assert_eq!(out[2].1, [0xDD; 32], "stamped wins on collision");
}
}
+61
View File
@@ -1078,4 +1078,65 @@ mod tests {
assert_eq!(store.get(k).await.unwrap(), Some([0xAA; 32]));
assert_eq!(store.get_stamped(k).await.unwrap(), Some(s));
}
#[tokio::test]
async fn list_unions_legacy_and_stamped_dedup_by_key() {
// Phase 6c fix coverage: modern pins land in tags-v2/;
// list() used to only walk tags/ → they were invisible.
// Assert list() surfaces both layers and dedupes when the
// same key exists in both.
let (_tmp, store) = open();
store.put("legacy-only", &[0x11; 32]).await.unwrap();
store.put_stamped("stamped-only", stamped_tag(0x22, 1, 1)).await.unwrap();
// Same key in both — dedup should collapse to one entry.
store.put("both", &[0x33; 32]).await.unwrap();
store.put_stamped("both", stamped_tag(0x44, 5, 5)).await.unwrap();
let out = store.list().await.unwrap();
let keys: Vec<_> = out.iter().map(|e| e.key.as_str()).collect();
assert_eq!(keys, vec!["both", "legacy-only", "stamped-only"]);
// On collision the legacy value wins (walked first, seen check
// skips the stamped one). Documents current dedup order.
let both = out.iter().find(|e| e.key == "both").unwrap();
assert!(both.value_hex.starts_with("33"), "legacy wins on key collision");
}
#[tokio::test]
async fn get_falls_through_to_stamped_when_legacy_absent() {
// Phase 6c fix coverage: pin() writes stamped; unpin/lookup
// paths need to see it via get() too.
let (_tmp, store) = open();
store.put_stamped("only-stamped", stamped_tag(0x55, 1, 1)).await.unwrap();
assert_eq!(store.get("only-stamped").await.unwrap(), Some([0x55; 32]));
}
#[tokio::test]
async fn delete_unlinks_both_layers_and_expiry_sidecar() {
// Phase 6c fix coverage: unpin only removed tags/ → stamped
// pins stayed on disk. Verify delete() clears both AND the
// TTL sidecar so a subsequent pin/pin-with-ttl round-trip
// starts clean.
let (_tmp, store) = open();
let k = "pin-with-ttl";
store.put(k, &[0x66; 32]).await.unwrap();
store.put_stamped(k, stamped_tag(0x77, 2, 2)).await.unwrap();
store.set_stamped_expiry(k, 12345).await.unwrap();
assert!(store.contains(k).await.unwrap());
assert_eq!(store.get_stamped_expiry(k).await.unwrap(), Some(12345));
assert!(store.delete(k).await.unwrap(), "returns true when anything removed");
assert!(!store.contains(k).await.unwrap());
assert_eq!(store.get(k).await.unwrap(), None);
assert_eq!(store.get_stamped(k).await.unwrap(), None);
assert_eq!(store.get_stamped_expiry(k).await.unwrap(), None);
// Second delete is a clean no-op.
assert!(!store.delete(k).await.unwrap());
}
#[tokio::test]
async fn contains_reports_stamped_only_pin() {
let (_tmp, store) = open();
assert!(!store.contains("nope").await.unwrap());
store.put_stamped("only-stamped", stamped_tag(0x88, 1, 1)).await.unwrap();
assert!(store.contains("only-stamped").await.unwrap());
}
}