Stabilize sync transcription preference tests on Windows#7783
Stabilize sync transcription preference tests on Windows#7783tianmind-studio wants to merge 2 commits into
Conversation
Greptile SummaryThis PR fixes 61 failing tests in
Confidence Score: 4/5Test-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
Reviews (1): Last reviewed commit: "Stabilize sync transcription prefs tests..." | Re-trigger Greptile |
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| _opuslib = ModuleType('opuslib') | ||
| _opuslib.Decoder = MagicMock | ||
| sys.modules['opuslib'] = _opuslib |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Summary
test_sync_transcription_prefs.pyso the sync router tests run in lightweight Windows environments without Deepgram or a system Opus library.routers.syncsymbols (prerecorded,httpx.get, andsubmit_with_context) instead of stale call sites.opuslibstub from overwriting a real installed module, and make the speaker embedding stub tolerate 1D vectors.Windows reproduction
Before this change on this Windows test environment:
python -m pytest tests\unit\test_sync_transcription_prefs.py -q->61 failed, 1 warningdeepgram, systemopus) during import, plus stale patch targets from olderrouters.synccall sitesTesting
python -m pytest tests\unit\test_sync_transcription_prefs.py -q->62 passed, 2 warningspython -m black --line-length 120 --skip-string-normalization tests\unit\test_sync_transcription_prefs.py --checkpython -m py_compile tests\unit\test_sync_transcription_prefs.pygit diff --check