From 291a8108e1fd06739d156a8739e6289d19c140cd Mon Sep 17 00:00:00 2001 From: iomgaa Date: Sat, 11 Jul 2026 08:48:04 -0400 Subject: [PATCH] test(agent): tighten type annotations in step-retry tests --- tests/unit/test_agent_loop.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_agent_loop.py b/tests/unit/test_agent_loop.py index b7e3c5b..3ca244b 100644 --- a/tests/unit/test_agent_loop.py +++ b/tests/unit/test_agent_loop.py @@ -314,14 +314,16 @@ class TestParseNormalization: class TestStepLevelRetry: """LLM 瞬时异常的步级重试:可重试元组 / 退避 / fail-fast。""" - def _make_loop(self, chat_side_effects: list) -> AgentLoop: + def _make_loop(self, chat_side_effects: list[object]) -> AgentLoop: """构造 chat 按序抛异常/返回响应的 AgentLoop。""" llm = AsyncMock() llm.chat = AsyncMock(side_effect=chat_side_effects) return AgentLoop(llm=llm, max_steps=10) @pytest.mark.asyncio - async def test_transient_error_retried_then_succeeds(self, monkeypatch) -> None: + async def test_transient_error_retried_then_succeeds( + self, monkeypatch: pytest.MonkeyPatch + ) -> None: """SSL/超时瞬时异常按 20s/40s 退避重试,第三次成功 → finished。""" delays: list[float] = [] @@ -341,7 +343,9 @@ class TestStepLevelRetry: assert delays == [20.0, 40.0] @pytest.mark.asyncio - async def test_retry_exhausted_terminates_with_error(self, monkeypatch) -> None: + async def test_retry_exhausted_terminates_with_error( + self, monkeypatch: pytest.MonkeyPatch + ) -> None: """重试预算(首次 + 2 次)耗尽仍失败 → stop_reason=error。""" async def _fake_sleep(seconds: float) -> None: @@ -354,7 +358,7 @@ class TestStepLevelRetry: assert loop._llm.chat.await_count == 3 # 首次 + 2 次重试 @pytest.mark.asyncio - async def test_non_retryable_fails_fast(self, monkeypatch) -> None: + async def test_non_retryable_fails_fast(self, monkeypatch: pytest.MonkeyPatch) -> None: """非可重试异常不退避不重发,首次即终止 → stop_reason=error。""" sleep_mock = AsyncMock() monkeypatch.setattr("core.agent.loop.asyncio.sleep", sleep_mock) @@ -365,7 +369,9 @@ class TestStepLevelRetry: assert loop._llm.chat.await_count == 1 @pytest.mark.asyncio - async def test_exhaustion_raises_last_original_exception(self, monkeypatch) -> None: + async def test_exhaustion_raises_last_original_exception( + self, monkeypatch: pytest.MonkeyPatch + ) -> None: """耗尽语义窄测试:_call_llm_with_step_retry 耗尽后原样抛出最后一次异常。""" async def _fake_sleep(seconds: float) -> None: