Skip to content

Commit ed52d3c

Browse files
committed
Clear Sonar security hotspots and tighten Codacy suppressions
- vision/_parse.py: rewrite the coord regex as a single unambiguous alternation (``\s*,\s*`` | ``\s+``) so Sonar S5852 stops flagging polynomial-backtracking risk; behaviour unchanged on covered cases - test_run_history: route artifact paths through the ``tmp_path`` fixture instead of hard-coded ``/tmp/*`` literals, eliminating the five S5443 "publicly writable directory" hotspots without changing test intent - utils/xml/__init__.py: call ``defusedxml.defuse_stdlib()`` on import so every stdlib xml parser used anywhere in the package is replaced by the safe variant — closes the remaining Bandit B314/B318 nags - platform_wrapper: add an explicit ``__all__`` listing the facade re-exports so Prospector/pyflakes stop reporting ``keyboard_check`` as unused (F401) - .codacy.yaml: also exclude ``test/**`` from Prospector and drop the manual/gui smoke scripts from analysis so pytest-style imports and assertions stop lighting up PR runs
1 parent ea354a7 commit ed52d3c

5 files changed

Lines changed: 36 additions & 8 deletions

File tree

.codacy.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ engines:
99
# Test code legitimately uses `assert` (B101); pytest depends on it.
1010
# Library/non-test code is constrained by CLAUDE.md "no assert outside tests".
1111
- "test/**"
12+
prospector:
13+
enabled: true
14+
exclude_paths:
15+
- "test/**"
1216

1317
# Drop generated docs / build outputs from analysis entirely.
1418
exclude_paths:
1519
- "docs/build/**"
1620
- ".venv/**"
1721
- "build/**"
1822
- "dist/**"
23+
# One-off GUI smoke scripts — not library code, not pytest targets.
24+
- "test/gui_test/**"
25+
- "test/manual_test/**"

je_auto_control/utils/vision/backends/_parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33
from typing import Optional, Tuple
44

5-
_COORDS_RE = re.compile(r"(-?\d{1,5})\s*[,\s]\s*(-?\d{1,5})")
5+
_COORDS_RE = re.compile(r"(-?\d{1,5})(?:\s*,\s*|\s+)(-?\d{1,5})")
66

77

88
def parse_coords(text: str) -> Optional[Tuple[int, int]]:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""XML helpers.
2+
3+
Calling ``defusedxml.defuse_stdlib()`` at import time monkey-patches the
4+
stdlib XML parsers (xml.etree.ElementTree, xml.dom.minidom, xml.sax, ...)
5+
so any subsequent parsing in this package — including accidental imports
6+
by third-party code — is XXE/billion-laughs safe. We still prefer the
7+
explicit ``defusedxml`` API in our own modules for clarity.
8+
"""
9+
import defusedxml
10+
11+
defusedxml.defuse_stdlib()

je_auto_control/wrapper/platform_wrapper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@
2525

2626
if None in [keyboard_keys_table, mouse_keys_table, keyboard, mouse, screen]:
2727
raise AutoControlException("Can't init auto control")
28+
29+
30+
__all__ = [
31+
"keyboard", "keyboard_check", "keyboard_keys_table",
32+
"mouse", "mouse_keys_table", "special_mouse_keys_table",
33+
"screen", "recorder",
34+
]

test/unit_test/headless/test_run_history.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,23 @@ def test_executor_history_commands(monkeypatch, store):
169169
assert rows and rows[0]["source_type"] == SOURCE_SCHEDULER
170170

171171

172-
def test_finish_run_persists_artifact_path(store):
172+
def test_finish_run_persists_artifact_path(tmp_path, store):
173+
artifact = str(tmp_path / "x.png")
173174
run_id = store.start_run(SOURCE_SCHEDULER, "j", "s.json")
174175
store.finish_run(run_id, STATUS_ERROR, error_text="boom",
175-
artifact_path="/tmp/x.png")
176+
artifact_path=artifact)
176177
record = store.get_run(run_id)
177-
assert record.artifact_path == "/tmp/x.png"
178+
assert record.artifact_path == artifact
178179

179180

180-
def test_attach_artifact_updates_existing_row(store):
181+
def test_attach_artifact_updates_existing_row(tmp_path, store):
182+
attached = str(tmp_path / "snap.png")
183+
missing = str(tmp_path / "a.png")
181184
run_id = store.start_run(SOURCE_HOTKEY, "h", "s.json")
182185
store.finish_run(run_id, STATUS_ERROR, error_text="oops")
183-
assert store.attach_artifact(run_id, "/tmp/snap.png") is True
184-
assert store.get_run(run_id).artifact_path == "/tmp/snap.png"
185-
assert store.attach_artifact(99999, "/tmp/a.png") is False
186+
assert store.attach_artifact(run_id, attached) is True
187+
assert store.get_run(run_id).artifact_path == attached
188+
assert store.attach_artifact(99999, missing) is False
186189

187190

188191
def test_clear_removes_artifact_files(tmp_path, store):

0 commit comments

Comments
 (0)