mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-11-19 15:49:56 +02:00
fix(reporting): remove a previous run's sections when a report is saved to the same folder (#1566)
- write_report_tree deletes the section files and HTML page this run did not write; other files in the folder are kept
This commit is contained in:
@@ -49,6 +49,46 @@ def test_save_reports_explicit_path(tmp_path):
|
||||
assert out == tmp_path / "complete_report.md"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.parametrize("empty_value", [None, ""])
|
||||
def test_save_reports_replaces_previous_run_sections(tmp_path, empty_value):
|
||||
graph = SimpleNamespace(run_settings=lambda: SETTINGS)
|
||||
first = dict(_state(), trade_date="2026-09-22")
|
||||
TradingAgentsGraph.save_reports(graph, first, "AAPL", save_path=tmp_path)
|
||||
(tmp_path / "notes.md").write_text("User notes", encoding="utf-8")
|
||||
(tmp_path / "1_analysts" / "notes.md").write_text("Analyst notes", encoding="utf-8")
|
||||
|
||||
second = {
|
||||
"trade_date": "2026-09-23",
|
||||
"market_report": "NEW MARKET",
|
||||
"news_report": empty_value,
|
||||
"investment_debate_state": {"bull_history": empty_value},
|
||||
}
|
||||
out = TradingAgentsGraph.save_reports(graph, second, "AAPL", save_path=tmp_path)
|
||||
|
||||
assert (tmp_path / "1_analysts" / "market.md").read_text() == "NEW MARKET"
|
||||
for filename in (
|
||||
"1_analysts/news.md", "2_research/bull.md", "2_research/manager.md",
|
||||
"3_trading/trader.md", "4_risk/neutral.md", "5_portfolio/decision.md",
|
||||
):
|
||||
assert not (tmp_path / filename).exists()
|
||||
assert (tmp_path / "notes.md").read_text() == "User notes"
|
||||
assert (tmp_path / "1_analysts" / "notes.md").read_text() == "Analyst notes"
|
||||
assert "NEW MARKET" in out.read_text(encoding="utf-8")
|
||||
assert "NEWS" not in out.read_text(encoding="utf-8")
|
||||
assert "NEWS" not in (tmp_path / "complete_report.html").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_empty_report_removes_previous_sections_and_disabled_html(tmp_path):
|
||||
write_report_tree(_state(), "AAPL", tmp_path)
|
||||
out = write_report_tree({}, "AAPL", tmp_path, html=False)
|
||||
|
||||
assert list(tmp_path.rglob("*.md")) == [out]
|
||||
assert not (tmp_path / "complete_report.html").exists()
|
||||
assert "Trading Analysis Report: AAPL" in out.read_text()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_save_reports_defaults_under_results_dir(tmp_path):
|
||||
graph = object.__new__(TradingAgentsGraph)
|
||||
|
||||
Reference in New Issue
Block a user