Files
tradingagents/tests/test_reporting.py
T
Yijia-Xiao cf960d6382 refactor: one name per decision in the state and its log
- the Research Manager's plan and the Portfolio Manager's decision live only in investment_plan and final_trade_decision; the debate states no longer copy them as judge_decision
- the saved state log writes the Trader's plan as trader_investment_plan, its state key
- the report tree, the final display and the live CLI read the decisions from those fields
2026-09-24 19:38:41 +00:00

53 lines
2.0 KiB
Python

"""Report parity: the shared writer produces the report tree for the CLI and the
programmatic API alike (#1037)."""
from types import SimpleNamespace
import pytest
from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.reporting import write_report_tree
def _state():
return {
"market_report": "MKT",
"news_report": "NEWS",
"investment_debate_state": {"bull_history": "BULL"},
"investment_plan": "RM PLAN",
"trader_investment_plan": "TRADE",
"risk_debate_state": {"neutral_history": "NEUTRAL"},
"final_trade_decision": "PM DECISION",
}
@pytest.mark.unit
def test_write_report_tree_creates_files(tmp_path):
out = write_report_tree(_state(), "AAPL", tmp_path)
assert out.name == "complete_report.md"
assert (tmp_path / "1_analysts" / "market.md").read_text() == "MKT"
assert (tmp_path / "1_analysts" / "news.md").read_text() == "NEWS"
assert (tmp_path / "2_research" / "manager.md").read_text() == "RM PLAN"
assert (tmp_path / "3_trading" / "trader.md").read_text() == "TRADE"
assert (tmp_path / "5_portfolio" / "decision.md").read_text() == "PM DECISION"
complete = out.read_text()
assert "Trading Analysis Report: AAPL" in complete
assert "MKT" in complete and "PM DECISION" in complete
@pytest.mark.unit
def test_save_reports_explicit_path(tmp_path):
# Unbound: with an explicit save_path, the method doesn't touch self/config.
out = TradingAgentsGraph.save_reports(None, _state(), "AAPL", save_path=tmp_path)
assert (tmp_path / "complete_report.md").exists()
assert out == tmp_path / "complete_report.md"
@pytest.mark.unit
def test_save_reports_defaults_under_results_dir(tmp_path):
mock_self = SimpleNamespace(config={"results_dir": str(tmp_path)})
out = TradingAgentsGraph.save_reports(mock_self, _state(), "AAPL")
assert out.exists()
assert out.parent.parent.name == "reports" # results_dir/reports/AAPL_<stamp>/...
assert out.parent.name.startswith("AAPL_")