@@ -346,6 +346,35 @@ def test_serve_logs_convenience_function(self, temp_build_dir):
346346 # Verify that the run method was called
347347 mock_run .assert_called_once ()
348348
349+ def test_serve_logs_port_parameter (self , temp_build_dir ):
350+ """Test that serve_logs properly passes the port parameter to LogsServer."""
351+ with patch ("eval_protocol.utils.logs_server.LogsServer" ) as mock_logs_server_class :
352+ mock_server_instance = Mock ()
353+ mock_logs_server_class .return_value = mock_server_instance
354+
355+ # Call serve_logs with a specific port
356+ test_port = 9000
357+ serve_logs (port = test_port )
358+
359+ # Verify that LogsServer was created with the correct port
360+ mock_logs_server_class .assert_called_once_with (port = test_port )
361+ # Verify that the run method was called on the instance
362+ mock_server_instance .run .assert_called_once ()
363+
364+ def test_serve_logs_default_port (self , temp_build_dir ):
365+ """Test that serve_logs uses default port when none is specified."""
366+ with patch ("eval_protocol.utils.logs_server.LogsServer" ) as mock_logs_server_class :
367+ mock_server_instance = Mock ()
368+ mock_logs_server_class .return_value = mock_server_instance
369+
370+ # Call serve_logs without specifying a port
371+ serve_logs ()
372+
373+ # Verify that LogsServer was created with None port (which will use LogsServer's default of 8000)
374+ mock_logs_server_class .assert_called_once_with (port = None )
375+ # Verify that the run method was called on the instance
376+ mock_server_instance .run .assert_called_once ()
377+
349378 @pytest .mark .asyncio
350379 async def test_run_async_lifecycle (self , temp_build_dir ):
351380 """Test the async lifecycle of the server."""
@@ -445,6 +474,72 @@ def test_health_endpoint(self, temp_build_dir_with_files):
445474 data = response .json ()
446475 assert data ["status" ] == "ok"
447476
477+ @pytest .mark .asyncio
478+ async def test_server_runs_on_specific_port (self , temp_build_dir_with_files ):
479+ """Integration test: verify that LogsServer actually runs on the specified port (async requests)."""
480+ import socket
481+
482+ import httpx
483+
484+ # Find an available port for testing
485+ def find_free_port ():
486+ with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
487+ s .bind (("" , 0 ))
488+ s .listen (1 )
489+ port = s .getsockname ()[1 ]
490+ return port
491+
492+ test_port = find_free_port ()
493+
494+ # Create and start server in background
495+ server = LogsServer (build_dir = str (temp_build_dir_with_files ), port = test_port )
496+
497+ # Start server in background task
498+ server_task = asyncio .create_task (server .run_async ())
499+
500+ try :
501+ # Wait longer for server to start and be ready
502+ await asyncio .sleep (3 )
503+
504+ async with httpx .AsyncClient () as client :
505+ # Test that we can actually connect to the server on the specified port
506+ response = await client .get (f"http://localhost:{ test_port } /" , timeout = 10 )
507+ assert response .status_code == 200
508+ assert "Test" in response .text
509+
510+ # Test the health endpoint
511+ response = await client .get (f"http://localhost:{ test_port } /health" , timeout = 10 )
512+ assert response .status_code == 200
513+ data = response .json ()
514+ assert data ["status" ] == "ok"
515+
516+ finally :
517+ # Clean up
518+ server_task .cancel ()
519+ try :
520+ await server_task
521+ except asyncio .CancelledError :
522+ pass
523+
524+ def test_serve_logs_port_parameter_integration (self , temp_build_dir_with_files ):
525+ """Integration test: verify that serve_logs function actually works with port parameter."""
526+ # This test verifies that serve_logs creates LogsServer with the correct port
527+ # without actually starting the server
528+ test_port = 9999
529+
530+ # Use a different approach - mock the LogsServer class and verify the port parameter
531+ with patch ("eval_protocol.utils.logs_server.LogsServer" ) as mock_logs_server_class :
532+ mock_server_instance = Mock ()
533+ mock_logs_server_class .return_value = mock_server_instance
534+
535+ # Call serve_logs with specific port
536+ serve_logs (port = test_port )
537+
538+ # Verify that LogsServer was created with the correct port
539+ mock_logs_server_class .assert_called_once_with (port = test_port )
540+ # Verify that the run method was called on the instance
541+ mock_server_instance .run .assert_called_once ()
542+
448543
449544@pytest .mark .asyncio
450545class TestAsyncWebSocketOperations :
0 commit comments