@@ -280,7 +280,7 @@ def test_generates_health_check_when_enabled(
280280 "name" : "HealthProject" ,
281281 "health_check_enabled" : True ,
282282 "health_check_path" : "/health" ,
283- "health_check_response" : "OK"
283+ "health_check_response" : "OK" ,
284284 }
285285 config_file .write_text (json .dumps (config ))
286286
@@ -321,7 +321,7 @@ def simple_tool() -> Output:
321321 assert "from starlette.responses import PlainTextResponse" in server_code
322322
323323 # Should contain health check route definition
324- assert " @mcp.custom_route(\ " /health\ " , methods=[\ " GET\ " ])" in server_code
324+ assert ' @mcp.custom_route("/health", methods=["GET"])' in server_code
325325 assert (
326326 "async def health_check(request: Request) -> PlainTextResponse:"
327327 in server_code
@@ -338,7 +338,7 @@ def test_health_check_with_custom_config(
338338 "name" : "CustomHealthProject" ,
339339 "health_check_enabled" : True ,
340340 "health_check_path" : "/status" ,
341- "health_check_response" : "Service is running"
341+ "health_check_response" : "Service is running" ,
342342 }
343343 config_file .write_text (json .dumps (config ))
344344
@@ -371,7 +371,7 @@ def simple_tool() -> Output:
371371 server_code = server_file .read_text ()
372372
373373 # Should use custom path and response
374- assert " @mcp.custom_route(\ " /status\ " , methods=[\ " GET\ " ])" in server_code
374+ assert ' @mcp.custom_route("/status", methods=["GET"])' in server_code
375375 assert 'return PlainTextResponse("Service is running")' in server_code
376376
377377 def test_no_health_check_when_disabled (
@@ -380,10 +380,7 @@ def test_no_health_check_when_disabled(
380380 """Test that health check route is not generated when disabled."""
381381 # Ensure health check is disabled (default)
382382 config_file = sample_project / "golf.json"
383- config = {
384- "name" : "NoHealthProject" ,
385- "health_check_enabled" : False
386- }
383+ config = {"name" : "NoHealthProject" , "health_check_enabled" : False }
387384 config_file .write_text (json .dumps (config ))
388385
389386 # Create a simple tool
@@ -426,18 +423,15 @@ def test_health_check_without_starlette_imports_when_disabled(
426423 # Create a minimal project without any auth or other features
427424 project_dir = temp_dir / "minimal_project"
428425 project_dir .mkdir ()
429-
426+
430427 # Create minimal golf.json with only health check disabled
431428 config_file = project_dir / "golf.json"
432- config = {
433- "name" : "MinimalProject" ,
434- "health_check_enabled" : False
435- }
429+ config = {"name" : "MinimalProject" , "health_check_enabled" : False }
436430 config_file .write_text (json .dumps (config ))
437-
431+
438432 # Create minimal tool structure
439433 (project_dir / "tools" ).mkdir ()
440- (project_dir / "resources" ).mkdir ()
434+ (project_dir / "resources" ).mkdir ()
441435 (project_dir / "prompts" ).mkdir ()
442436
443437 # Create a simple tool
@@ -470,8 +464,7 @@ def simple_tool() -> Output:
470464
471465 # Most importantly, no health check route should be generated
472466 assert (
473- "@mcp.custom_route" not in server_code
474- or "health_check" not in server_code
467+ "@mcp.custom_route" not in server_code or "health_check" not in server_code
475468 )
476469 assert "async def health_check" not in server_code
477470
@@ -480,10 +473,7 @@ def test_health_check_docstring_generation(
480473 ) -> None :
481474 """Test that health check function has proper docstring."""
482475 config_file = sample_project / "golf.json"
483- config = {
484- "name" : "DocstringProject" ,
485- "health_check_enabled" : True
486- }
476+ config = {"name" : "DocstringProject" , "health_check_enabled" : True }
487477 config_file .write_text (json .dumps (config ))
488478
489479 # Create a simple tool
@@ -515,20 +505,25 @@ def simple_tool() -> Output:
515505 server_code = server_file .read_text ()
516506
517507 # Should include descriptive docstring
518- assert '"""Health check endpoint for Kubernetes and load balancers."""' in server_code
508+ assert (
509+ '"""Health check endpoint for Kubernetes and load balancers."""'
510+ in server_code
511+ )
519512
520513
521514class TestHealthCheckEdgeCases :
522515 """Test edge cases and error conditions for health check generation."""
523516
524- def test_health_check_with_empty_response (self , sample_project : Path , temp_dir : Path ) -> None :
517+ def test_health_check_with_empty_response (
518+ self , sample_project : Path , temp_dir : Path
519+ ) -> None :
525520 """Test health check with empty response string."""
526521 config_file = sample_project / "golf.json"
527522 config = {
528523 "name" : "EmptyResponseProject" ,
529524 "health_check_enabled" : True ,
530525 "health_check_path" : "/health" ,
531- "health_check_response" : ""
526+ "health_check_response" : "" ,
532527 }
533528 config_file .write_text (json .dumps (config ))
534529
@@ -563,14 +558,16 @@ def simple_tool() -> Output:
563558 # Should handle empty string gracefully
564559 assert 'return PlainTextResponse("")' in server_code
565560
566- def test_health_check_path_sanitization (self , sample_project : Path , temp_dir : Path ) -> None :
561+ def test_health_check_path_sanitization (
562+ self , sample_project : Path , temp_dir : Path
563+ ) -> None :
567564 """Test that health check paths are properly handled in generated code."""
568565 config_file = sample_project / "golf.json"
569566 config = {
570567 "name" : "PathSanitizationProject" ,
571568 "health_check_enabled" : True ,
572569 "health_check_path" : "/api/v1/health-check" ,
573- "health_check_response" : "All systems operational"
570+ "health_check_response" : "All systems operational" ,
574571 }
575572 config_file .write_text (json .dumps (config ))
576573
@@ -603,23 +600,22 @@ def simple_tool() -> Output:
603600 server_code = server_file .read_text ()
604601
605602 # Should properly handle complex paths
606- assert "@mcp.custom_route(\" /api/v1/health-check\" , methods=[\" GET\" ])" in server_code
603+ assert (
604+ '@mcp.custom_route("/api/v1/health-check", methods=["GET"])' in server_code
605+ )
607606 assert 'return PlainTextResponse("All systems operational")' in server_code
608607
609608 def test_health_check_imports_only_when_needed (self , temp_dir : Path ) -> None :
610609 """Test that health check route is only generated when explicitly enabled."""
611610 # Create a minimal project without any auth or other features
612611 project_dir = temp_dir / "minimal_project"
613612 project_dir .mkdir ()
614-
613+
615614 # Create minimal golf.json with health check disabled
616615 config_file = project_dir / "golf.json"
617- config = {
618- "name" : "MinimalProject" ,
619- "health_check_enabled" : False
620- }
616+ config = {"name" : "MinimalProject" , "health_check_enabled" : False }
621617 config_file .write_text (json .dumps (config ))
622-
618+
623619 # Create minimal tool structure
624620 (project_dir / "tools" ).mkdir ()
625621 (project_dir / "resources" ).mkdir ()
@@ -655,7 +651,7 @@ def simple_tool() -> Output:
655651
656652 # Should not have health check route when disabled
657653 assert "async def health_check" not in server_code
658-
654+
659655 # Now test with health check enabled
660656 config ["health_check_enabled" ] = True
661657 config ["health_check_path" ] = "/health"
@@ -664,6 +660,7 @@ def simple_tool() -> Output:
664660
665661 # Clean and regenerate
666662 import shutil
663+
667664 shutil .rmtree (output_dir )
668665
669666 settings = load_settings (project_dir )
0 commit comments