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
+2 -2
View File
@@ -14,11 +14,11 @@ sys.path.insert(0, str(ROOT))
def test_versions_are_coherent_across_hub_agent_and_packages():
from central.app.version import GTI_FISCAL_VERSION
v = (ROOT / "release" / "VERSION").read_text(encoding="utf-8").strip()
assert v == GTI_FISCAL_VERSION == "1.1.6"
assert v == GTI_FISCAL_VERSION == "1.1.7"
pep = v.replace("-rc", "rc")
for pp in ("central/pyproject.toml", "agent/pyproject.toml"):
assert f'version = "{pep}"' in (ROOT / pp).read_text(encoding="utf-8")
assert '"AGENT_VERSION", "1.1.6"' in (ROOT / "agent" / "scripts" / "run_agent_service.py").read_text(encoding="utf-8")
assert '"AGENT_VERSION", "1.1.7"' in (ROOT / "agent" / "scripts" / "run_agent_service.py").read_text(encoding="utf-8")
manifest = ROOT / "release" / "RELEASE_MANIFEST.json"
if manifest.exists():
m = json.loads(manifest.read_text(encoding="utf-8"))
+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