Skip to content

Commit ccdc7aa

Browse files
OriNachumclaude
andauthored
fix: resolve SonarCloud quality gate failures (#50)
* fix: resolve SonarCloud quality gate failures Remove legacy dead code files (server.py, mcp-chatbot-client.py, is_mcp_tool.py) that caused 720+ duplicated lines and contributed 5 bugs and 6 vulnerabilities. Fix async bugs in mcp_manager.py (sync file I/O in async context, CancelledError not re-raised). Add nosec annotations for intentional bandit findings in CLI/config. Coverage: 51.7% → 90.5% | Duplication: 17.5% → ~0% Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: import config from centralized module in cli.py Use API_ADAPTER_HOST and API_ADAPTER_PORT from common/config.py instead of reading os.environ directly, per reviewer feedback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 53368c7 commit ccdc7aa

File tree

8 files changed

+12
-1757
lines changed

8 files changed

+12
-1757
lines changed

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ asyncio_mode = "auto"
5858

5959
[tool.coverage.run]
6060
source = ["open_responses_server"]
61-
omit = [
62-
"src/open_responses_server/server.py",
63-
"src/open_responses_server/mcp-chatbot-client.py",
64-
"src/open_responses_server/is_mcp_tool.py",
65-
]
61+
omit = []
6662

6763
[tool.coverage.report]
6864
show_missing = true

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sonar.python.coverage.reportPaths=coverage.xml
2020
sonar.python.xunit.reportPath=test-results.xml
2121

2222
# Exclude patterns
23-
sonar.exclusions=**/*.pyc,**/__pycache__/**,**/tests/**,**/test_*.py,**/*.db
23+
sonar.exclusions=**/*.pyc,**/__pycache__/**,**/tests/**,**/test_*.py,**/*.db,docs/prompts/**
2424

2525
# Security-related settings
2626
sonar.python.bandit.reportPaths=bandit-results.json

src/open_responses_server/cli.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

33
import argparse
4-
import subprocess
4+
import subprocess # nosec B404 - subprocess needed for CLI server management
55
import os
66
import json
77
import sys
@@ -11,15 +11,17 @@
1111
# Load environment variables from .env file
1212
load_dotenv()
1313

14+
from open_responses_server.common.config import API_ADAPTER_HOST, API_ADAPTER_PORT
15+
1416
# Configure logging
1517
logging.basicConfig(
1618
level=logging.INFO,
1719
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
1820
)
1921
logger = logging.getLogger("otc_cli")
2022

21-
DEFAULT_HOST = os.environ.get("API_ADAPTER_HOST", "0.0.0.0")
22-
DEFAULT_PORT = os.environ.get("API_ADAPTER_PORT", "8080")
23+
DEFAULT_HOST = API_ADAPTER_HOST
24+
DEFAULT_PORT = str(API_ADAPTER_PORT)
2325

2426
def start_server(host=DEFAULT_HOST, port=DEFAULT_PORT):
2527
"""Starts the FastAPI server."""
@@ -38,7 +40,7 @@ def start_server(host=DEFAULT_HOST, port=DEFAULT_PORT):
3840
logger.error(f"Error importing server module: {e}")
3941
logger.info("Trying to start server using subprocess...")
4042
try:
41-
subprocess.run(
43+
subprocess.run( # nosec B603 B607 - trusted command with controlled arguments
4244
["uvicorn", "open_responses_server.server_entrypoint:app", "--host", host, "--port", str(port)],
4345
check=True
4446
)

src/open_responses_server/common/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
OPENAI_BASE_URL_INTERNAL = os.environ.get("OPENAI_BASE_URL_INTERNAL", "http://localhost:8000")
1212
OPENAI_BASE_URL = os.environ.get("OPENAI_BASE_URL", "http://localhost:8080")
1313
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "dummy-key")
14-
API_ADAPTER_HOST = os.environ.get("API_ADAPTER_HOST", "0.0.0.0")
14+
API_ADAPTER_HOST = os.environ.get("API_ADAPTER_HOST", "0.0.0.0") # nosec B104 - server must bind all interfaces
1515
API_ADAPTER_PORT = int(os.environ.get("API_ADAPTER_PORT", "8080"))
1616

1717
# MCP Configuration

src/open_responses_server/common/mcp_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ async def startup_mcp_servers(self):
201201
logger.info(f"[MCP-STARTUP] Loading MCP server configuration from: {config_path}")
202202

203203
try:
204-
with open(config_path) as f:
205-
cfg = json.load(f)
204+
content = await asyncio.to_thread(config_path.read_text)
205+
cfg = json.loads(content)
206206

207207
server_configs = cfg.get("mcpServers", {})
208208
logger.info(f"[MCP-STARTUP] Found {len(server_configs)} server configurations: {list(server_configs.keys())}")
@@ -306,7 +306,7 @@ async def _mcp_refresh_loop(self) -> None:
306306
await self._refresh_mcp_functions()
307307
except asyncio.CancelledError:
308308
logger.info("[MCP-REFRESH] Background refresh task cancelled")
309-
break
309+
raise
310310
except Exception as e:
311311
logger.error(f"[MCP-REFRESH] Error in background refresh: {e}")
312312

src/open_responses_server/is_mcp_tool.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)