Skip to content

The agent that grows with you

test(gateway): make Windows timestamp regression deterministic

tank321e0047e0544ad
diff --git a/tests/gateway/test_message_timestamps.py b/tests/gateway/test_message_timestamps.py
index efb98ac2bd6..93f68581fe8 100644
--- a/tests/gateway/test_message_timestamps.py
+++ b/tests/gateway/test_message_timestamps.py
@@ -1,13 +1,14 @@
from datetime import datetime, timezone
+from unittest.mock import Mock
from zoneinfo import ZoneInfo
import pytest
-from hermes_time import safe_strftime
-
+from gateway import message_timestamps
from gateway.message_timestamps import (
render_user_content_with_timestamp,
)
+from hermes_time import safe_strftime
BERLIN = ZoneInfo("Europe/Berlin")
@@ -27,6 +28,20 @@ def test_render_numeric_timestamp_preserves_instant_in_system_timezone(epoch):
assert render_user_content_with_timestamp("hello", epoch) == f"[{prefix}] hello"
+def test_system_timezone_conversion_starts_from_aware_utc(monkeypatch):
+ # Record real datetime calls: output alone also passes with the unsafe
+ # conversion when the canonical runner sets TZ=UTC. A modern epoch keeps
+ # the failure at this assertion rather than a host-dependent exception.
+ datetime_spy = Mock(wraps=datetime)
+ monkeypatch.setattr(message_timestamps, "datetime", datetime_spy)
+ epoch = 1_000_000_000.0
+
+ render_user_content_with_timestamp("hello", epoch)
+
+ datetime_spy.fromtimestamp.assert_called_once_with(epoch, tz=timezone.utc)
+
+
def test_render_user_content_deduplicates_existing_timestamp_and_preserves_embedded_time():
db_processing_ts = _epoch(2026, 4, 27, 15, 55, 36)
stored_content = (