From b40222385aa1a636c33c7ef41d6017942e76c045 Mon Sep 17 00:00:00 2001 From: Cryptopoly <31970407+cryptopoly@users.noreply.github.com> Date: Sat, 2 May 2026 13:31:24 +0100 Subject: [PATCH] Pin sys.platform to win32 in legacy-Tauri-extras test test_legacy_tauri_app_data_extras_are_import_candidates patched LOCALAPPDATA but not sys.platform. _user_data_base() in backend_service/runtime_paths.py only reads LOCALAPPDATA on sys.platform == 'win32'; on macOS dev boxes and the ubuntu-latest CI runner that branch is skipped, so the helper looks in the host's real ~/Library/Application Support or ~/.local/share rather than the tempdir the test mkdir'd into. The assertion then fails because the legacy candidate path resolved against the real user-data base doesn't match the one the test created. Wrap the helper call with mock.patch.object(runtime_paths.sys, 'platform', 'win32') so the Windows branch is exercised regardless of host OS. Same shape as the existing env-var patch. Surfaced by the run-25251848663 failure on main. --- tests/test_setup_routes.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/test_setup_routes.py b/tests/test_setup_routes.py index da984be..922e1d5 100644 --- a/tests/test_setup_routes.py +++ b/tests/test_setup_routes.py @@ -34,6 +34,17 @@ def test_env_extras_are_inserted_on_sys_path(self): sys.path[:] = original_sys_path def test_legacy_tauri_app_data_extras_are_import_candidates(self): + # ``_user_data_base`` only consults ``LOCALAPPDATA`` when + # ``sys.platform == "win32"``. On macOS dev boxes and the + # ubuntu-latest CI runner that branch is skipped, so just + # patching the env var leaves the legacy candidate path + # rooted at the host's real ``~/Library/Application Support`` + # / ``~/.local/share`` instead of the temp dir we created + # below — and the assertion fails because the legacy dir we + # mkdir'd isn't where the helper looks. Patch + # ``sys.platform`` to ``win32`` for the duration of this test + # so the Windows branch is exercised regardless of host OS. + from backend_service import runtime_paths from backend_service.runtime_paths import ensure_extras_on_sys_path tag = f"cp{sys.version_info.major}{sys.version_info.minor}" @@ -42,11 +53,12 @@ def test_legacy_tauri_app_data_extras_are_import_candidates(self): legacy.mkdir(parents=True) original_sys_path = list(sys.path) try: - with mock.patch.dict( - os.environ, - {"LOCALAPPDATA": tmp, "CHAOSENGINE_EXTRAS_SITE_PACKAGES": ""}, - clear=False, - ): + with mock.patch.object(runtime_paths.sys, "platform", "win32"), \ + mock.patch.dict( + os.environ, + {"LOCALAPPDATA": tmp, "CHAOSENGINE_EXTRAS_SITE_PACKAGES": ""}, + clear=False, + ): inserted = ensure_extras_on_sys_path() self.assertIn(legacy, inserted) self.assertIn(str(legacy), sys.path)