Skip to content

feat: add test for unknown model name handling in TTS client#121

Open
twangodev wants to merge 1 commit intomainfrom
feat/test-unknown-model
Open

feat: add test for unknown model name handling in TTS client#121
twangodev wants to merge 1 commit intomainfrom
feat/test-unknown-model

Conversation

@twangodev
Copy link
Collaborator

@twangodev twangodev commented Mar 6, 2026

Summary by CodeRabbit

  • Tests
    • Added unit test to verify that unknown model names are correctly preserved in request headers, ensuring robustness in model handling edge cases.

Copilot AI review requested due to automatic review settings March 6, 2026 03:35
@coderabbitai
Copy link

coderabbitai bot commented Mar 6, 2026

📝 Walkthrough

Walkthrough

A 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

Cohort / File(s) Summary
TTS Client Test Coverage
tests/unit/test_tts.py
Added unit test test_convert_unknown_model_passed_through_to_header to verify that unknown model identifiers are passed through unchanged to HTTP request headers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A test hops into the fold,
Checking models both old and new,
Unknown strings stay true and bold,
In headers they travel right through!
Quality whiskers twitch with glee. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a test for unknown model name handling in the TTS client, which matches the new test method introduced.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/test-unknown-model

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
tts_client.convert(text="Hello", model="speech-99-nonexistent")
tts_client.convert(text="Hello", model="speech-99-nonexistent") # type: ignore[arg-type]

Copilot uses AI. Check for mistakes.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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 as Model = Literal["speech-1.5", "speech-1.6", "s1"]. While the repository uses the ty type checker (configured in pyproject.toml), no type: ignore comments 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".

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7531081c-b85a-41a2-a294-7cded181feac

📥 Commits

Reviewing files that changed from the base of the PR and between dd251bf and 6f7db02.

📒 Files selected for processing (1)
  • tests/unit/test_tts.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants