Skip to content

Stabilize desktop transcribe tests on Windows#7796

Open
tianmind-studio wants to merge 2 commits into
BasedHardware:mainfrom
tianmind-studio:codex/windows-desktop-transcribe-test
Open

Stabilize desktop transcribe tests on Windows#7796
tianmind-studio wants to merge 2 commits into
BasedHardware:mainfrom
tianmind-studio:codex/windows-desktop-transcribe-test

Conversation

@tianmind-studio

Copy link
Copy Markdown
Contributor

Summary

  • Stub Deepgram and speaker-embedding transitive imports so test_desktop_transcribe.py can collect in a minimal Windows backend venv.
  • Use package-shaped utils.conversations and router dependency stubs for Opus, pydub, voice-duration budget helpers, and subscription paywall checks.
  • Patch utils.chat.prerecorded_from_bytes, matching the current production import name.
  • Create /tmp for the router's multipart temp-file path on Windows and align retry assertions with the current one-retry implementation.

Why

On this Windows backend venv, test_desktop_transcribe.py failed at collection on missing optional/native dependencies (deepgram, then scipy via speaker embedding). Once collection reached execution, router tests also failed because MagicMock package stubs did not match current import paths, native Opus/pydub/av-backed imports were pulled in, default MagicMock paywall checks returned truthy, and /tmp did not exist on Windows.

This keeps the desktop voice-message test self-contained without requiring native audio/Deepgram/scipy dependencies.

Testing

  • python -m pytest tests\unit\test_desktop_transcribe.py -q -> 56 passed
  • python -m black --line-length 120 --skip-string-normalization tests\unit\test_desktop_transcribe.py --check
  • python -m py_compile tests\unit\test_desktop_transcribe.py
  • git diff --check -- backend/tests/unit/test_desktop_transcribe.py

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes test_desktop_transcribe.py collection and execution failures on a minimal Windows backend venv by adding proper module stubs for optional native dependencies and aligning test assertions with the current production implementation.

  • Adds ModuleType stubs for deepgram and utils.stt.speaker_embedding (previously missing, causing collection failures), restructures utils.conversations as a real package stub instead of a flat MagicMock, and adds opuslib, pydub, utils.voice_duration_limiter, and utils.subscription stubs so router-level tests load correctly.
  • Corrects patch targets from utils.chat.deepgram_prerecorded_from_bytes to utils.chat.prerecorded_from_bytes (the actual name exported from utils/chat.py), and updates retry-count assertions from 3 → 2 to match the production attempts < 1 guard in deepgram_prerecorded_from_bytes.

Confidence Score: 4/5

Test-only change; all production code is untouched and the fixes correctly match the current production import names and retry logic.

All corrections (patch target name, retry count, package stubs) have been verified against the production files. The one minor concern is that os.makedirs('/tmp') runs at module-import time, creating a directory on disk as a side effect of collection rather than inside a fixture.

backend/tests/unit/test_desktop_transcribe.py — module-level os.makedirs call worth moving into a fixture if this pattern expands.

Important Files Changed

Filename Overview
backend/tests/unit/test_desktop_transcribe.py Stubs deepgram/speaker-embedding imports, restructures utils.conversations as a proper package, corrects patch target to prerecorded_from_bytes, aligns retry assertions from 3→2, and adds opuslib/pydub/limiter/subscription stubs for router tests. One P2: os.makedirs('/tmp') runs at collection time as a module-level side effect.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[pytest collect test_desktop_transcribe.py] --> B{Module-level stubs}
    B --> B1[deepgram ModuleType]
    B --> B2[utils.stt.speaker_embedding ModuleType]
    B --> B3[utils.conversations package ModuleType]
    B --> B4[os.makedirs /tmp]
    B1 & B2 & B3 & B4 --> C[Import utils.stt.pre_recorded]
    C --> D[TestDeepgramPrerecordedFromBytes*]
    C --> E[TestTranscribePcmBytes]
    E --> E1["Patch: utils.chat.prerecorded_from_bytes ✓"]
    C --> F[TestDeepgramPrerecordedFromBytesEdgeCases]
    F --> F1["Assert: 2 attempts ✓"]
    C --> G[_make_chat_client]
    G --> G1[_stub_router_deps]
    G1 --> G2[opuslib / pydub stubs]
    G1 --> G3[utils.voice_duration_limiter stub]
    G1 --> G4["utils.subscription stub is_trial_paywalled=False"]
    G2 & G3 & G4 --> H[exec routers/chat.py]
    H --> I[TestVoiceMessageTranscribeEndpoint / TestTranscribeStreamWebSocket / ...]
Loading

Reviews (1): Last reviewed commit: "test(backend): stabilize desktop transcr..." | Re-trigger Greptile

os.environ.setdefault('OPENAI_API_KEY', 'sk-fake-for-test')
os.environ.setdefault('DEEPGRAM_API_KEY', 'fake-for-test')
os.environ.setdefault('ENCRYPTION_SECRET', 'omi_ZwB2ZNqB2HHpMK6wStk7sTpavJiPTFg7gXUHnc4tFABPU6pZ2c2DKgehtfgi4RZv')
os.makedirs('/tmp', exist_ok=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 /tmp creation as module-level side effect

os.makedirs('/tmp', exist_ok=True) runs at collection time (module import), not inside a fixture, so it creates C:\tmp on every pytest invocation — including runs that import this file for filtering or collection only. Prefer a session-scoped fixture, or confine it to the functions that actually need the path.

@tianmind-studio tianmind-studio left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved the /tmp setup out of module import and into an autouse pytest fixture, so collection no longer creates directories on disk. Re-ran test_desktop_transcribe.py plus black, py_compile, and diff check after the update.

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