diff --git a/scripts/execution_report_heartbeat.py b/scripts/execution_report_heartbeat.py index 7e4bd7e..7116592 100644 --- a/scripts/execution_report_heartbeat.py +++ b/scripts/execution_report_heartbeat.py @@ -60,7 +60,9 @@ def _month_segments(start: dt.datetime, end: dt.datetime) -> list[str]: cursor = dt.datetime(start.year, start.month, 1, tzinfo=dt.timezone.utc) end_cursor = dt.datetime(end.year, end.month, 1, tzinfo=dt.timezone.utc) while cursor <= end_cursor: - months.append(f"{cursor.year:04d}-{cursor.month:02d}") + month = f"{cursor.year:04d}-{cursor.month:02d}" + months.append(month) + months.append(month.replace("-", "_")) if cursor.month == 12: cursor = dt.datetime(cursor.year + 1, 1, 1, tzinfo=dt.timezone.utc) else: diff --git a/tests/test_execution_report_heartbeat.py b/tests/test_execution_report_heartbeat.py new file mode 100644 index 0000000..a81da14 --- /dev/null +++ b/tests/test_execution_report_heartbeat.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +import datetime as dt + +from scripts import execution_report_heartbeat as heartbeat + + +def test_report_globs_include_sanitized_month_segments(monkeypatch): + monkeypatch.delenv("RUNTIME_HEARTBEAT_GCS_GLOBS", raising=False) + monkeypatch.delenv("EXECUTION_REPORT_GCS_URI", raising=False) + monkeypatch.delenv("RUNTIME_HEARTBEAT_GCS_URIS", raising=False) + monkeypatch.delenv("RUNTIME_HEARTBEAT_REPORT_PLATFORM", raising=False) + monkeypatch.setenv("FIRSTRADE_GCS_STATE_BUCKET", "runtime-state") + monkeypatch.setenv("FIRSTRADE_STATE_PREFIX", "firstrade-platform") + + globs = heartbeat._report_globs( + dt.datetime(2026, 5, 31, tzinfo=dt.timezone.utc), + dt.datetime(2026, 6, 1, tzinfo=dt.timezone.utc), + ) + + assert globs == [ + "gs://runtime-state/firstrade-platform/strategy-runs/**/2026-05/*.json", + "gs://runtime-state/firstrade-platform/strategy-runs/**/2026_05/*.json", + "gs://runtime-state/firstrade-platform/strategy-runs/**/2026-06/*.json", + "gs://runtime-state/firstrade-platform/strategy-runs/**/2026_06/*.json", + ]