@@ -26,6 +26,21 @@ def _redis_available():
2626 return False
2727
2828
29+ def _create_server_process (project_root ):
30+ """Create a server process with proper encoding for cross-platform compatibility."""
31+ return subprocess .Popen (
32+ [sys .executable , "-m" , "src.main" ],
33+ cwd = project_root ,
34+ stdin = subprocess .PIPE ,
35+ stdout = subprocess .PIPE ,
36+ stderr = subprocess .PIPE ,
37+ text = True ,
38+ encoding = 'utf-8' ,
39+ errors = 'replace' , # Replace invalid characters instead of failing
40+ env = {"REDIS_HOST" : "localhost" , "REDIS_PORT" : "6379" , ** dict (os .environ )},
41+ )
42+
43+
2944@pytest .mark .integration
3045class TestMCPServerIntegration :
3146 """Integration tests that start the actual MCP server."""
@@ -36,16 +51,8 @@ def server_process(self):
3651 # Get the project root directory
3752 project_root = Path (__file__ ).parent .parent
3853
39- # Start the server process
40- process = subprocess .Popen (
41- [sys .executable , "-m" , "src.main" ],
42- cwd = project_root ,
43- stdin = subprocess .PIPE ,
44- stdout = subprocess .PIPE ,
45- stderr = subprocess .PIPE ,
46- text = True ,
47- env = {"REDIS_HOST" : "localhost" , "REDIS_PORT" : "6379" , ** dict (os .environ )},
48- )
54+ # Start the server process with proper encoding for cross-platform compatibility
55+ process = _create_server_process (project_root )
4956
5057 # Give the server a moment to start
5158 time .sleep (1 )
@@ -72,6 +79,42 @@ def test_server_starts_successfully(self, server_process):
7279 # The server should still be running
7380 assert server_process .poll () is None
7481
82+ def test_server_handles_unicode_on_windows (self , server_process ):
83+ """Test that the server handles Unicode properly on Windows."""
84+ # This test specifically addresses the Windows Unicode decode error
85+ # Check if process is still running
86+ assert server_process .poll () is None , "Server process should be running"
87+
88+ # Try to read any available output without blocking
89+ # This should not cause a UnicodeDecodeError on Windows
90+ try :
91+ # Use a short timeout to avoid blocking
92+ import select
93+ import sys
94+
95+ if sys .platform == "win32" :
96+ # On Windows, we can't use select, so just check if process is alive
97+ time .sleep (0.1 )
98+ assert server_process .poll () is None
99+ else :
100+ # On Unix-like systems, we can use select
101+ ready , _ , _ = select .select ([server_process .stdout ], [], [], 0.1 )
102+ # If there's output available, try to read it
103+ if ready :
104+ try :
105+ output = server_process .stdout .read (1 ) # Read just one character
106+ # If we get here, Unicode handling is working
107+ assert True
108+ except UnicodeDecodeError :
109+ pytest .fail ("Unicode decode error occurred" )
110+
111+ except Exception as e :
112+ # If any other error occurs, that's fine - we're just testing Unicode handling
113+ pass
114+
115+ # Main assertion: process should still be running
116+ assert server_process .poll () is None
117+
75118 def test_server_responds_to_initialize_request (self , server_process ):
76119 """Test that the server responds to MCP initialize request."""
77120 # MCP initialize request
0 commit comments