{"record":{"id":"15f1e4f4edd33a34","repo":"Hmbown/CodeWhale","slug":"expected-text","errorCode":null,"errorMessage":"expected text","messagePattern":"expected text","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/llm_client/mock.rs","lineNumber":599,"sourceCode":"            }],\n            model: \"mock-model\".to_string(),\n            stop_reason: Some(\"end_turn\".to_string()),\n            stop_sequence: None,\n            container: None,\n            usage: Usage::default(),\n        });\n\n        let resp = mock.create_message(empty_request()).await.unwrap();\n        assert_eq!(resp.id, \"preset\");\n    }\n\n    #[tokio::test]\n    async fn create_message_synthesizes_from_streaming_turn_when_no_message_queued() {\n        let mock = MockLlmClient::new(vec![canned::simple_text_turn(\"synthesized\")]);\n        let resp = mock.create_message(empty_request()).await.unwrap();\n        let text = match &resp.content[0] {\n            ContentBlock::Text { text, .. } => text.clone(),\n            _ => panic!(\"expected text\"),\n        };\n        assert_eq!(text, \"synthesized\");\n        assert_eq!(resp.stop_reason.as_deref(), Some(\"end_turn\"));\n    }\n\n    #[tokio::test]\n    async fn create_message_synthesizes_from_factory_turn() {\n        let mock = MockLlmClient::new(Vec::new());\n        mock.push_factory(|request| {\n            assert_eq!(request.model, \"mock-model\");\n            canned::simple_text_turn(\"from factory\")\n        });\n\n        let resp = mock.create_message(empty_request()).await.unwrap();\n        let text = match &resp.content[0] {\n            ContentBlock::Text { text, .. } => text.clone(),\n            _ => panic!(\"expected text\"),\n        };","sourceCodeStart":581,"sourceCodeEnd":617,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/llm_client/mock.rs#L581-L617","documentation":"Test panic asserting that the first content block of the synthesized response is a Text block. MockLlmClient::create_message synthesizes a response from a canned simple_text_turn when no message is queued; the test matches on resp.content[0] and panics if the block is not ContentBlock::Text.","triggerScenarios":"Calling create_message on a mock seeded with canned::simple_text_turn(\"synthesized\") when resp.content[0] holds a non-text ContentBlock (tool_use, thinking, etc.).","commonSituations":"A change to the streaming-turn synthesis ordering or ContentBlock construction inserted a non-text block first; block indexing changed.","solutions":["Print resp.content before matching to see what block type is actually first.","Fix the synthesis path so simple_text_turn produces ContentBlock::Text as the first block.","If the response legitimately starts with another block type, update the test to find the text block instead of assuming index 0."],"exampleFix":"// before\nlet text = match &resp.content[0] { ContentBlock::Text { text, .. } => text.clone(), _ => panic!(\"expected text\") };\n// after\nlet text = resp.content.iter().find_map(|b| if let ContentBlock::Text { text, .. } = b { Some(text.clone()) } else { None }).expect(\"expected text block in response\");","handlingStrategy":"type-guard","validationCode":"// verify the canned turn produces a text block before asserting\nlet resp = mock.create_message(req).await.unwrap();\nassert!(!resp.content.is_empty(), \"synthesized response has no content blocks\");","typeGuard":"fn first_text<'a>(blocks: &'a [ContentBlock]) -> Option<&'a str> { blocks.iter().find_map(|b| if let ContentBlock::Text { text, .. } = b { Some(text.as_str()) } else { None }) }","tryCatchPattern":"let text = first_text(&resp.content).expect(\"expected text block\").to_string();","preventionTips":["Do not assume content[0] is Text; scan blocks","Keep simple_text_turn producing exactly one Text block as the first element"],"tags":["rust","test-assertion","mock","content-blocks"],"backgroundTag":"unexpected-response-shape","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T06:17:15.046Z"}