Skip to content

Commit 49a3cde

Browse files
committed
fix: merge backtest config over DEFAULT_CONFIG so empty overrides work
1 parent 215ce9f commit 49a3cde

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

tests/test_backtest_harness.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,29 @@ def fake_factory(config):
134134
assert captured["config"]["memory_log_path"] is None
135135

136136

137+
@pytest.mark.unit
138+
def test_run_backtest_merges_defaults_when_config_is_empty_dict(monkeypatch):
139+
# Regression: the CLI passes config={} when no provider/model flags are
140+
# given; run_backtest must fall back to DEFAULT_CONFIG for every other key
141+
# instead of handing TradingAgentsGraph a one-key dict (#1234).
142+
captured = {}
143+
144+
def fake_factory(config):
145+
captured["config"] = config
146+
return _FakeGraph(config)
147+
148+
monkeypatch.setattr(backtest, "TradingAgentsGraph", fake_factory)
149+
df, _ = backtest.run_backtest(
150+
tickers=["NVDA"],
151+
dates=["2024-01-01"],
152+
config={},
153+
)
154+
assert len(df) == 1
155+
assert captured["config"]["data_cache_dir"]
156+
assert captured["config"]["llm_provider"]
157+
assert captured["config"]["memory_log_path"] is None
158+
159+
137160
@pytest.mark.unit
138161
def test_run_backtest_records_failures_and_continues(monkeypatch):
139162
monkeypatch.setattr(backtest, "TradingAgentsGraph", _FlakyGraph)

tradingagents/evaluation/backtest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ def run_backtest(
7777
Returns:
7878
``(results_df, markdown_summary)``.
7979
"""
80-
if config is None:
81-
cfg = DEFAULT_CONFIG.copy()
82-
cfg["memory_log_path"] = None
83-
else:
84-
cfg = dict(config)
85-
cfg.setdefault("memory_log_path", None)
80+
cfg = DEFAULT_CONFIG.copy()
81+
if config:
82+
cfg.update(config)
83+
# Backtests stay out of the persistent decision log unless the caller
84+
# explicitly opts in with a memory_log_path of their own.
85+
cfg["memory_log_path"] = (config or {}).get("memory_log_path")
8686

8787
graph = TradingAgentsGraph(config=cfg)
8888
rows: list[dict] = []

0 commit comments

Comments
 (0)