From 688ababecc921697553067da286d61ff20957ed7 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Wed, 16 Sep 2026 12:24:30 -0600 Subject: [PATCH] test(TASK-042): prove serialize leg for old-session blocks and YAML round-trip - assert old Thinking/RedactedThinking blocks re-serialize to the original wire shape, proving both legs of old-session compat - add serde_yaml round-trip test for Vec covering the on-disk session format, including a Reasoning block with summary payload and the encrypted_content: None omitted-field case --- src/client/message.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/client/message.rs b/src/client/message.rs index 87154ff..46e6b7d 100644 --- a/src/client/message.rs +++ b/src/client/message.rs @@ -288,7 +288,7 @@ mod tests { { "type": "redacted_thinking", "data": "b64data" }, ]); - let blocks: Vec = serde_json::from_value(json).unwrap(); + let blocks: Vec = serde_json::from_value(json.clone()).unwrap(); assert!( matches!(&blocks[0], ThinkingBlock::Thinking { thinking, signature } if thinking == "hmm" && signature == "sig123") @@ -296,6 +296,7 @@ mod tests { assert!( matches!(&blocks[1], ThinkingBlock::RedactedThinking { data } if data == "b64data") ); + assert_eq!(serde_json::to_value(&blocks).unwrap(), json); } #[test] @@ -330,4 +331,31 @@ mod tests { ); assert_eq!(serde_json::to_value(&block).unwrap(), json); } + + #[test] + fn thinking_blocks_round_trip_through_yaml() { + let json = json!([ + { "type": "thinking", "thinking": "hmm", "signature": "sig123" }, + { "type": "redacted_thinking", "data": "b64data" }, + { + "type": "reasoning", + "id": "rs_1", + "summary": [{ "type": "summary_text", "text": "thinking about it" }], + "encrypted_content": "enc123", + }, + { + "type": "reasoning", + "id": "rs_2", + "summary": [], + }, + ]); + + let blocks: Vec = serde_json::from_value(json.clone()).unwrap(); + + let yaml = serde_yaml::to_string(&blocks).unwrap(); + assert!(!yaml.contains("encrypted_content: null")); + + let restored: Vec = serde_yaml::from_str(&yaml).unwrap(); + assert_eq!(serde_json::to_value(&restored).unwrap(), json); + } }