{"record":{"id":"a7dd3f45e9753b2a","repo":"Hmbown/CodeWhale","slug":"codewhale-chat-request-should-succeed","errorCode":null,"errorMessage":"Codewhale chat request should succeed","messagePattern":"Codewhale chat request should succeed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/client.rs","lineNumber":7804,"sourceCode":"                \"object\": \"chat.completion\",\n                \"model\": \"deepseek/deepseek-v4-pro\",\n                \"choices\": [{\n                    \"index\": 0,\n                    \"message\": {\"role\": \"assistant\", \"content\": \"ok\"},\n                    \"finish_reason\": \"stop\"\n                }],\n                \"usage\": {\"prompt_tokens\": 1, \"completion_tokens\": 1, \"total_tokens\": 2}\n            })))\n            .expect(1)\n            .mount(&server)\n            .await;\n\n        let client = codewhale_client(&server, \"deepseek/deepseek-v4-pro\");\n        assert_eq!(client.wire_format, WireFormat::ChatCompletions);\n        client\n            .create_message(minimal_zen_request(\"deepseek/deepseek-v4-pro\"))\n            .await\n            .expect(\"Codewhale chat request should succeed\");\n\n        let requests = server.received_requests().await.expect(\"recorded request\");\n        assert_eq!(requests.len(), 1);\n        assert_codewhale_bearer(&requests[0]);\n        let body: Value = serde_json::from_slice(&requests[0].body).expect(\"chat JSON body\");\n        // Model ids reach the account API exactly as its catalog returns them.\n        assert_eq!(\n            body.get(\"model\").and_then(Value::as_str),\n            Some(\"deepseek/deepseek-v4-pro\")\n        );\n    }\n\n    #[tokio::test]\n    async fn codewhale_messages_request_carries_the_account_bearer_not_x_api_key() {\n        let server = MockServer::start().await;\n        Mock::given(method(\"POST\"))\n            .and(path(\"/v1/messages\"))\n            .respond_with(ResponseTemplate::new(200).set_body_json(json!({","sourceCodeStart":7786,"sourceCodeEnd":7822,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/client.rs#L7786-L7822","documentation":"This .expect(\"Codewhale chat request should succeed\") is in crates/tui/src/client.rs:7804. It unwraps create_message() on a CodewhaleClient configured for WireFormat::ChatCompletions against a wiremock server. It panics when the chat-completions request fails — transport error, unexpected status, or response body the client can't parse into a message.","triggerScenarios":"Calling client.create_message(minimal_zen_request(...)) where the mounted mock route for ChatCompletions is missing/returns non-2xx or a body that fails deserialization; auth mismatch (the test requires the account key as Authorization: Bearer, never x-api-key) causing a mocked 401; wrong model id in the request path/body.","commonSituations":"Changing Codewhale's auth header from Bearer to x-api-key so the mock's auth guard rejects it; altering the ChatCompletions request/response schema; pointing the client at an unmocked URL path after a base-URL refactor.","solutions":["Inspect the panic payload: a status error names the code; a serde error names the field that no longer matches.","Check the mock: it must accept the model \"deepseek/deepseek-v4-pro\" and return a valid chat-completions JSON body.","Verify assert_codewhale_bearer's contract — Authorization: Bearer with the account key, never x-api-key — matches what the client now sends.","If the wire schema intentionally changed, update both the client mapping and this test's mock/response fixture together."],"exampleFix":"// before\nclient\n    .create_message(minimal_zen_request(\"deepseek/deepseek-v4-pro\"))\n    .await\n    .expect(\"Codewhale chat request should succeed\");\n// after\nclient\n    .create_message(minimal_zen_request(\"deepseek/deepseek-v4-pro\"))\n    .await\n    .unwrap_or_else(|e| panic!(\"Codewhale chat request should succeed: {e:?}\"));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// log the failure detail instead of a bare expect\nmatch client.create_message(minimal_zen_request(model)).await {\n    Ok(msg) => { /* assertions */ }\n    Err(e) => panic!(\"chat request failed: {e:?}\"),\n}","preventionTips":["Keep the account key on Authorization: Bearer; never send it as x-api-key on either protocol the account API serves.","Mirror the ChatCompletions request/response schema in the mock fixture whenever the wire types change.","After base-URL refactors, confirm the client path still matches the mounted wiremock route."],"tags":["rust","test","http","chat-completions"],"backgroundTag":"api-request-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}