From 92fb906b0720ed1e323b45ace1761c1f0afe44dc Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 26 Oct 2026 14:52:32 +0100 Subject: [PATCH] Bend stored questions through the leaf's array encoding in the read-back fault tests Co-Authored-By: Claude Sonnet 5.5 --- crates/huginn-mind/src/query.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/huginn-mind/src/query.rs b/crates/huginn-mind/src/query.rs index 8a02aa2..1237948 100644 --- a/crates/huginn-mind/src/query.rs +++ b/crates/huginn-mind/src/query.rs @@ -2220,10 +2220,12 @@ mod tests { (rows, key) } - fn rewritten(payload: &[u8], edit: impl FnOnce(&mut serde_json::Map)) -> Vec { - let mut map: serde_json::Map = rmp_serde::from_slice(payload).unwrap(); - edit(&mut map); - rmp_serde::to_vec_named(&map).unwrap() + /// The stored question, decoded, for a test to bend. + fn stored_question(row: &cultcache_rs::CultCacheEnvelope) -> eureka_pipeline::PipelineQuestion { + match D::decode(row).unwrap() { + D::Question(question) => question, + other => panic!("not a question: {other:?}"), + } } #[test] @@ -2235,9 +2237,9 @@ mod tests { #[test] fn read_back_refuses_a_field_past_its_bound() { let (rows, key) = faulted(|rows, at| { - rows[at].payload = rewritten(&rows[at].payload, |map| { - map.insert("title".into(), serde_json::Value::String("x".repeat(300))); - }); + let mut question = stored_question(&rows[at]); + question.title = "x".repeat(300).as_str().into(); + rows[at].payload = D::Question(question).prepare(&schema_cache().unwrap()).unwrap().payload; }); refused_with(rows, "no longer validates", &key); } @@ -2262,9 +2264,9 @@ mod tests { #[test] fn read_back_refuses_a_payload_that_decodes_but_was_encoded_differently() { let (rows, key) = faulted(|rows, at| { - let again = rewritten(&rows[at].payload, |_| {}); - assert_ne!(again, rows[at].payload, "the re-encoding differs, so the fault is real"); - rows[at].payload = again; + let named = rmp_serde::to_vec_named(&stored_question(&rows[at])).unwrap(); + assert_ne!(named, rows[at].payload, "the re-encoding differs, so the fault is real"); + rows[at].payload = named; }); refused_with(rows, "re-encode", &key); }