fix(backtest): give each sweep started without a run_id its own run (#1549)

- the stamped run directory is claimed atomically; a second sweep in the same second takes the next suffix instead of resuming the first
This commit is contained in:
Yijia-Xiao
2026-10-27 07:58:10 +00:00
parent 1c0e3e37fc
commit 28d32653d3
2 changed files with 40 additions and 5 deletions
+17
View File
@@ -155,6 +155,23 @@ def test_the_analyst_set_under_test_is_the_one_that_runs(tmp_path):
assert _FakeGraph.instances[-1].analysts == ["market", "news"]
@pytest.mark.unit
def test_sweeps_started_in_the_same_second_get_their_own_runs(tmp_path, monkeypatch):
import tradingagents.backtest as backtest
class _Frozen(backtest.datetime):
@classmethod
def now(cls, tz=None):
return cls(2026, 1, 20, 9, 30, 0)
monkeypatch.setattr(backtest, "datetime", _Frozen)
first = run_backtest(["NVDA"], ["2026-01-05"], _config(tmp_path))
second = run_backtest(["NVDA"], ["2026-01-05"], _config(tmp_path))
assert first.run_id == "20260120_093000" and second.run_id == "20260120_093000_2"
assert first.cells_run == second.cells_run == 1
@pytest.mark.unit
def test_a_run_id_cannot_escape_the_results_directory(tmp_path):
"""run_id becomes a path segment, so it is validated like a ticker is."""