From 2aba489036c1c534b234ccb68b50825db135768c Mon Sep 17 00:00:00 2001 From: timmy Date: Thu, 6 Aug 2026 09:00:45 +0000 Subject: [PATCH] fix: skip malformed activity feed entries (#89) --- src/gitea_proxy.py | 1 + tests/test_event_stream.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/gitea_proxy.py b/src/gitea_proxy.py index 6d04c8e..7525866 100644 --- a/src/gitea_proxy.py +++ b/src/gitea_proxy.py @@ -48,4 +48,5 @@ async def activity_events() -> list[dict]: "created_at": event.get("created", ""), } for event in events + if isinstance(event, dict) ] diff --git a/tests/test_event_stream.py b/tests/test_event_stream.py index d72f036..3861205 100644 --- a/tests/test_event_stream.py +++ b/tests/test_event_stream.py @@ -118,3 +118,33 @@ async def test_activity_events_fetches_feed_for_authenticated_user(monkeypatch): "created_at": "2026-08-05T03:00:00Z", }] assert paths == ["users/timmy/activities/feeds?limit=20"] + + +@pytest.mark.anyio +async def test_activity_events_skips_malformed_feed_entries(monkeypatch): + async def fake_current_user(): + return {"login": "timmy"} + + async def fake_fetch(path): + return [ + None, + { + "op_type": "push", + "act_user": {"login": "timmy"}, + "repo": {"full_name": "stackchain/stackchain-dashboard"}, + "created": "2026-08-06T08:00:00Z", + }, + "invalid", + ] + + monkeypatch.setattr(gitea_proxy, "current_user", fake_current_user) + monkeypatch.setattr(gitea_proxy, "fetch", fake_fetch) + + result = await gitea_proxy.activity_events() + + assert result == [{ + "type": "push", + "actor": {"login": "timmy"}, + "repo": {"full_name": "stackchain/stackchain-dashboard"}, + "created_at": "2026-08-06T08:00:00Z", + }]