"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
test(session): verify configured iteration limit reaches agent execution
Haozhe Wuf86fc97e759e
diff --git a/agent/.env.example b/agent/.env.exampleindex 990f90dac..64b927d0b 100644--- a/agent/.env.example+++ b/agent/.env.example@@ -348,8 +348,9 @@ TUSHARE_TOKEN=your-tushare-token# whatever the window (real tokens):# VIBE_TRADING_CONTEXT_MAX_TOKENS=200000# TOKEN_THRESHOLD is deprecated and ignored (it counted chars/4 of the messages-# VIBE_TRADING_AGENT_MAX_ITERATIONS=100 # ReAct loop iteration cap for web/interactive sessions (default 50); raise for heavy multi-step pipelines# without tool schemas); remove it from your .env.+# ReAct iteration cap for session-based research (default 50).+# VIBE_TRADING_AGENT_MAX_ITERATIONS=100# Hard timeout (seconds) for read-only tool execution; write tools only warn.# Default 1800; set 0 to disable.# VIBE_TRADING_TOOL_TIMEOUT_SECONDS=1800diff --git a/agent/tests/test_env_schema.py b/agent/tests/test_env_schema.pyindex 0f1c98142..d50037952 100644--- a/agent/tests/test_env_schema.py+++ b/agent/tests/test_env_schema.py@@ -69,6 +69,21 @@ def _clean_env(monkeypatch: pytest.MonkeyPatch) -> None:# ===================================================================[email protected]("value", ["0", "-1"])+def test_session_iteration_cap_rejects_nonpositive_values(monkeypatch, value: str) -> None:+ """A nonpositive cap must not silently become an unlimited loop."""+ monkeypatch.setenv("VIBE_TRADING_AGENT_MAX_ITERATIONS", value)+ with pytest.raises(ValidationError):+ get_env_config()++[email protected]("value", ["2.5", "invalid"])+def test_session_iteration_cap_uses_safe_default_for_malformed_env(monkeypatch, value: str) -> None:+ """Unparseable env values follow the shared numeric-default contract."""+ monkeypatch.setenv("VIBE_TRADING_AGENT_MAX_ITERATIONS", value)+ assert get_env_config().agent_tuning.vibe_trading_agent_max_iterations == 50++class TestEnvConfigDefaults:"""Verify every field defaults correctly when no env vars are set."""diff --git a/agent/tests/test_session_service_mcp.py b/agent/tests/test_session_service_mcp.pyindex a9a913b94..86d1e5563 100644--- a/agent/tests/test_session_service_mcp.py+++ b/agent/tests/test_session_service_mcp.py@@ -6,6 +6,8 @@ import asyncioimport timefrom pathlib import Path+import pytest+from src.session.events import EventBusfrom src.session.models import Attemptfrom src.session.service import SessionService@@ -29,10 +31,24 @@ class _DummyAgentLoop:return {"status": "completed"}[email protected](("configured_cap", "expected_cap"), [(None, 50), ("73", 73)])def test_run_with_agent_keeps_event_loop_responsive_during_registry_build(monkeypatch,tmp_path: Path,+ configured_cap: str | None,+ expected_cap: int,) -> None:+ monkeypatch.setattr("src.config.accessor._instance", None)+ if configured_cap is None:+ monkeypatch.delenv("VIBE_TRADING_AGENT_MAX_ITERATIONS", raising=False)+ else:+ monkeypatch.setenv("VIBE_TRADING_AGENT_MAX_ITERATIONS", configured_cap)+ received_caps: list[int] = []++ def _agent_factory(**kwargs):+ received_caps.append(kwargs["max_iterations"])+ return _DummyAgentLoop(**kwargs)+def _slow_build_registry(**kwargs):del kwargstime.sleep(0.25)@@ -42,7 +58,7 @@ def test_run_with_agent_keeps_event_loop_responsive_during_registry_build(monkeypatch.setattr("src.tools.build_registry", _slow_build_registry)monkeypatch.setattr("src.providers.chat.ChatLLM", lambda: object())monkeypatch.setattr("src.memory.persistent.PersistentMemory", lambda: object())- monkeypatch.setattr("src.agent.loop.AgentLoop", _DummyAgentLoop)+ monkeypatch.setattr("src.agent.loop.AgentLoop", _agent_factory)monkeypatch.setattr("src.config.loader.load_runtime_agent_config", lambda overrides=None: object())monkeypatch.setattr("src.config.loader.sanitize_session_overrides", lambda overrides: dict(overrides))@@ -68,5 +84,6 @@ def test_run_with_agent_keeps_event_loop_responsive_during_registry_build(tick_times, result = asyncio.run(_exercise())assert result["status"] == "completed"+ assert received_caps == [expected_cap]assert tick_times, "Expected the event loop ticker to run while registry build was pending"- assert tick_times[0] < 0.18, f"Registry build blocked the event loop for too long: {tick_times[0]:.3f}s"\ No newline at end of file+ assert tick_times[0] < 0.18, f"Registry build blocked the event loop for too long: {tick_times[0]:.3f}s"