All checks were successful
Zapret source guards / validate (push) Successful in 8s
Second and third seams of the multi-platform project. platforms.current() now also offers privileges (is_elevated, relaunch_elevated, and gui_needs_elevation: true on Windows, false on Linux where a root helper service will do the privileged work) and single_instance (Windows: mutex + named event as before; Linux: flock lock file + Unix socket carrying 'show the window', bound before Qt starts so an early signal is not lost). shell_bootstrap, the show-window bridge and every IsUserAnAdmin call site (system state, program settings, winws health diagnostics, Defender manager, NSSM diagnostics) go through the platform. startup/admin_check.py (its two restart helpers had no callers) and startup/single_instance.py are deleted. The process-hacker diagnostics test now runs on Linux too. Windows behaviour is unchanged. The Windows API ratchet shrinks from 72 to 66 files. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
import inspect
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import Mock, patch
|
|
|
|
|
|
class LaunchConflictingProcessesTests(unittest.TestCase):
|
|
def test_start_preflight_does_not_warn_just_because_process_hacker_is_running(self) -> None:
|
|
from winws_runtime.runtime import conflict_flow
|
|
|
|
runtime_owner = Mock()
|
|
|
|
with patch.object(conflict_flow, "check_conflicting_processes") as check_conflicts:
|
|
allowed = conflict_flow.handle_conflicting_processes_before_start(runtime_owner)
|
|
|
|
self.assertTrue(allowed)
|
|
check_conflicts.assert_not_called()
|
|
|
|
def test_conflict_registry_lives_in_separate_module(self) -> None:
|
|
from winws_runtime.health import launch_conflicts
|
|
from winws_runtime.health import process_health_check
|
|
|
|
self.assertTrue(callable(launch_conflicts.check_conflicting_processes))
|
|
self.assertTrue(callable(launch_conflicts.build_launch_conflict_advice))
|
|
self.assertNotIn("CONFLICTING_PROCESSES", inspect.getsource(process_health_check))
|
|
|
|
def test_process_hacker_advice_is_added_after_windivert_launch_failure(self) -> None:
|
|
import platforms
|
|
from winws_runtime.health import launch_conflicts
|
|
from winws_runtime.health.process_health_check import diagnose_winws_exit
|
|
|
|
conflict = {
|
|
"exe": "processhacker.exe",
|
|
"name": "Process Hacker",
|
|
"reason": "мешает WinDivert",
|
|
"solution": "Закройте Process Hacker",
|
|
"pid": 4242,
|
|
}
|
|
|
|
with (
|
|
# The access-denied handler first probes real admin rights and
|
|
# short-circuits with generic advice when not elevated, so the
|
|
# probe must be pinned for the conflict branch to be reachable.
|
|
patch.object(platforms.current().privileges, "is_elevated", return_value=True),
|
|
patch.object(launch_conflicts, "check_conflicting_processes", return_value=[conflict]),
|
|
):
|
|
diagnosis = diagnose_winws_exit(5, "Error opening filter: Access is denied")
|
|
|
|
self.assertIsNotNone(diagnosis)
|
|
assert diagnosis is not None
|
|
self.assertIn("Process Hacker", diagnosis.cause)
|
|
self.assertIn("помешал запуску Zapret", diagnosis.cause)
|
|
self.assertIn("Закройте Process Hacker", diagnosis.solution)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|