Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
test(agent): cover turn hook ordering
chengyongru04dbf1742659
diff --git a/tests/agent/test_turn_hooks.py b/tests/agent/test_turn_hooks.pyindex aaf4dd4a1..8ea458bf4 100644--- a/tests/agent/test_turn_hooks.py+++ b/tests/agent/test_turn_hooks.py@@ -5,12 +5,13 @@ from nanobot.agent.turn_hooks import AgentTurnHookSpec, build_agent_turn_hookclass RecordingHook(AgentHook):- def __init__(self, events: list[str]) -> None:+ def __init__(self, events: list[str], label: str = "hook") -> None:super().__init__()self._events = events+ self._label = labelasync def before_iteration(self, context: AgentHookContext) -> None:- self._events.append(f"hook:{context.iteration}")+ self._events.append(f"{self._label}:{context.iteration}")@pytest.mark.asyncio@@ -27,6 +28,21 @@ async def test_turn_hook_builder_runs_progress_hook_before_extra_hooks() -> Noneassert events == ["progress:2", "hook:2"]+async def test_turn_hook_builder_runs_registered_hooks_before_turn_hooks() -> None:+ events: list[str] = []++ hook = build_agent_turn_hook(AgentTurnHookSpec(+ on_iteration=lambda iteration: events.append(f"progress:{iteration}"),+ registered_hooks=[RecordingHook(events, "registered")],+ turn_hooks=[RecordingHook(events, "turn")],+ ))++ await hook.before_iteration(AgentHookContext(iteration=2, messages=[]))++ assert events == ["progress:2", "registered:2", "turn:2"]++@pytest.mark.asyncioasync def test_turn_hook_builder_skips_extra_hooks_for_ephemeral_turns_by_default() -> None:events: list[str] = []