{"record":{"id":"6a312c8e806e79f8","repo":"Hmbown/CodeWhale","slug":"zen-chat-completions-request-should-succeed","errorCode":null,"errorMessage":"Zen Chat Completions request should succeed","messagePattern":"Zen Chat Completions request should succeed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/client.rs","lineNumber":8209,"sourceCode":"                \"object\": \"chat.completion\",\n                \"model\": \"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 = opencode_zen_client(&server, \"deepseek-v4-pro\");\n        assert_eq!(client.wire_format, WireFormat::ChatCompletions);\n        client\n            .create_message(minimal_zen_request(\"deepseek-v4-pro\"))\n            .await\n            .expect(\"Zen Chat Completions request should succeed\");\n\n        let requests = server.received_requests().await.expect(\"recorded request\");\n        assert_eq!(requests.len(), 1);\n        assert_zen_bearer_without_codex_headers(&requests[0]);\n        assert!(requests[0].headers.get(\"anthropic-version\").is_none());\n    }\n\n    #[tokio::test]\n    async fn opencode_zen_client_fails_closed_when_request_model_changes_protocol() {\n        let server = MockServer::start().await;\n        let client = opencode_zen_client(&server, \"gpt-5.5\");\n\n        let error = client\n            .create_message(minimal_zen_request(\"claude-sonnet-4-6\"))\n            .await\n            .expect_err(\"a Responses-bound client must not send a Messages model\");\n        assert!(format!(\"{error:#}\").contains(\"resolve a new model route\"));\n        assert!(","sourceCodeStart":8191,"sourceCodeEnd":8227,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/client.rs#L8191-L8227","documentation":"Test-side `.expect(\"Zen Chat Completions request should succeed\")` panic. `create_message` returned `Err` for a `WireFormat::ChatCompletions` client against the mocked `/v1/chat/completions` endpoint. The OpenAI-compatible chat completion path failed before completion — send failure, wrong route, or the mock's chat-completion JSON no longer parses into the client's response type.","triggerScenarios":"Running `opencode_zen_chat_request_uses_chat_completions_route` when the mock path no longer matches, deepseek-v4-pro no longer resolves to ChatCompletions, or the fixture (missing `created`, `object`, `choices[].finish_reason`, `usage`) fails response parsing.","commonSituations":"Tightening the ChatCompletions response deserializer; renaming models in the route table so the test model falls to another wire; edited mock fixture dropping required fields.","solutions":["Print the underlying error (`{e:?}`) to see send vs. parse failure.","Verify the mock at `POST /v1/chat/completions` returns the complete fixture including `object`, `created`, `choices` and `usage`.","Confirm `client.wire_format == WireFormat::ChatCompletions` (asserted above).","Check auth: ChatCompletions uses `authorization: Bearer ...` and must not carry `anthropic-version`."],"exampleFix":"// before\nclient\n    .create_message(minimal_zen_request(\"deepseek-v4-pro\"))\n    .await\n    .expect(\"Zen Chat Completions request should succeed\");\n// after\nclient\n    .create_message(minimal_zen_request(\"deepseek-v4-pro\"))\n    .await\n    .unwrap_or_else(|e| panic!(\"Zen Chat Completions request should succeed: {e:?}\"));","handlingStrategy":"try-catch","validationCode":"// Rust (preconditions)\nassert_eq!(client.wire_format, WireFormat::ChatCompletions);\nassert!(fixture[\"choices\"].as_array().map_or(false, |c| !c.is_empty()));\nassert!(fixture.get(\"usage\").is_some());","typeGuard":null,"tryCatchPattern":"match client.create_message(req).await {\n    Ok(msg) => assert!(!msg.content.is_empty()),\n    Err(e) => panic!(\"Chat Completions request should succeed: {e:?}\"),\n}","preventionTips":["Keep the chat-completions fixture schema-complete (object, created, choices, usage).","Keep model-to-wire routing table and test model names in sync.","Print the error chain in panics to separate transport from parse failures.","Assert Bearer auth and absence of anthropic-version on this wire."],"tags":["test-assertion","openai","chat-completions","rust"],"backgroundTag":"http-request-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}