fix: installer tolerates localized 'service exists' (1073) and restarts the service if an upgrade step fails; 1.1.7

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
gti
2026-09-24 11:13:19 -03:00
co-authored by Claude Sonnet 5
parent 55e858e261
commit f5f05d87e6
21 changed files with 68 additions and 29 deletions
+33
View File
@@ -157,3 +157,36 @@ def test_start_and_verify_reports_failure_after_all_attempts(monkeypatch, tmp_pa
ok, detail = common.start_and_verify(attempts=2, per_attempt=0.01)
assert not ok and "1053" in detail
assert "NÃO iniciou" in setup_main.final_message({"service_running": False, "service_detail": detail, "install_dir": "x"})
def test_install_service_tolerates_localized_already_exists(monkeypatch):
"""pt-BR Windows says 'já existe', not 'already exists': the return code (1073) must decide."""
import subprocess
seen = []
def fake_sc(args):
seen.append(args[0])
if args[0] == "create":
return subprocess.CompletedProcess(args, 1073, "[SC] CreateService FALHA 1073: O serviço especificado já existe.", "")
if args[0] == "qc":
return subprocess.CompletedProcess(args, 0, "START_TYPE : 2 AUTO_START (DELAYED)", "")
return subprocess.CompletedProcess(args, 0, "", "")
monkeypatch.setattr(common, "_sc", fake_sc)
common.install_service(Path("C:/x"))
assert seen[:3] == ["create", "config", "config"] and "failure" in seen
def test_failed_upgrade_step_restarts_the_existing_service(world, monkeypatch):
calls, inst = world
inst.mkdir(parents=True)
(inst / "credentials.bin").write_bytes(b"b")
(inst / "agent.env").write_text("AGENT_ID=2\nINSTALLATION_ID=x\nGTI_HUB_URL=https://h\n")
def boom(d):
raise RuntimeError("boom")
monkeypatch.setattr(common, "install_service", boom)
with pytest.raises(RuntimeError, match="boom"):
setup_main.upgrade_flow()
assert ("start",) in calls # the Agent was brought back up despite the failure