Fix T6 occupancy parsing in host agent

This commit is contained in:
2026-10-04 20:20:10 -04:00
parent ed004ddbcf
commit 456af32b36
5 changed files with 80 additions and 8 deletions
+42
View File
@@ -153,6 +153,28 @@ class AgentTests(unittest.TestCase):
self.agent.rcon = lambda *_: {"ok": True, "players": 0}
self.assertEqual(self.agent.execute(operation)["state"], "completed")
def test_occupancy_hold_explains_local_rcon_failure_without_exposing_reply(self):
self.create()
operation = self.operation("instance.restart")
for reason, detail in (
("unconfigured", "password is not configured"),
("unreachable", "endpoint is unreachable"),
("invalid-reply", "invalid packet prefix"),
("timeout", "query timed out"),
("authentication", "authentication failed"),
(None, "no recognized player count"),
):
with self.subTest(reason=reason):
self.agent.rcon = lambda *_: {"ok": reason is None, "reason": reason, "players": None, "text": "sensitive raw reply"}
result = self.agent.execute(operation)
self.assertEqual(result["state"], "accepted")
message = json.loads(result["result"])["message"]
self.assertIn(detail, message)
self.assertNotIn("sensitive raw reply", message)
self.assertFalse(any(call[:2] == ("container", "restart") for call in self.docker.calls))
self.agent.rcon = lambda *_: {"ok": True, "players": 0}
self.assertEqual(self.agent.execute(operation)["state"], "completed")
def test_unknown_container_health_cannot_disrupt(self):
self.create()
self.docker.containers[self.agent.container_name(INSTANCE, 1)]["State"] = {"Status": "unknown", "Running": False}
@@ -896,6 +918,26 @@ class AgentTests(unittest.TestCase):
self.assertEqual(result["players"], 1)
self.assertTrue(result["ok"])
def test_t6_bot_column_allows_empty_restart_but_holds_players_and_partial_replies(self):
self.create()
header = "map: zm_nuked\nnum score bot ping guid name lastmsg address qport rate\n"
table = header + "--- ----- --- ---- -------------------------------- ---------------- ------- --------------------- ------ -----\n"
operation = self.operation("instance.restart")
for body, players in (
(header, None),
(table + "0 0 0 CNCT abc player 0 127.0.0.1:28960 123 25000\n", 1),
(table + "0 0 1 0 abc bot 0 loopback 0 25000\n", 1),
(table + "unrecognized trailing output", None),
(table, 0),
):
with self.subTest(body=body):
self.assertEqual(module.status_players(body), players)
self.agent.rcon = lambda *_: {"ok": True, "players": module.status_players(body)}
result = self.agent.execute(operation)
self.assertEqual(result["state"], "completed" if players == 0 else "accepted")
if players != 0:
self.assertFalse(any(call[:2] == ("container", "restart") for call in self.docker.calls))
def test_invalid_rebuild_preflight_preserves_running_original(self):
payload = self.create()
result = self.agent.execute(self.operation("instance.rebuild", {**payload, "image": "--privileged", "nextGeneration": 2}))