"""Tests for the Windows gateway backend.""" import pytest import hermes_cli.gateway_windows as gateway_windows @pytest.mark.parametrize( "detail", [ "ERROR: Access is denied.", "ERROR: Acceso denegado.", "ERROR: Přístup byl odepřen.", "schtasks timed out after 15s", "schtasks produced no output", ], ) def test_schtasks_fallback_patterns_cover_localized_access_denied(detail): """Localized schtasks access-denied errors should use Startup fallback.""" assert gateway_windows._should_fall_back(1, detail) is True def test_schtasks_fallback_does_not_hide_unknown_errors(): assert gateway_windows._should_fall_back(1, "ERROR: The system cannot find the file specified.") is False def test_build_gateway_argv_uses_base_pythonw_for_uv_venv_launcher(monkeypatch, tmp_path): """Avoid uv's venv pythonw launcher because it respawns console python.exe.""" project = tmp_path / "project" scripts = project / "venv" / "Scripts" site_packages = project / "venv" / "Lib" / "site-packages" base = tmp_path / "uv" / "python" / "cpython-3.11-windows-x86_64-none" scripts.mkdir(parents=True) site_packages.mkdir(parents=True) base.mkdir(parents=True) venv_python = scripts / "python.exe" venv_pythonw = scripts / "pythonw.exe" base_pythonw = base / "pythonw.exe" for exe in (venv_python, venv_pythonw, base_pythonw): exe.write_text("", encoding="utf-8") (project / "venv" / "pyvenv.cfg").write_text( f"home = {base}\nimplementation = CPython\nuv = 0.11.14\nversion_info = 3.11.15\n", encoding="utf-8", ) import hermes_cli.gateway as gateway monkeypatch.setattr(gateway_windows.sys, "platform", "win32") monkeypatch.setattr(gateway, "PROJECT_ROOT", project) monkeypatch.setattr(gateway, "get_python_path", lambda: str(venv_python)) monkeypatch.setattr(gateway, "_profile_arg", lambda hermes_home: "") monkeypatch.setattr("hermes_cli.config.get_hermes_home", lambda: str(tmp_path / "hermes-home")) argv, cwd, env_overlay = gateway_windows._build_gateway_argv() assert argv[:3] == [str(base_pythonw), "-m", "hermes_cli.main"] assert cwd == str(project) assert env_overlay["VIRTUAL_ENV"] == str(project / "venv") assert str(project) in env_overlay["PYTHONPATH"].split(gateway_windows.os.pathsep) assert str(site_packages) in env_overlay["PYTHONPATH"].split(gateway_windows.os.pathsep)