fix(cli): write the state log, and name the analysts as users know them

- record_decision writes the run's state log, so CLI runs save full_states_log like propagate() does
- with both round counts from the environment, the CLI no longer says a chosen research depth was overridden
- an unknown --analysts name lists sentiment, not social
This commit is contained in:
Yijia-Xiao
2026-09-29 05:57:17 +00:00
parent 9968bd8dd1
commit 9470b92150
6 changed files with 70 additions and 19 deletions
+22 -1
View File
@@ -38,7 +38,7 @@ class TestFlagValues:
def test_analysts_are_named_and_checked_against_the_asset(self):
assert prompts.parse_analysts(" Market, news ", AssetType.STOCK) == [AnalystType.MARKET, AnalystType.NEWS]
with pytest.raises(ValueError, match="market, social, news, fundamentals"):
with pytest.raises(ValueError, match="market, sentiment, news, fundamentals"):
prompts.parse_analysts("market,macro", AssetType.STOCK)
with pytest.raises(ValueError, match="crypto"):
prompts.parse_analysts("fundamentals", AssetType.CRYPTO)
@@ -160,3 +160,24 @@ def test_a_closed_stdin_counts_as_no_terminal(monkeypatch, capsys):
with pytest.raises(typer.Exit):
run.run_analysis(flags={})
assert "--ticker" in capsys.readouterr().out
@pytest.mark.unit
def test_rounds_from_the_environment_do_not_claim_a_depth_was_chosen(monkeypatch, capsys):
"""With both round counts set, the depth question never appeared."""
monkeypatch.setenv("TRADINGAGENTS_MAX_DEBATE_ROUNDS", "1")
monkeypatch.setenv("TRADINGAGENTS_MAX_RISK_ROUNDS", "1")
selections = {"research_depth": 3, "quick_think_llm": "q", "deep_think_llm": "d", "backend_url": None,
"llm_provider": "openai", "google_thinking_level": None, "openai_reasoning_effort": None,
"anthropic_effort": None, "output_language": "English"}
run._build_run_config(selections, None)
assert "the research depth you chose" not in capsys.readouterr().out
@pytest.mark.unit
def test_an_unknown_analyst_error_names_the_analysts_as_users_know_them():
with pytest.raises(ValueError) as caught:
prompts.parse_analysts("macro", AssetType.STOCK)
assert "sentiment" in str(caught.value) and "social" not in str(caught.value)
+24
View File
@@ -21,6 +21,7 @@ def _bare_graph(tmp_path):
graph = object.__new__(TradingAgentsGraph)
graph.config = {"memory_log_path": str(tmp_path / "trading_memory.md")}
graph.memory_log = TradingMemoryLog(graph.config)
graph._log_state = lambda *a: None # these tests are about the memory log
return graph
@@ -187,3 +188,26 @@ def test_a_run_without_checkpointing_says_nothing_about_resuming(tmp_path, monke
buffer = _run_cli(monkeypatch, tmp_path, _FakeGraph())
assert not any("resum" in text.lower() or "fresh" in text.lower() for _, _, text in buffer.messages)
@pytest.mark.unit
def test_recording_a_run_writes_its_state_log(tmp_path):
"""The CLI records a run through record_decision, so the state log is written there."""
graph = object.__new__(TradingAgentsGraph)
graph.config = {"results_dir": str(tmp_path), "llm_provider": "openai", "deep_think_llm": "d",
"quick_think_llm": "q", "max_debate_rounds": 1, "max_risk_discuss_rounds": 1,
"output_language": "English", "data_vendors": {}, "tool_vendors": {}}
graph.selected_analysts = ("market",)
graph.memory_log = TradingMemoryLog({"memory_log_path": str(tmp_path / "m.md")})
state = {"company_of_interest": "NVDA", "trade_date": "2026-09-23", "market_report": "M",
"sentiment_report": "", "news_report": "", "fundamentals_report": "",
"investment_debate_state": {"bull_history": "", "bear_history": "", "history": "",
"current_response": ""},
"trader_investment_plan": "T", "investment_plan": "P",
"risk_debate_state": {"aggressive_history": "", "conservative_history": "",
"neutral_history": "", "history": ""},
"final_trade_decision": "**Rating**: Hold", "final_rating": "Hold"}
graph.record_decision("NVDA", "2026-09-23", state)
assert list(tmp_path.glob("NVDA/TradingAgentsStrategy_logs/full_states_log_2026-09-23.json"))