BlueGit

ict rusty-teams

fix(cards): only connector and hero cards become a legacy card

- An object with just a title (golden: text 5, title, value) stayed a card and broke card_content_text
- Needs @type MessageCard, sections or potentialAction, or hero buttons or images

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-17 · 13 days ago

Hash
a8644718d94584b97ea1d6561e7dc373cd3a927c
Parent
5a11426a
1 file changed +12 −1
crates/core/src/legacy_card.rs +12 −1
@@ -15,6 +15,16 @@ pub(crate) fn as_adaptive_card(root: &Value) -> Option<Value> {
15 15 if object.contains_key("body") || text(root, "type") == Some("AdaptiveCard") {
16 16 return None;
17 17 }
18 let connector = text(root, "@type") == Some("MessageCard")
19 || ["sections", "potentialAction"]
20 .iter()
21 .any(|key| root.get(key).is_some_and(Value::is_array));
22 let hero = ["buttons", "images"]
23 .iter()
24 .any(|key| root.get(key).is_some_and(Value::is_array));
25 if !connector && !hero {
26 return None;
27 }
18 28 let mut body = Vec::new();
19 29 if let Some(title) = text(root, "title") {
20 30 body.push(json!({"type": "TextBlock", "text": title, "weight": "Bolder", "size": "Medium", "wrap": true}));
@@ -205,7 +215,8 @@ mod tests {
205 215 }
206 216
207 217 #[test]
208 fn an_empty_object_stays_no_card() {
218 fn an_object_without_card_shape_stays_no_card() {
209 219 assert!(AdaptiveCard::parse("{}").is_none());
220 assert!(AdaptiveCard::parse(r#"{"title": "t", "value": "v"}"#).is_none());
210 221 }
211 222 }
@@ -15,6 +15,16 @@ pub(crate) fn as_adaptive_card(root: &Value) -> Option<Value> {
15 if object.contains_key("body") || text(root, "type") == Some("AdaptiveCard") {
15 if object.contains_key("body") || text(root, "type") == Some("AdaptiveCard") {
16 return None;
16 return None;
17 }
17 }
18 let connector = text(root, "@type") == Some("MessageCard")
19 || ["sections", "potentialAction"]
20 .iter()
21 .any(|key| root.get(key).is_some_and(Value::is_array));
22 let hero = ["buttons", "images"]
23 .iter()
24 .any(|key| root.get(key).is_some_and(Value::is_array));
25 if !connector && !hero {
26 return None;
27 }
18 let mut body = Vec::new();
28 let mut body = Vec::new();
19 if let Some(title) = text(root, "title") {
29 if let Some(title) = text(root, "title") {
20 body.push(json!({"type": "TextBlock", "text": title, "weight": "Bolder", "size": "Medium", "wrap": true}));
30 body.push(json!({"type": "TextBlock", "text": title, "weight": "Bolder", "size": "Medium", "wrap": true}));
@@ -205,7 +215,8 @@ mod tests {
205 }
215 }
206
216
207 #[test]
217 #[test]
208 fn an_empty_object_stays_no_card() {
218 fn an_object_without_card_shape_stays_no_card() {
209 assert!(AdaptiveCard::parse("{}").is_none());
219 assert!(AdaptiveCard::parse("{}").is_none());
220 assert!(AdaptiveCard::parse(r#"{"title": "t", "value": "v"}"#).is_none());
210 }
221 }
211}
222}