krz/hutch-stats

Server-side utility for calculating contributions for sourcehut users.

clone: git clone https://gitbay.org/krz/hutch-stats.git

c544c1bd6ac7cf9c989abd887067d34b0455bd66

verified · cmc

author: Christian Cleberg <hello@cleberg.net> · 2026-07-20T17:00:19Z

fix: make todo idempotency test timestamps relative to now

test_todo_ingestion_is_idempotent used hardcoded May 2026 event
timestamps, but the poller computes `since` as now - 30 days. Once
wall-clock time passed 2026-06-01 the fixture events fell outside that
window, were skipped by the todo since filter, and the test asserted
0 inserted instead of 3.

Anchor the three fixture timestamps to datetime.now(UTC) while keeping
their original relative ordering, so the test stays inside the poller's
lookback window regardless of when it runs.
 tests/test_ingestion.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tests/test_ingestion.py b/tests/test_ingestion.py
index 81c4084..693d575 100644
--- a/tests/test_ingestion.py
+++ b/tests/test_ingestion.py
@@ -237,13 +237,15 @@ def branch_payload(*branches: str) -> dict:
 
 def test_todo_ingestion_is_idempotent(db_session) -> None:
     settings = make_settings()
+    # The poller polls the last 30 days, so keep fixture events inside that window.
+    now = datetime.now(tz=UTC)
     payload = {
         "me": {"canonicalName": "~ccleberg"},
         "events": {
             "results": [
                 {
                     "id": "1001",
-                    "created": "2026-05-01T10:00:00Z",
+                    "created": (now - timedelta(days=3)).isoformat(),
                     "ticket": {
                         "id": "123",
                         "ref": "~ccleberg/todo/123",
@@ -262,7 +264,7 @@ def test_todo_ingestion_is_idempotent(db_session) -> None:
                 },
                 {
                     "id": "1002",
-                    "created": "2026-05-02T09:00:00Z",
+                    "created": (now - timedelta(days=2, hours=1)).isoformat(),
                     "ticket": {
                         "id": "123",
                         "ref": "~ccleberg/todo/123",
@@ -281,7 +283,7 @@ def test_todo_ingestion_is_idempotent(db_session) -> None:
                 },
                 {
                     "id": "1003",
-                    "created": "2026-05-02T10:00:00Z",
+                    "created": (now - timedelta(days=2)).isoformat(),
                     "ticket": {
                         "id": "123",
                         "ref": "~ccleberg/todo/123",