fix: fresh install archives stale state of a previous installation; a fatal Agent loop error stops the service instead of leaving a dead 'Running' one; 1.2.3

Found by uninstall + fresh install on the clean Windows Sandbox: the old agent_state.sqlite identity conflicted with the new enrollment and the service sat idle.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
gti
2026-09-25 12:25:53 -03:00
co-authored by Claude Sonnet 5
parent 2e5598ce9c
commit 6f0f072d84
23 changed files with 81 additions and 25 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.2.2"
assert v == GTI_FISCAL_VERSION == "1.2.3"
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.2.2"' in (ROOT / "agent" / "scripts" / "run_agent_service.py").read_text(encoding="utf-8")
assert '"AGENT_VERSION", "1.2.3"' 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"))
+25
View File
@@ -191,3 +191,28 @@ def test_failed_upgrade_step_restarts_the_existing_service(world, monkeypatch):
with pytest.raises(RuntimeError, match="boom"):
setup_main.upgrade_flow()
assert ("start",) in calls # the Agent was brought back up despite the failure
def test_fresh_install_archives_a_state_database_left_by_a_previous_installation(tmp_path, monkeypatch):
"""Uninstall keeps local data; a NEW enrollment must not inherit the old installation_id (the Agent refuses the mix and used to sit dead while 'Running')."""
monkeypatch.setenv("GTI_LOG_DIR", str(tmp_path / "logs"))
inst = tmp_path / "inst"
inst.mkdir()
(inst / "agent_state.sqlite").write_bytes(b"old identity")
(inst / "agent_state.sqlite-wal").write_bytes(b"wal")
moved = common.archive_stale_state(inst)
assert len(moved) == 2 and not (inst / "agent_state.sqlite").exists()
assert (inst / moved[0]).read_bytes() in (b"old identity", b"wal") # renamed aside, never deleted
assert common.archive_stale_state(inst) == [] # nothing left to archive
def test_install_flow_archives_stale_state_before_starting_the_service(world, monkeypatch):
calls, inst = world
one_db(monkeypatch)
inst.mkdir(parents=True)
(inst / "agent_state.sqlite").write_bytes(b"identity of a previous installation")
order = []
monkeypatch.setattr(common, "archive_stale_state", lambda d: order.append("archive") or [])
monkeypatch.setattr(common, "start_and_verify", lambda *a, **k: order.append("start") or (True, "RUNNING"))
setup_main.install_flow("AAAA-BBBB-CCCC-DDDD")
assert order == ["archive", "start"]