99import psutil
1010import pytest
1111from fastapi import FastAPI
12+ from fastapi .routing import APIWebSocketRoute
1213from fastapi .testclient import TestClient
1314
1415from eval_protocol .dataset_logger import default_logger
@@ -291,36 +292,41 @@ def temp_build_dir(self):
291292 (temp_path / "assets" ).mkdir (exist_ok = True )
292293 yield temp_path
293294
294- def test_initialization (self , temp_build_dir ):
295+ def test_initialization (self , temp_build_dir : Path ):
295296 """Test LogsServer initialization."""
296297 server = LogsServer (build_dir = str (temp_build_dir ))
297- assert server .build_dir == str ( temp_build_dir )
298+ assert server .build_dir == temp_build_dir
298299 assert server .websocket_manager is not None
299300 assert server .evaluation_watcher is not None
300301
301302 def test_initialization_invalid_build_dir (self ):
302303 """Test LogsServer initialization with invalid build directory."""
303- with pytest .raises (ValueError , match = "Build directory does not exist" ):
304+ with pytest .raises (FileNotFoundError , match = "Build directory '/nonexistent/path' does not exist" ):
304305 LogsServer (build_dir = "/nonexistent/path" )
305306
306307 def test_websocket_routes (self , temp_build_dir ):
307308 """Test that WebSocket routes are properly set up."""
308309 server = LogsServer (build_dir = str (temp_build_dir ))
309310
310311 # Check that the WebSocket endpoint exists
311- websocket_routes = [route for route in server .app .routes if hasattr (route , "endpoint" )]
312- assert len (websocket_routes ) > 0
312+ if not server .app .routes :
313+ raise ValueError ("No routes found" )
314+ for route in server .app .routes :
315+ if isinstance (route , APIWebSocketRoute ) and route .path == "/ws" :
316+ break
317+ else :
318+ raise ValueError ("WebSocket route not found" )
313319
314320 @pytest .mark .asyncio
315321 async def test_handle_event (self , temp_build_dir ):
316322 """Test event handling."""
317323 server = LogsServer (build_dir = str (temp_build_dir ))
318324
319325 # Test handling a log event
320- test_row = EvaluationRow (
321- messages = [ Message ( role = " user" , content = " test") ],
322- input_metadata = InputMetadata ( row_id = " test-123") ,
323- )
326+ test_row = {
327+ " messages" : [{ " role" : " user" , " content" : " test"} ],
328+ " input_metadata" : { " row_id" : " test-123"} ,
329+ }
324330
325331 server ._handle_event (LOG_EVENT_TYPE , test_row )
326332 # The event should be queued for broadcasting
@@ -333,8 +339,12 @@ def test_create_app_factory(self, temp_build_dir):
333339
334340 def test_serve_logs_convenience_function (self , temp_build_dir ):
335341 """Test the serve_logs convenience function."""
336- # This should not raise an error
337- serve_logs (port = 8001 )
342+ # Mock the LogsServer.run method to avoid actually starting a server
343+ with patch ("eval_protocol.utils.logs_server.LogsServer.run" ) as mock_run :
344+ # This should not raise an error
345+ serve_logs (port = 8001 )
346+ # Verify that the run method was called
347+ mock_run .assert_called_once ()
338348
339349 @pytest .mark .asyncio
340350 async def test_run_async_lifecycle (self , temp_build_dir ):
0 commit comments