Stabilize desktop migration tests on Windows#7794
Conversation
Greptile SummaryThis PR fixes three Windows-specific test failures in
Confidence Score: 5/5Safe to merge — changes are confined to the test file and address three concrete, independently-verified cross-platform failures with minimal risk of unintended side effects. All three changes are narrow, well-motivated fixes: the Redis lock stub is placed at exactly the right point in the module setup sequence; the UTF-8 encoding calls are standard cross-platform hygiene; and the get_llm module stub now correctly mirrors the function the production code actually imports. No production code is modified. No files require special attention. The sole changed file is a unit test file. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[pytest collects test file] --> B[Stub loop registers database.redis_db]
B --> C[redis_stub.try_acquire_user_platform_write_lock = MagicMock]
C --> D[sys.path.insert adds backend dir]
D --> E[import database.users succeeds - finds stub attribute]
A --> G[TestModelParity tests]
G --> H[Path.read_text with encoding=utf-8 - no Windows codec error]
A --> I[TestGenerateTitleEndpoint tests]
I --> J[ModuleType stub with get_llm = MagicMock]
J --> K[patch.dict sys.modules utils.llm.clients to stub]
K --> L[generate_session_title local import resolves to stub]
Reviews (1): Last reviewed commit: "test(backend): stabilize desktop migrati..." | Re-trigger Greptile |
| llm_clients_stub = types.ModuleType('utils.llm.clients') | ||
| llm_clients_stub.get_llm = MagicMock(return_value=mock_llm) | ||
| with patch.dict('sys.modules', {'utils.llm.clients': llm_clients_stub}): |
There was a problem hiding this comment.
The stub accepts any call (MagicMock(return_value=mock_llm)), so if production code changes from get_llm('session_titles') to get_llm('something_else'), these tests would still pass silently. Adding mock_get_llm.assert_called_once_with('session_titles') after each assertion would make the tests sensitive to the argument the production code actually passes.
There was a problem hiding this comment.
Addressed in the current head: both title-generation tests now assert mock_get_llm.assert_called_once_with('session_titles') after exercising the endpoint.
8771a6a to
9183d1f
Compare
Summary
try_acquire_user_platform_write_lockon the testdatabase.redis_dbmodule before importingdatabase.users.routers/users.pywith UTF-8 in AST parity checks so Windows default code pages do not fail on source comments/strings.utils.llm.clients.get_llmwith a module-shaped stub in title generation tests, matching the currentrouters.chat_sessions.generate_session_titleimport path.get_llmis called with the expectedsession_titlesmodel key.database/models/utilsand imported router modules before the test's import sandbox is built, then restore parent package paths so later test modules can import real package children.Why
test_desktop_migration.pyimports several production modules under a lightweight test stub environment. On a minimal Windows backend venv, collection failed whendatabase.usersimported a recently-added Redis lock helper that the test stub did not expose. After collection was fixed, the file still failed on Windows becausePath.read_text()used the locale codec and because two title tests patched an oldllm_minishape while production importsget_llm().In broader Windows collect-only runs, earlier tests can also leave stale
database.*/utils.*modules insys.modules, causing this test to reuse old stubs instead of its own import sandbox. After this test imports its target modules, the parentmodels,utils, andutils.otherpackage paths are restored so later tests are not trapped behind this file's empty stub packages.Testing
python -m pytest tests\unit\test_desktop_migration.py -q-> 91 passedpython -m pytest tests\unit --collect-only -q -x --ignore=tests\unit\test_lock_bypass_fixes.py --ignore=tests\unit\test_action_item_date_validation.py --ignore=tests\unit\test_apps_review_reply_validation.py --ignore=tests\unit\test_async_app_integrations.py --ignore=tests\unit\test_async_geocoding.py --ignore=tests\unit\test_async_http_infrastructure.py --ignore=tests\unit\test_async_webhooks.py --ignore=tests\unit\test_auth_redirect_uri.py --ignore=tests\unit\test_available_plans_resilience.py --ignore=tests\unit\test_sync_v2.py --ignore=tests\unit\test_action_item_reminder_cancel_on_complete.py --ignore=tests\unit\test_batch_upload_storage.py --ignore=tests\unit\test_daily_summary_race_condition.py --ignore=tests\unit\test_delete_account_purge_storage.py --ignore=tests\unit\test_delete_account_stripe_cancel.py-> progressed throughtest_desktop_migration.pyand stopped at independenttest_desktop_transcribe.pymissingdeepgrampython -m black --line-length 120 --skip-string-normalization tests\unit\test_desktop_migration.py --checkpython -m py_compile tests\unit\test_desktop_migration.pygit diff --check -- backend/tests/unit/test_desktop_migration.py