"""An optional HTML copy of the report, for readers who do not open Markdown (#1419). It is one self-contained file: no script, no remote asset, nothing a report's text can inject; the Markdown report is unchanged. """ import re import pytest from tradingagents.reporting import write_report_tree SETTINGS = {"version": "1.2.3", "llm_provider": "openai", "deep_think_llm": "gpt-6-sol", "quick_think_llm": "gpt-6-luna", "analysts": ["market", "news"], "max_debate_rounds": 1, "max_risk_discuss_rounds": 1, "data_vendors": {"core_stock_apis": "yfinance"}} def _state(**overrides): state = {"trade_date": "2026-09-26", "market_report": "# Market view\n\nPrice | Level\n--- | ---\nClose | 181.2\n", "news_report": "News text.", "final_trade_decision": "**Rating**: Overweight\n\nAdd on weakness."} state.update(overrides) return state def _html(tmp_path, **overrides): write_report_tree(_state(**overrides), "NVDA", tmp_path, settings=SETTINGS, html=True) return (tmp_path / "complete_report.html").read_text(encoding="utf-8") @pytest.mark.unit def test_the_html_page_is_written_unless_declined(tmp_path): write_report_tree(_state(), "NVDA", tmp_path / "plain", settings=SETTINGS, html=False) assert not (tmp_path / "plain" / "complete_report.html").exists() write_report_tree(_state(), "NVDA", tmp_path / "default", settings=SETTINGS) assert (tmp_path / "default" / "complete_report.html").exists() page = _html(tmp_path / "html") assert "' in page and "181.2" in page @pytest.mark.unit def test_the_markdown_report_is_the_same_with_or_without_html(tmp_path): write_report_tree(_state(), "NVDA", tmp_path / "a", settings=SETTINGS, html=False) write_report_tree(_state(), "NVDA", tmp_path / "b", settings=SETTINGS) def undated(path): return re.sub(r"- Generated: .*\n", "", path.read_text(encoding="utf-8")) assert undated(tmp_path / "a" / "complete_report.md") == undated(tmp_path / "b" / "complete_report.md") @pytest.mark.unit def test_the_page_loads_nothing_and_runs_nothing(tmp_path): page = _html(tmp_path) assert "Content-Security-Policy" in page and "default-src 'none'" in page assert "alert(1) \n\n" "![pixel](https://tracker.example/p.png) [x](javascript:alert(1))") page = _html(tmp_path, news_report=hostile) assert "