From 6edbc404043edfc4a88622c3c48cf94d71627acb Mon Sep 17 00:00:00 2001 From: Kingston Date: Thu, 3 Sep 2026 18:48:17 -0700 Subject: [PATCH] test(server): stop asserting UTC rendering with a substring that matches the date test_preview_stats_render_timestamps_in_utc_on_a_non_utc_host asserted "-04" not in the rendered bound to catch the host's -04:00 offset. The substring also matches the day in 2026-09-04 and the month in any April date, so the test failed on the 4th of every month and through all of April regardless of the code under test. It is failing on main today. The bounds are now compared to the row timestamps and to the wall clock instead. That drops the date collision and covers more: a render that shifted the clock into the host zone while still stamping +00:00 passed both the old substring check and a rows-to-stats comparison on its own, because rows and stats go through the same projection and shift together. Reported independently by @akshatpatel64 (#383) and @victorwon2001 (#384). --- .../tests/test_server_curation_preview.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/hflow-server/tests/test_server_curation_preview.py b/packages/hflow-server/tests/test_server_curation_preview.py index 1ad6dcb..09d77de 100644 --- a/packages/hflow-server/tests/test_server_curation_preview.py +++ b/packages/hflow-server/tests/test_server_curation_preview.py @@ -2,7 +2,7 @@ import os import time -from datetime import UTC, datetime +from datetime import UTC, datetime, timedelta import pytest from fastapi.testclient import TestClient @@ -76,14 +76,23 @@ def test_preview_stats_render_timestamps_in_utc_on_a_non_utc_host( # Rows are UTC ISO text... for row in payload["rows"]: assert row["recorded_at"].endswith("+00:00") - # ...and the column stats agree (same UTC rendering, not the host's -04), - # so the stats panel never shows a different offset or calendar day. + # ...and the column stats agree, so the stats panel never shows a different + # offset or calendar day than the rows above it. stats_by_column = {entry["column_name"]: entry for entry in payload["column_stats"]} recorded_at_stats = stats_by_column["recorded_at"] + row_timestamps = sorted(datetime.fromisoformat(row["recorded_at"]) for row in payload["rows"]) + expected_bounds = {"min": row_timestamps[0], "max": row_timestamps[-1]} for bound_key in ("min", "max"): bound_value = recorded_at_stats[bound_key] assert bound_value.endswith("+00:00"), bound_value - assert "-04" not in bound_value + parsed_bound = datetime.fromisoformat(bound_value) + assert parsed_bound.utcoffset() == timedelta(0), bound_value + assert parsed_bound == expected_bounds[bound_key], bound_value + # The fixture stamps recorded_at as it appends, so a correct render lands + # near now. Rows and stats pass through the same projection and would shift + # together, so agreement alone cannot catch a clock moved into the host zone + # and then stamped +00:00; the host offset here is whole hours away from UTC. + assert abs(datetime.now(UTC) - expected_bounds["max"]) < timedelta(hours=1) def test_preview_stats_returns_summarize_rows(api: TestClient) -> None: