mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-06-29 19:26:24 +03:00
feat(reporting): share the report-tree writer between the CLI and the API
The per-section markdown report tree was written only by the CLI, so programmatic (TradingAgentsGraph) runs produced no saved reports. - Extract the writer into tradingagents/reporting.write_report_tree. - The CLI's save_report_to_disk delegates to it (no behavior change). - Add TradingAgentsGraph.save_reports(final_state, ticker) so headless/API callers get the same report tree, defaulting under results_dir.
This commit is contained in:
50
tests/test_reporting.py
Normal file
50
tests/test_reporting.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""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": {"judge_decision": "RM PLAN"},
|
||||
"trader_investment_plan": "TRADE",
|
||||
"risk_debate_state": {"judge_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_")
|
||||
Reference in New Issue
Block a user