Thing 2.0: the schema-id fallback test reads a legacy envelope array

The first test wrote through put_envelope, which always stores a schema id, so the unwrap_or_default mutant survived. A legacy array with no schemaId reaches the fallback and kills it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-28 03:24:40 +01:00
commit 7358e9b1da

View file

@ -224,25 +224,24 @@ fn load_store_names_a_record_by_its_schema_id_when_it_has_one() {
#[test]
fn load_store_falls_back_to_the_entry_type_when_an_envelope_has_no_schema_id() {
// A store written without schema ids names a record's schema by its entry type, and the
// catalog's member rows are found under that name.
// A legacy envelope array carries no schema id and no catalog: a record's schema is then its
// entry type, which is the id a provider's state type is registered under. With no member
// rows the record is refused, and refused under that schema.
let dir = std::env::temp_dir().join(format!("thing-state-noschema-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let path = dir.join("noschema.cc");
let bytes = thing_testkit::store::bytes(|cache| {
cache.register_entry_type::<Swarm>().unwrap();
let swarm = Swarm { id: "a".into(), name: "n".into(), load: 1.0 };
let (mut envelope, _) = cache.prepare_entry("k", &swarm).unwrap();
envelope.stored_at = thing_testkit::store::PINNED_CLOCK.into();
envelope.schema_id = None;
cache.put_envelope::<Swarm>(envelope).unwrap();
});
std::fs::write(&path, bytes).unwrap();
let mut cache = thing_testkit::store::memory();
cache.register_entry_type::<Swarm>().unwrap();
let swarm = Swarm { id: "a".into(), name: "n".into(), load: 1.0 };
let (mut envelope, _) = cache.prepare_entry("k", &swarm).unwrap();
envelope.stored_at = thing_testkit::store::PINNED_CLOCK.into();
envelope.schema_id = None;
std::fs::write(&path, rmp_serde::to_vec_named(&vec![envelope]).unwrap()).unwrap();
let mut state = MemState::new();
state.load_store(&ProviderId::new(PROVIDER), &path);
let _ = std::fs::remove_dir_all(&dir);
let found = state.read(&at(SWARM_SCHEMA, "k"));
let Lookup::Present(Entry { record: Record::State { schema, value }, .. }) = found else { panic!("{found:?}") };
assert_eq!(schema, SchemaId::new(SWARM_SCHEMA));
assert_eq!(value.member("Name"), Some(&Text("n".into())));
let Lookup::Refused(refusal) = found else { panic!("{found:?}") };
assert_eq!(refusal.kind, SchemaId::new(SWARM_SCHEMA));
assert_eq!(refusal.address, at(SWARM_SCHEMA, "k"));
}