import os
import unittest
from unittest.mock import patch

import mcp_pipe


class EndpointConfigTest(unittest.TestCase):
    def test_reads_multiple_endpoints(self):
        with patch.dict(
            os.environ,
            {
                "MCP_ENDPOINTS": "wss://device-1, wss://device-2",
                "MCP_ENDPOINT": "wss://legacy",
            },
        ):
            self.assertEqual(
                mcp_pipe.load_endpoint_urls(),
                ["wss://device-1", "wss://device-2"],
            )

    def test_falls_back_to_legacy_endpoint(self):
        with patch.dict(os.environ, {"MCP_ENDPOINT": "wss://legacy"}, clear=True):
            self.assertEqual(mcp_pipe.load_endpoint_urls(), ["wss://legacy"])


if __name__ == "__main__":
    unittest.main()
