Skip to content

Stabilize sync transcription preference tests on Windows#7783

Open
tianmind-studio wants to merge 2 commits into
BasedHardware:mainfrom
tianmind-studio:codex/sync-transcription-prefs-test-stability
Open

Stabilize sync transcription preference tests on Windows#7783
tianmind-studio wants to merge 2 commits into
BasedHardware:mainfrom
tianmind-studio:codex/sync-transcription-prefs-test-stability

Conversation

@tianmind-studio

@tianmind-studio tianmind-studio commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Stub import-time SDK/native audio dependencies in test_sync_transcription_prefs.py so the sync router tests run in lightweight Windows environments without Deepgram or a system Opus library.
  • Update the tests to patch the current routers.sync symbols (prerecorded, httpx.get, and submit_with_context) instead of stale call sites.
  • Keep the opuslib stub from overwriting a real installed module, and make the speaker embedding stub tolerate 1D vectors.
  • Keep speaker-ID and transcription-preference assertions focused on the router behavior under test; production code is unchanged.

Windows reproduction

Before this change on this Windows test environment:

  • python -m pytest tests\unit\test_sync_transcription_prefs.py -q -> 61 failed, 1 warning
  • failures were dominated by missing optional/native dependencies (deepgram, system opus) during import, plus stale patch targets from older routers.sync call sites

Testing

  • python -m pytest tests\unit\test_sync_transcription_prefs.py -q -> 62 passed, 2 warnings
  • python -m black --line-length 120 --skip-string-normalization tests\unit\test_sync_transcription_prefs.py --check
  • python -m py_compile tests\unit\test_sync_transcription_prefs.py
  • git diff --check

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes 61 failing tests in test_sync_transcription_prefs.py on Windows by stubbing optional native dependencies (opuslib, deepgram, pydub, vad, speaker-embedding modules) at import time, and updating stale patch targets to match the current routers.sync symbols.

  • Stub layer: Adds module-level sys.modules stubs for dependencies unavailable on Windows (no system Opus library, no Deepgram SDK), using both real logic (cosine similarity for _compare_embeddings) and MagicMock sentinels where behaviour doesn't matter.
  • Patch target corrections: All deepgram_prerecorded patches are updated to routers.sync.prerecorded, and requests patches to routers.sync.httpx, aligning with the current production import names.
  • Assertion updates: Model-selection assertions (model == 'nova-3') are replaced with return_language is True to reflect the current router contract; @patch('routers.sync.submit_with_context', MagicMock()) is added to three classes that call background-task submission.

Confidence Score: 4/5

Test-only change; production code is untouched and the updated patch targets correctly reflect the current routers.sync imports.

The patch-target and assertion updates are accurate (verified against routers/sync.py imports). The two concerns — _compare_embeddings shape assumption and opuslib's direct sys.modules assignment — are unlikely to cause failures in the current test suite but could bite future contributors adding 1D-embedding tests or running the file alongside tests that expect a real opuslib installation.

backend/tests/unit/test_sync_transcription_prefs.py — the stub setup block (lines 80–127) warrants a second look for the opuslib assignment style and the embedding shape assumption.

Important Files Changed

Filename Overview
backend/tests/unit/test_sync_transcription_prefs.py Adds Windows-compatible stubs for opuslib/deepgram/pydub/vad/speaker-embedding, updates patch targets from stale deepgram_prerecorded/requests to the current prerecorded/httpx symbols, and replaces model assertions with return_language assertions. Two minor concerns: _compare_embeddings assumes 2D array shape, and opuslib uses direct sys.modules assignment rather than setdefault.

Reviews (1): Last reviewed commit: "Stabilize sync transcription prefs tests..." | Re-trigger Greptile

Comment on lines +113 to +120
def _compare_embeddings(embedding1: np.ndarray, embedding2: np.ndarray) -> float:
if embedding1.shape[1] != embedding2.shape[1]:
return 2.0
norm_product = np.linalg.norm(embedding1) * np.linalg.norm(embedding2)
if norm_product == 0:
return 2.0
similarity = float(np.dot(embedding1.reshape(-1), embedding2.reshape(-1)) / norm_product)
return 1.0 - similarity

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 Stub assumes 2D embedding shape

The _compare_embeddings stub accesses embedding1.shape[1], which requires a 2D array. If the production compare_embeddings is ever called with a 1D embedding (512,) (e.g., from a new test or changed fixture), this raises an IndexError rather than the expected distance value. Every existing test passes (1, 512) arrays, but the boundary is invisible — a caller using np.array([0.1] * 512) instead of np.array([[0.1] * 512]) would trigger it. The guard could use np.atleast_2d or check embedding1.ndim first.

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.

Addressed in 4333bb8ba: the stub now normalizes both inputs with np.atleast_2d(...) before checking dimensions, and I added a regression test covering 1D vectors plus mismatched dimensions. Local validation: 62 passed.

Comment on lines +86 to +88
_opuslib = ModuleType('opuslib')
_opuslib.Decoder = MagicMock
sys.modules['opuslib'] = _opuslib

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 opuslib stub uses direct assignment instead of setdefault

Unlike the deepgram and pydub stubs that use sys.modules.setdefault(...), opuslib is injected with direct assignment. If opuslib is genuinely installed in the test environment (e.g., on Linux CI), this permanently replaces the real module for the rest of the pytest session, potentially breaking any subsequent test that imports and exercises real opuslib behaviour. Using sys.modules.setdefault('opuslib', _opuslib) would register the stub only when opuslib is absent, matching the pattern used for the other stubs.

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.

Addressed in 4333bb8ba: opuslib is now registered with sys.modules.setdefault('opuslib', _opuslib), matching the other optional dependency stubs so an existing real module is not overwritten. Local validation: 62 passed.

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