Skip to content

test(speech-engine): cover stream text extraction and websocket wrapping - #878

Open
aniruddhaadak80 wants to merge 1 commit into
elevenlabs:mainfrom
aniruddhaadak80:test/speech-engine-extract-coverage
Open

aniruddhaadak80 wants to merge 1 commit into
elevenlabs:mainfrom
aniruddhaadak80:test/speech-engine-extract-coverage

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What changed

New tests/test_speech_engine_helpers.py (24 tests, no source changes) covering two hand-maintained Speech Engine helpers (both under .fernignore) that previously had zero direct coverage:

  • _extract_text (speech_engine/session.py): plain-string passthrough, None/scalar/unknown shapes, and every documented provider format — OpenAI Responses (response.output_text.delta), OpenAI Chat Completions (choices[].delta.content), Anthropic (content_block_delta/text_delta), Gemini (candidates[].content.parts[].text) — each in dict- and attribute-style chunks, plus non-string/missing/empty edge cases.
  • wrap_websocket / _ASGIWebSocketAdapter (speech_engine/types.py): websockets-style passthrough identity, ASGI-style wrapping, recv/send/close delegation, and TypeError for unknown styles.

Why

send_response() auto-detects LLM stream formats via _extract_text, so a provider-side field change that breaks extraction silently drops response text; FastAPI/Starlette integration depends on the adapter delegating correctly. Pinning both behaviors with unit tests (no network, no credentials) locks them against regressions. Follows the repo's test-only precedent (#850, #827).

How tested

  • pytest tests/test_speech_engine_helpers.py: 24/24 pass.
  • Full suite pytest tests/: 223 passed; the only 16 failures are pre-existing live-API tests (test_tts, test_stt, test_voices, …) failing with 401 needs_authorization because no ELEVENLABS_API_KEY is set locally — CI provides it as a secret. Untouched by this PR (new file only).
  • ruff check clean on the new file.

Add regression coverage for two untested hand-maintained helpers (both
under .fernignore): _extract_text in speech_engine/session.py across
plain strings, OpenAI Responses/Chat Completions, Anthropic, and Gemini
shapes (dict- and attribute-style chunks plus None/empty/mistyped edge
cases), and wrap_websocket/_ASGIWebSocketAdapter in
speech_engine/types.py (passthrough identity, ASGI delegation,
TypeError).
@cursor

cursor Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Test-only addition with no runtime or API behavior changes.

Overview
Adds tests/test_speech_engine_helpers.py with unit tests only—no production code changes.

The new suite pins _extract_text behavior used when streaming LLM chunks into TTS responses: passthrough/None/unknown inputs, plus OpenAI Responses, Chat Completions, Anthropic, and Gemini chunk shapes (dict and object-style), including empty or non-string edge cases.

It also covers wrap_websocket and _ASGIWebSocketAdapter: websockets-style identity passthrough, ASGI wrapping, TypeError for unsupported sockets, and async recv/send/close delegation.

Reviewed by Cursor Bugbot for commit 121f92a. Bugbot is set up for automated code reviews on this repo. Configure here.

This branch has not been deployed

No deployments
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.

1 participant