Skip to content

Commit 6d72a07

Browse files
committed
Close remaining Sonar + Codacy findings on PR #194
Sonar (3 left after the previous pass): - LSP run() complexity dropped from 16→<10 by extracting _build_reply() and collapsing the request==None / method==exit guards into one branch (python:S3776). - Dockerfile: merged the chmod + user-creation RUN layers so docker:S7031 is satisfied without extra image layers. - test_acme_v2: chained endswith → tuple form (python:S8513). Codacy: - Real bug: connection_screen called send_magic_packet(broadcast=...) but the wake_on_lan signature is broadcast_address=. Fixed. - Real bug: examples 03/11/12 called default_scheduler() / default_hotkey_daemon() / default_trigger_engine() but those are module-level instances, not factories. Dropped the parens. - autocontrol-lsp/vscode/package-lock.json: generated via ``npm install --package-lock-only`` so dependencies are reproducible (text:S8564 / Codacy lockfile rule). False positives — tool-specific suppressions with reason: - Semgrep dangerous-subprocess-use-audit in adb_client.py + tls_acme/ challenge.py + test_android_adb.py (Bandit B603 already justifies; the argv list is hard-coded / shutil.which-resolved). - Semgrep request-data-write in usbip/libusb_backend.py (rule expects a Django filesystem path; this is libusb's bulk-out endpoint write). - Semgrep openai.import-without-guardrails in agent/backends/openai.py (Guardrails is an unrelated content-filter SDK; safety is handled at the action-executor allowlist + audit layer). - Bandit B105 hardcoded-password in examples/16_secrets.py + B310 url-open in examples/06_observability.py + examples/15_rest_api.py (demo strings + loopback URLs). - Pylint W0622 ``format`` shadow in two ``log_message`` overrides (the parameter name comes from BaseHTTPRequestHandler — we can't rename it without breaking the protocol).
1 parent e57a8d6 commit 6d72a07

17 files changed

Lines changed: 611 additions & 30 deletions

File tree

autocontrol-lsp/autocontrol_lsp/server/server.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,35 @@ def _write_message(stream, message: Dict[str, Any]) -> None:
8282
stream.flush()
8383

8484

85+
def _build_reply(method, request_id, result) -> Dict[str, Any]:
86+
reply: Dict[str, Any] = {"jsonrpc": "2.0", "id": request_id}
87+
if result is None:
88+
reply["error"] = {
89+
"code": -32601, "message": f"method not found: {method}",
90+
}
91+
else:
92+
reply["result"] = result
93+
return reply
94+
95+
8596
def run(input_stream=None, output_stream=None) -> int:
8697
"""Run the LSP loop. Returns 0 on clean shutdown, 1 on transport error."""
8798
inp = input_stream or sys.stdin.buffer
8899
out = output_stream or sys.stdout.buffer
89100
try:
90101
while True:
91102
request = _read_message(inp)
92-
if request is None:
103+
if request is None or request.get("method") == "exit":
93104
return 0
94105
method = request.get("method")
95-
if method == "exit":
96-
return 0
97106
params = request.get("params") or {}
98107
result = (
99108
_dispatch(method, params) if isinstance(method, str) else None
100109
)
101110
request_id = request.get("id")
102111
if request_id is None:
103112
continue # notification; no response needed
104-
reply: Dict[str, Any] = {"jsonrpc": "2.0", "id": request_id}
105-
if result is None:
106-
reply["error"] = {
107-
"code": -32601, "message": f"method not found: {method}",
108-
}
109-
else:
110-
reply["result"] = result
111-
_write_message(out, reply)
113+
_write_message(out, _build_reply(method, request_id, result))
112114
except (OSError, ValueError):
113115
return 1
114116

0 commit comments

Comments
 (0)