From a12dc8a7681fd43abc1e7d0de95b449348f50259 Mon Sep 17 00:00:00 2001 From: momentum dev Date: Tue, 14 Jul 2026 00:36:00 -0400 Subject: [PATCH] test: de-flake volume-ratio test (real-clock dead zone, not plan 007) compute_ratios bails when UTC now-16min precedes today's 08:00Z, i.e. nightly ~00:00-04:16 ET; the test's hardcoded 2026-07-06 bars made it KeyError at the date rollover independent of any code change. Freeze the module clock to a mid-session UTC time so the window is valid deterministically. Co-Authored-By: Claude Fable 5 --- tests/unit/test_volume_ratio.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_volume_ratio.py b/tests/unit/test_volume_ratio.py index 0d882a3..511d666 100644 --- a/tests/unit/test_volume_ratio.py +++ b/tests/unit/test_volume_ratio.py @@ -32,7 +32,26 @@ class _Con: return self -def test_compute_ratios_measures_and_skips_thin(): +def test_compute_ratios_measures_and_skips_thin(monkeypatch): + # Freeze the clock inside the stub's bar-date window. compute_ratios bails + # (`end <= start`) when UTC now-16min is before today's 08:00Z — true nightly + # from ~00:00-04:16 ET — so with hardcoded 2026-07-06 bars this test flaked at + # the date rollover regardless of the stub data. Pin a mid-session UTC clock. + import research.ingestion.volume_ratio as vr + from datetime import date as _date, datetime as _dt, timezone + + class _FrozenDT: + @staticmethod + def now(tz=None): + return _dt(2026, 7, 6, 18, 0, 0, tzinfo=tz or timezone.utc) + + class _FrozenDate: + @staticmethod + def today(): + return _date(2026, 7, 6) + + monkeypatch.setattr(vr, "datetime", _FrozenDT) + monkeypatch.setattr(vr, "date", _FrozenDate) r = compute_ratios(_Client(), ["GOOD", "DUST", "MISSING"]) assert r["GOOD"] == 25.0 # 12500 sip / 500 iex assert "DUST" not in r # sip sample below floor -> untrusted