krz/hutch-stats

Server-side utility for calculating contributions for sourcehut users. contributions server sourcehut stats

Commit c544c1bd6a

c544c1bd6ac7cf9c989abd887067d34b0455bd66

parent: 084874158a

Verified · cmc

cmc <hello@cleberg.net> · 2026-07-20 17:00 UTC

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.

Layout: unified · split

tests/test_ingestion.py +5 −3
@@ -237,13 +237,15 @@ def branch_payload(*branches: str) -> dict:
237 237
238def test_todo_ingestion_is_idempotent(db_session) -> None: 238def test_todo_ingestion_is_idempotent(db_session) -> None:
239 settings = make_settings() 239 settings = make_settings()
240 # The poller polls the last 30 days, so keep fixture events inside that window.
241 now = datetime.now(tz=UTC)
240 payload = { 242 payload = {
241 "me": {"canonicalName": "~ccleberg"}, 243 "me": {"canonicalName": "~ccleberg"},
242 "events": { 244 "events": {
243 "results": [ 245 "results": [
244 { 246 {
245 "id": "1001", 247 "id": "1001",
246 "created": "2026-05-01T10:00:00Z", 248 "created": (now - timedelta(days=3)).isoformat(),
247 "ticket": { 249 "ticket": {
248 "id": "123", 250 "id": "123",
249 "ref": "~ccleberg/todo/123", 251 "ref": "~ccleberg/todo/123",
@@ -262,7 +264,7 @@ def test_todo_ingestion_is_idempotent(db_session) -> None:
262 }, 264 },
263 { 265 {
264 "id": "1002", 266 "id": "1002",
265 "created": "2026-05-02T09:00:00Z", 267 "created": (now - timedelta(days=2, hours=1)).isoformat(),
266 "ticket": { 268 "ticket": {
267 "id": "123", 269 "id": "123",
268 "ref": "~ccleberg/todo/123", 270 "ref": "~ccleberg/todo/123",
@@ -281,7 +283,7 @@ def test_todo_ingestion_is_idempotent(db_session) -> None:
281 }, 283 },
282 { 284 {
283 "id": "1003", 285 "id": "1003",
284 "created": "2026-05-02T10:00:00Z", 286 "created": (now - timedelta(days=2)).isoformat(),
285 "ticket": { 287 "ticket": {
286 "id": "123", 288 "id": "123",
287 "ref": "~ccleberg/todo/123", 289 "ref": "~ccleberg/todo/123",