From ac37e19d60397ca688a61c755adf839a30fb8e55 Mon Sep 17 00:00:00 2001 From: Zoey Rose Date: Thu, 24 Sep 2026 08:27:12 -0500 Subject: [PATCH 1/2] fix(classic): use generated packet command IDs --- maps/python/Packet.py | 6 +- tools/tests/test_packet_commands.py | 97 +++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 tools/tests/test_packet_commands.py diff --git a/maps/python/Packet.py b/maps/python/Packet.py index d09bc1b03..0e9514a08 100644 --- a/maps/python/Packet.py +++ b/maps/python/Packet.py @@ -4,6 +4,8 @@ ## ## @author Zoey Rose +import Atrinik + ## Send a notification command to the player. ## @param pl The player. ## @param msg Message contents of the notification. @@ -32,7 +34,7 @@ def Notification(pl, msg, action = None, shortcut = None, delay = 0): data += [3, delay] # Send it off... - pl.SendPacket(27, fmt, *data) + pl.SendPacket(Atrinik.CLIENT_CMD_NOTIFICATION, fmt, *data) ## Send a map stats command. ## @pl Player to send the command to. @@ -59,4 +61,4 @@ def MapStats(pl, name = None, music = None, weather = None): data += [3, weather] # Send it off... - pl.SendPacket(13, fmt, *data) + pl.SendPacket(Atrinik.CLIENT_CMD_MAPSTATS, fmt, *data) diff --git a/tools/tests/test_packet_commands.py b/tools/tests/test_packet_commands.py new file mode 100644 index 000000000..503639755 --- /dev/null +++ b/tools/tests/test_packet_commands.py @@ -0,0 +1,97 @@ +from __future__ import annotations + +import importlib.util +from pathlib import Path +import sys +import types +import unittest +from unittest import mock + + +ROOT = Path(__file__).resolve().parents[2] +PACKET_PATH = ROOT / "maps" / "python" / "Packet.py" +NOTIFICATION_COMMAND = 26026 +MAPSTATS_COMMAND = 12012 + + +def load_packet(): + atrinik = types.ModuleType("Atrinik") + atrinik.CLIENT_CMD_NOTIFICATION = NOTIFICATION_COMMAND + atrinik.CLIENT_CMD_MAPSTATS = MAPSTATS_COMMAND + spec = importlib.util.spec_from_file_location("content_test_packet", PACKET_PATH) + assert spec is not None and spec.loader is not None + module = importlib.util.module_from_spec(spec) + with mock.patch.dict(sys.modules, {"Atrinik": atrinik}): + spec.loader.exec_module(module) + return module + + +class RecordingPlayer: + def __init__(self): + self.packets = [] + + def SendPacket(self, command, fmt, *data): + self.packets.append((command, fmt, data)) + + +class PacketCommandTests(unittest.TestCase): + def setUp(self): + self.packet = load_packet() + self.player = RecordingPlayer() + + def test_notification_uses_exported_command_and_preserves_optional_fields(self): + cases = ( + ( + {}, + (NOTIFICATION_COMMAND, "Bs", (0, "Message")), + ), + ( + {"action": "apply"}, + (NOTIFICATION_COMMAND, "BsBs", (0, "Message", 1, "apply")), + ), + ( + {"shortcut": "?HELP", "delay": 4000}, + (NOTIFICATION_COMMAND, "BsBi", (0, "Message", 3, 4000)), + ), + ( + {"action": "apply", "shortcut": "?HELP", "delay": 120000}, + ( + NOTIFICATION_COMMAND, + "BsBsBsBi", + (0, "Message", 1, "apply", 2, "?HELP", 3, 120000), + ), + ), + ) + + for kwargs, expected in cases: + with self.subTest(kwargs=kwargs): + self.player.packets.clear() + self.packet.Notification(self.player, "Message", **kwargs) + self.assertEqual([expected], self.player.packets) + + def test_map_stats_uses_exported_command_and_preserves_field_order(self): + cases = ( + ({}, (MAPSTATS_COMMAND, "", ())), + ( + {"name": "The Lake", "music": "lake.ogg", "weather": "rain"}, + ( + MAPSTATS_COMMAND, + "BsBsBs", + (1, "The Lake", 2, "lake.ogg", 3, "rain"), + ), + ), + ( + {"music": "lake.ogg"}, + (MAPSTATS_COMMAND, "Bs", (2, "lake.ogg")), + ), + ) + + for kwargs, expected in cases: + with self.subTest(kwargs=kwargs): + self.player.packets.clear() + self.packet.MapStats(self.player, **kwargs) + self.assertEqual([expected], self.player.packets) + + +if __name__ == "__main__": + unittest.main() From 646c42dca71189b17b163eb4606e23cb5d0b8387 Mon Sep 17 00:00:00 2001 From: Zoey Rose Date: Thu, 24 Sep 2026 08:33:32 -0500 Subject: [PATCH 2/2] test(content): run packet command regression tests --- tools/validate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/validate.py b/tools/validate.py index 83f231ccd..5ac0140f5 100755 --- a/tools/validate.py +++ b/tools/validate.py @@ -71,6 +71,7 @@ def main() -> int: "tools.tests.test_release_guidance", "tools.tests.test_release_line_parity", "tools.tests.test_pr_metadata", + "tools.tests.test_packet_commands", "tools.tests.test_python_commands", "tools.tests.test_status_icons", "tools.tests.test_validate_exits",