cultcache-rs: pin the pulled-only unpull guard in add_backing_store with a consumer test (loaded-guard-unpinned)

A store attached after a refused load must leave the refusal reason; mutating the
guard to always demote to Unpulled makes the new test fail.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Libby 2026-11-17 01:59:27 +00:00
commit 53b13f3974

View file

@ -539,3 +539,22 @@ fn a_store_with_marked_records_and_a_tail_is_refused_and_its_cache_writes_nothin
}
assert_eq!(std::fs::read(&path).unwrap(), before);
}
// Attaching a store to a cache whose load was refused must keep the refusal: the write refusal still names why the load
// failed, not merely that the cache has not pulled. (Only a pulled cache falls back to unpulled when a store is attached.)
#[test]
fn a_store_attached_after_a_refused_load_keeps_the_refusal_reason() {
use cultcache_rs::CacheBackingStore;
use cultcache_rs::CultCacheLoadRefused;
let (_held, dir, path) = held_marked_and_clean();
let mut tailed = vector("union-surface.msgpack");
tailed.push(0xc0);
SingleFileMessagePackBackingStore::new(&path).push(&envelope("tailed", tailed)).unwrap();
let mut cache = registered();
cache.add_generic_backing_store(SingleFileMessagePackBackingStore::new(&path)).unwrap();
assert!(cache.pull_all_backing_stores().is_err());
cache.add_backing_store(SingleFileMessagePackBackingStore::new(dir.path().join("routed.cc")), [SlotUnit::TYPE]).unwrap();
let error = cache.put("new", &constructed()).unwrap_err();
let refused = error.downcast_ref::<CultCacheLoadRefused>().unwrap_or_else(|| panic!("{error:#}"));
assert!(refused.reason.contains("bytes after"), "refusal reason lost: {}", refused.reason);
}