feat: add test for unknown model name handling in TTS client#121
feat: add test for unknown model name handling in TTS client#121
Conversation
📝 WalkthroughWalkthroughA new unit test is added to verify that unknown TTS model names are preserved exactly as provided in HTTP request headers. The test creates a mock client scenario, invokes the TTS conversion method with a non-existent model identifier, and validates that the model string passes through unmodified to the request header. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a unit test ensuring that when a caller passes an unrecognized TTS model name, the SDK forwards it to the outbound HTTP request header unchanged (rather than validating/rejecting it).
Changes:
- Add a new unit test covering “unknown model name” behavior for
TTSClient.convert. - Assert the provided model string is used verbatim in the
headers["model"]field.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| mock_client_wrapper.request.return_value = mock_response | ||
|
|
||
| # Pass a model name that doesn't exist in the Model Literal type | ||
| tts_client.convert(text="Hello", model="speech-99-nonexistent") |
There was a problem hiding this comment.
This test passes a model value that is not part of the Model = Literal[...] type used by TTSClient.convert, which will likely fail the repo's ty check type-check job. To keep the runtime behavior test while satisfying type checking, add an explicit cast (e.g., to Any) or a targeted # type: ignore[arg-type] on the tts_client.convert(...) call; alternatively, if unknown models are intentionally supported, consider widening the model parameter type in the public API to accept str.
| tts_client.convert(text="Hello", model="speech-99-nonexistent") | |
| tts_client.convert(text="Hello", model="speech-99-nonexistent") # type: ignore[arg-type] |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unit/test_tts.py (1)
204-217: Consider adding a type ignore comment for the intentional type violation.The test intentionally passes
"speech-99-nonexistent"to a parameter typed asModel = Literal["speech-1.5", "speech-1.6", "s1"]. While the repository uses thetytype checker (configured inpyproject.toml), notype: ignorecomments exist in the codebase, and test files don't have strict type annotations. This suggests type checking may not be enforced on tests. However, adding# type: ignore[arg-type]makes the intent explicit and follows best practices for intentional type violations:Suggested fix
# Pass a model name that doesn't exist in the Model Literal type - tts_client.convert(text="Hello", model="speech-99-nonexistent") + tts_client.convert(text="Hello", model="speech-99-nonexistent") # type: ignore[arg-type]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/test_tts.py` around lines 204 - 217, The test test_convert_unknown_model_passed_through_to_header intentionally passes an out-of-Literal model to tts_client.convert; add a local type-ignore to that call (e.g., append # type: ignore[arg-type] to the tts_client.convert(...) invocation) so the intentional type violation is explicit to the type checker while keeping behavior unchanged and still asserting the header contains "speech-99-nonexistent".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/unit/test_tts.py`:
- Around line 204-217: The test
test_convert_unknown_model_passed_through_to_header intentionally passes an
out-of-Literal model to tts_client.convert; add a local type-ignore to that call
(e.g., append # type: ignore[arg-type] to the tts_client.convert(...)
invocation) so the intentional type violation is explicit to the type checker
while keeping behavior unchanged and still asserting the header contains
"speech-99-nonexistent".
Summary by CodeRabbit