Stabilize desktop transcribe tests on Windows#7796
Conversation
Greptile SummaryThis PR fixes
Confidence Score: 4/5Test-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
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 / ...]
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) |
There was a problem hiding this comment.
/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
left a comment
There was a problem hiding this comment.
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.
Summary
test_desktop_transcribe.pycan collect in a minimal Windows backend venv.utils.conversationsand router dependency stubs for Opus, pydub, voice-duration budget helpers, and subscription paywall checks.utils.chat.prerecorded_from_bytes, matching the current production import name./tmpfor 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.pyfailed at collection on missing optional/native dependencies (deepgram, thenscipyvia 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/tmpdid 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 passedpython -m black --line-length 120 --skip-string-normalization tests\unit\test_desktop_transcribe.py --checkpython -m py_compile tests\unit\test_desktop_transcribe.pygit diff --check -- backend/tests/unit/test_desktop_transcribe.py