"""Unit tests for the plugin_metrics rollup cutoff helpers (no DB).""" from datetime import datetime, timezone from steward.core.metrics_retention import _hour_floor, _rollup_cutoff def test_hour_floor_drops_sub_hour(): dt = datetime(2026, 6, 20, 15, 42, 9, 123456, tzinfo=timezone.utc) assert _hour_floor(dt) == datetime(2026, 6, 20, 15, 0, 0, 0, tzinfo=timezone.utc) def test_rollup_cutoff_is_hour_aligned_and_offset(): now = datetime(2026, 6, 20, 15, 42, 9, tzinfo=timezone.utc) cutoff = _rollup_cutoff(now, 7) assert (cutoff.minute, cutoff.second, cutoff.microsecond) == (0, 0, 0) # 7 whole days back, then floored to the hour. assert cutoff == datetime(2026, 6, 13, 15, 0, 0, 0, tzinfo=timezone.utc)