from __future__ import annotations import os import unittest from unittest.mock import patch from straywild_discovery.server import ServerConfig class ServerConfigCompatibilityTests(unittest.TestCase): def test_legacy_environment_remains_accepted(self) -> None: with patch.dict( os.environ, { "NETFISHING_DISCOVERY_HOST": "127.0.0.9", "NETFISHING_DISCOVERY_PORT": "7791", "NETFISHING_DISCOVERY_BUILD_REVISION": "legacy-config", }, clear=True, ): config = ServerConfig.from_environment() self.assertEqual(config.bind_host, "127.0.0.9") self.assertEqual(config.bind_port, 7791) self.assertEqual(config.build_revision, "legacy-config") self.assertTrue(config.relay_enabled) def test_straywild_environment_wins_over_legacy_names(self) -> None: with patch.dict( os.environ, { "straywild_DISCOVERY_HOST": "127.0.0.8", "NETFISHING_DISCOVERY_HOST": "127.0.0.9", "straywild_DISCOVERY_PORT": "7792", "NETFISHING_DISCOVERY_PORT": "7791", }, clear=True, ): config = ServerConfig.from_environment() self.assertEqual(config.bind_host, "127.0.0.8") self.assertEqual(config.bind_port, 7792) def test_relay_can_be_explicitly_disabled_without_fallback_ambiguity(self) -> None: with patch.dict( os.environ, {"straywild_DISCOVERY_RELAY_ENABLED": "false"}, clear=True, ): config = ServerConfig.from_environment() self.assertFalse(config.relay_enabled) if __name__ == "__main__": unittest.main()