From b15510e2a6a1c99766e32bc04a825721c42b9e51 Mon Sep 17 00:00:00 2001 From: nelsonduarte Date: Sat, 18 Jul 2026 21:31:51 +0100 Subject: [PATCH] test(updater): exercise real MSIX detection in short-circuit test test_check_for_update_returns_none_on_msix mocked is_system_install -- the very function whose behaviour it claims to verify -- so it passed regardless of what the detection chain did. Reverting the win32 branch of is_system_install() to `return False` left the test green: false coverage on a load-bearing safety check. Patch only the environment the detection reads (sys.platform, the PACKAGE_FULL_NAME env var, sys.executable) plus the urlopen network boundary, so the genuine composition check_for_update -> is_system_install -> is_msix_install runs. Assert both that None is returned and that no HTTP request was attempted. A second case covers the load-bearing \WindowsApps\ path branch with the env var cleared. Both now fail against that mutant. Also add the artefacts-*/ spelling next to artifacts-*/ in .gitignore; the "e" variant was not covered and left local release artifacts showing up as untracked. Co-Authored-By: Claude Opus 4.8 --- .gitignore | 1 + tests/test_updater_msix.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0734393..b960e54 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ build_*.txt # Local release artifacts (downloaded for Microsoft Store submission) artifacts-*/ +artefacts-*/ # Testes / temporários test_ctrl_scroll.py diff --git a/tests/test_updater_msix.py b/tests/test_updater_msix.py index e30a7ce..63691b9 100644 --- a/tests/test_updater_msix.py +++ b/tests/test_updater_msix.py @@ -106,8 +106,41 @@ def test_is_system_install_false_for_nsis(): def test_check_for_update_returns_none_on_msix(): - with patch.object(updater, "is_system_install", return_value=True): + """End-to-end: real detection, no updater internals mocked. + + Nothing on the detection path (``is_msix_install`` / + ``is_system_install``) is patched here — only the *environment* they + read (platform, env var, executable path) and the network boundary. + So this exercises the genuine composition + ``check_for_update -> is_system_install -> is_msix_install`` and + fails if any link in that chain stops short-circuiting. + """ + with patch.object(updater.sys, "platform", "win32"), \ + patch.dict(updater.os.environ, + {"PACKAGE_FULL_NAME": "PDFApps_1.14.0.0_x64__abcdefg"}, + clear=False), \ + patch.object(updater.urllib.request, "urlopen") as mock_open: + assert check_for_update() is None + mock_open.assert_not_called() + + +def test_check_for_update_returns_none_on_msix_via_windowsapps_path(): + """Same, but through the load-bearing \\WindowsApps\\ path detection. + + The env var is cleared so the only thing that can short-circuit the + update check is the real executable-path branch of + ``is_msix_install``. + """ + exe = r"C:\Program Files\WindowsApps\PDFApps_1.14.0.0_x64__abc\PDFApps.exe" + env = {k: v for k, v in updater.os.environ.items() + if k != "PACKAGE_FULL_NAME"} + with patch.object(updater.sys, "platform", "win32"), \ + patch.dict(updater.os.environ, env, clear=True), \ + patch.object(updater.sys, "executable", exe), \ + patch.object(updater.os.path, "realpath", side_effect=lambda p: p), \ + patch.object(updater.urllib.request, "urlopen") as mock_open: assert check_for_update() is None + mock_open.assert_not_called() def test_check_for_update_makes_no_network_call_on_msix():