From c3a8f7e9e2545b8d9a3fa427f8c75bee25a32e95 Mon Sep 17 00:00:00 2001 From: Nomads_Reach <144523850+NomadsReach@users.noreply.github.com> Date: Sat, 15 Aug 2026 21:05:04 -0400 Subject: [PATCH] Update NPC protocol tests for validated active sessions --- server/test_npc_protocol.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/server/test_npc_protocol.py b/server/test_npc_protocol.py index bf1592f..2042273 100644 --- a/server/test_npc_protocol.py +++ b/server/test_npc_protocol.py @@ -6,7 +6,7 @@ import time import unittest from client_session import ClientSession -from server_core import FalloutTogetherServer +from server_core import FalloutTogetherServer, MAX_NPCS_PER_PACKET class NpcProtocolTests(unittest.TestCase): @@ -16,6 +16,10 @@ class NpcProtocolTests(unittest.TestCase): self.server = FalloutTogetherServer() self.host = ClientSession(self.host_server, ("local", 1), 1, time.time()) self.client = ClientSession(self.client_server, ("local", 2), 2, time.time()) + self.host.mark_gameplay_active(1) + self.client.mark_gameplay_active(1) + self.server._init_rate_state(self.host, time.monotonic()) + self.server._init_rate_state(self.client, time.monotonic()) self.server._clients = { self.host_server: self.host, self.client_server: self.client, @@ -31,6 +35,17 @@ class NpcProtocolTests(unittest.TestCase): ): connection.close() + def _npc(self, index: int) -> dict: + return { + "npcId": index, + "sourceFormId": "0001A4D7", + "x": float(index), + "y": 2.0, + "z": 3.0, + "angleZ": 0.5, + "cellId": "0000003C", + } + def test_host_npc_state_is_authoritative_and_broadcast(self) -> None: self.server._handle_line( self.host, @@ -38,17 +53,7 @@ class NpcProtocolTests(unittest.TestCase): { "type": "npcState", "playerId": 999, - "npcs": [ - { - "npcId": 1, - "baseFormId": "0001A4D7", - "x": 1.0, - "y": 2.0, - "z": 3.0, - "angleZ": 0.5, - "cellId": "0000003C", - } - ], + "npcs": [self._npc(1)], } ), ) @@ -104,7 +109,7 @@ class NpcProtocolTests(unittest.TestCase): json.dumps( { "type": "npcState", - "npcs": [{"npcId": index + 1} for index in range(17)], + "npcs": [self._npc(index + 1) for index in range(MAX_NPCS_PER_PACKET + 1)], } ), )