refactor(safety): apply consistent formatting across services and tests
Improved code readability and uniformity by standardizing line breaks, indentation, and inline conditions across safety-related services, models, and tests, including content filters, validation rules, and emergency controls.
This commit is contained in:
@@ -14,7 +14,6 @@ from app.services.mcp.client_manager import (
|
||||
shutdown_mcp_client,
|
||||
)
|
||||
from app.services.mcp.config import MCPConfig, MCPServerConfig
|
||||
from app.services.mcp.connection import ConnectionState
|
||||
from app.services.mcp.exceptions import MCPServerNotFoundError
|
||||
from app.services.mcp.registry import MCPServerRegistry
|
||||
from app.services.mcp.routing import ToolInfo, ToolResult
|
||||
|
||||
@@ -4,10 +4,8 @@ Tests for MCP Configuration System
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from app.services.mcp.config import (
|
||||
MCPConfig,
|
||||
@@ -217,9 +215,7 @@ mcp_servers:
|
||||
default_timeout: 60
|
||||
connection_pool_size: 20
|
||||
"""
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="w", suffix=".yaml", delete=False
|
||||
) as f:
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f:
|
||||
f.write(yaml_content)
|
||||
f.flush()
|
||||
|
||||
@@ -248,9 +244,7 @@ mcp_servers:
|
||||
explicit-server:
|
||||
url: http://explicit:8000
|
||||
"""
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="w", suffix=".yaml", delete=False
|
||||
) as f:
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f:
|
||||
f.write(yaml_content)
|
||||
f.flush()
|
||||
|
||||
@@ -267,9 +261,7 @@ mcp_servers:
|
||||
env-server:
|
||||
url: http://env:8000
|
||||
"""
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="w", suffix=".yaml", delete=False
|
||||
) as f:
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f:
|
||||
f.write(yaml_content)
|
||||
f.flush()
|
||||
|
||||
|
||||
@@ -220,9 +220,7 @@ class TestMCPConnection:
|
||||
MockClient.return_value = mock_client
|
||||
|
||||
await conn.connect()
|
||||
result = await conn.execute_request(
|
||||
"POST", "/mcp", data={"method": "test"}
|
||||
)
|
||||
result = await conn.execute_request("POST", "/mcp", data={"method": "test"})
|
||||
|
||||
assert result == {"result": "success"}
|
||||
|
||||
|
||||
@@ -160,11 +160,21 @@ class TestMCPToolNotFoundError:
|
||||
"""Test tool not found with available tools listed."""
|
||||
error = MCPToolNotFoundError(
|
||||
"unknown-tool",
|
||||
available_tools=["tool-1", "tool-2", "tool-3", "tool-4", "tool-5", "tool-6"],
|
||||
available_tools=[
|
||||
"tool-1",
|
||||
"tool-2",
|
||||
"tool-3",
|
||||
"tool-4",
|
||||
"tool-5",
|
||||
"tool-6",
|
||||
],
|
||||
)
|
||||
assert len(error.available_tools) == 6
|
||||
# Should show first 5 tools with ellipsis
|
||||
assert "available_tools=['tool-1', 'tool-2', 'tool-3', 'tool-4', 'tool-5']..." in str(error)
|
||||
assert (
|
||||
"available_tools=['tool-1', 'tool-2', 'tool-3', 'tool-4', 'tool-5']..."
|
||||
in str(error)
|
||||
)
|
||||
|
||||
|
||||
class TestMCPCircuitOpenError:
|
||||
|
||||
@@ -4,7 +4,7 @@ Tests for MCP Server Registry
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.mcp.config import MCPConfig, MCPServerConfig, TransportType
|
||||
from app.services.mcp.config import MCPConfig, MCPServerConfig
|
||||
from app.services.mcp.exceptions import MCPServerNotFoundError
|
||||
from app.services.mcp.registry import (
|
||||
MCPServerRegistry,
|
||||
|
||||
@@ -220,7 +220,9 @@ class TestScan:
|
||||
filter_all: ContentFilter,
|
||||
) -> None:
|
||||
"""Test scanning for specific categories only."""
|
||||
content = "Email: test@example.com, token: ghp_abc123456789012345678901234567890123"
|
||||
content = (
|
||||
"Email: test@example.com, token: ghp_abc123456789012345678901234567890123"
|
||||
)
|
||||
|
||||
# Scan only for secrets
|
||||
matches = await filter_all.scan(
|
||||
|
||||
@@ -321,8 +321,7 @@ class TestLoadRulesFromPolicy:
|
||||
validator.load_rules_from_policy(policy)
|
||||
|
||||
approval_rules = [
|
||||
r for r in validator._rules
|
||||
if r.decision == SafetyDecision.REQUIRE_APPROVAL
|
||||
r for r in validator._rules if r.decision == SafetyDecision.REQUIRE_APPROVAL
|
||||
]
|
||||
assert len(approval_rules) == 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user