Skip to content

Commit 5beaa53

Browse files
committed
Fix CI lint failures and CodeQL noise
- tests: split compound asserts (PT018), use pytest.raises (PT017), rename unused lambda params with _ prefix (ARG005). - sdk/base.py: drop redundant '...' from Protocol method bodies. - sdk/__init__.py: annotate substring URL match as intentional dispatch hint (endpoint is trusted operator config, not attacker input).
1 parent 16c8a53 commit 5beaa53

6 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/seclab_taskflow_agent/sdk/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def resolve_backend_name(
6666
the optional dependency is installed) > ``openai_agents``.
6767
"""
6868
name = explicit or os.getenv(_ENV_VAR)
69+
# lgtm[py/incomplete-url-substring-sanitization]
70+
# Endpoint is trusted operator config (YAML `endpoint:` / CAPI env),
71+
# not attacker-controlled input; this is a startup dispatch hint,
72+
# not a security boundary.
6973
if not name and endpoint and "api.githubcopilot.com" in endpoint:
7074
with contextlib.suppress(ImportError):
7175
__import__("copilot")

src/seclab_taskflow_agent/sdk/base.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ class AgentBackend(Protocol):
7878

7979
def validate(self, spec: AgentSpec) -> None:
8080
"""Reject any spec field the backend cannot honour."""
81-
...
8281

8382
async def build(
8483
self,
@@ -88,7 +87,6 @@ async def build(
8887
agent_hooks: Any = None,
8988
) -> Any:
9089
"""Construct a backend-native agent from a neutral spec."""
91-
...
9290

9391
def run_streamed(
9492
self,
@@ -98,8 +96,6 @@ def run_streamed(
9896
max_turns: int,
9997
) -> AsyncIterator[StreamEvent]:
10098
"""Run the agent against *prompt*, yielding neutral stream events."""
101-
...
10299

103100
async def aclose(self, agent: Any) -> None:
104101
"""Release any resources held by *agent*."""
105-
...

src/seclab_taskflow_agent/sdk/openai_agents/backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class OpenAIAgentsBackend:
5454
name = "openai_agents"
5555

5656
def validate(self, spec: AgentSpec) -> None:
57-
# The openai-agents adapter supports every YAML field this
58-
# runner exposes, so there's nothing to reject up front.
57+
# openai-agents accepts every field the YAML grammar exposes,
58+
# so there's nothing to reject up front.
5959
del spec
6060

6161
async def build(

tests/test_sdk_openai_adapter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ def run_streamed(self, prompt: str, *, max_turns: int): # noqa: ARG002
203203
return res
204204

205205
_collect(backend.run_streamed(_CapturingAgent(), "p", max_turns=1))
206-
assert captured and captured[0].cancel_called is True
206+
assert captured
207+
assert captured[0].cancel_called is True
207208

208209

209210
def test_aclose_closes_taskagent_client(backend):

tests/test_stream.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ async def on_tool_end(self, ctx: Any, agent: Any, tool: Any, result: Any) -> Non
3737
def test_bridge_emits_envelope_and_name():
3838
hooks = _RecordingHooks()
3939
asyncio.run(bridge_copilot_tool_event(ToolEnd(tool_name="echo", text="hi"), hooks))
40-
assert len(hooks.starts) == 1 and hooks.starts[0][2].name == "echo"
40+
assert len(hooks.starts) == 1
41+
assert hooks.starts[0][2].name == "echo"
4142
assert len(hooks.ends) == 1
4243
_, _, tool, payload = hooks.ends[0]
4344
assert tool.name == "echo"
@@ -93,13 +94,14 @@ async def _fake_render(text: str, **_kw: Any) -> None:
9394
_drive(backend, hooks)
9495

9596
assert "hi" in rendered
96-
assert hooks.ends and json.loads(hooks.ends[0][3]) == {"text": "r"}
97+
assert hooks.ends
98+
assert json.loads(hooks.ends[0][3]) == {"text": "r"}
9799

98100

99101
def test_drive_retries_then_succeeds_on_timeout(monkeypatch):
100102
monkeypatch.setattr(
101103
"seclab_taskflow_agent._stream.render_model_output",
102-
lambda *a, **kw: _noop(),
104+
lambda *_a, **_kw: _noop(),
103105
)
104106
backend = _ScriptedBackend([BackendTimeoutError("once"), [TextDelta(text="ok")]])
105107
_drive(backend, max_api_retry=2)
@@ -109,7 +111,7 @@ def test_drive_retries_then_succeeds_on_timeout(monkeypatch):
109111
def test_drive_raises_after_retries_exhausted(monkeypatch):
110112
monkeypatch.setattr(
111113
"seclab_taskflow_agent._stream.render_model_output",
112-
lambda *a, **kw: _noop(),
114+
lambda *_a, **_kw: _noop(),
113115
)
114116
backend = _ScriptedBackend([BackendTimeoutError("a"), BackendTimeoutError("b")])
115117
with pytest.raises(BackendTimeoutError):
@@ -119,7 +121,7 @@ def test_drive_raises_after_retries_exhausted(monkeypatch):
119121
def test_drive_caps_rate_limit_backoff(monkeypatch):
120122
monkeypatch.setattr(
121123
"seclab_taskflow_agent._stream.render_model_output",
122-
lambda *a, **kw: _noop(),
124+
lambda *_a, **_kw: _noop(),
123125
)
124126
sleeps: list[float] = []
125127

@@ -135,7 +137,8 @@ async def _fake_sleep(n: float) -> None:
135137
]
136138
)
137139
_drive(backend, initial_rate_limit_backoff=1, max_rate_limit_backoff=4)
138-
assert sleeps and all(s <= 4 for s in sleeps)
140+
assert sleeps
141+
assert all(s <= 4 for s in sleeps)
139142

140143

141144
async def _noop() -> None:
@@ -156,7 +159,7 @@ async def run_streamed(self, _agent: Any, _prompt: str, *, max_turns: int) -> An
156159
def test_drive_raises_on_stream_idle_timeout(monkeypatch):
157160
monkeypatch.setattr(
158161
"seclab_taskflow_agent._stream.render_model_output",
159-
lambda *a, **kw: _noop(),
162+
lambda *_a, **_kw: _noop(),
160163
)
161164
# Force a tiny idle timeout so the test runs quickly.
162165
monkeypatch.setattr("seclab_taskflow_agent._stream.STREAM_IDLE_TIMEOUT", 0.05)
@@ -182,7 +185,7 @@ def test_drive_raises_on_stream_idle_timeout(monkeypatch):
182185
def test_drive_pings_watchdog_per_event(monkeypatch):
183186
monkeypatch.setattr(
184187
"seclab_taskflow_agent._stream.render_model_output",
185-
lambda *a, **kw: _noop(),
188+
lambda *_a, **_kw: _noop(),
186189
)
187190
pings: list[int] = []
188191
monkeypatch.setattr(

tests/test_watchdog.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import time
99

10+
import pytest
11+
1012
from seclab_taskflow_agent import _watchdog
1113

1214

@@ -38,8 +40,7 @@ def _fake_exit(code: int) -> None:
3840
# Simulate a stale timestamp so the first iteration decides to exit.
3941
monkeypatch.setattr(_watchdog, "_last_activity", time.monotonic() - 10_000)
4042

41-
try:
43+
with pytest.raises(SystemExit) as excinfo:
4244
_watchdog._watchdog_loop(timeout=1)
43-
except SystemExit as exc:
44-
assert exc.code == 2
45+
assert excinfo.value.code == 2
4546
assert exits == [2]

0 commit comments

Comments
 (0)