diff --git a/src/services/wiki_change_listener.py b/src/services/wiki_change_listener.py index 2d4a491..dee699c 100644 --- a/src/services/wiki_change_listener.py +++ b/src/services/wiki_change_listener.py @@ -116,24 +116,6 @@ class WikiChangeListener: except Exception as e: logger.error(f"Failed to handle notification: {e}", exc_info=True) - def _is_automated_user(self, email: str) -> bool: - """ - Check if email belongs to an automated system user. - - These are edits made by library-desk via Wiki.js API (entity linking). - We skip processing these to prevent loops. - - Customize this list based on your Wiki.js username for library-desk. - """ - automated_users = [ - self.settings.wikijs_username, # Library-desk's Wiki.js API user - "library-desk@system", - "automation@system", - "bot@system" - ] - - return email.lower() in [u.lower() for u in automated_users] - def _is_recently_processed(self, page_id: int) -> bool: """Check if page was processed recently (debouncing).""" if page_id not in self._recent_notifications: diff --git a/tests/test_wiki_change_listener.py b/tests/test_wiki_change_listener.py index b04d3fd..2270dd9 100644 --- a/tests/test_wiki_change_listener.py +++ b/tests/test_wiki_change_listener.py @@ -50,22 +50,6 @@ class TestWikiChangeListener: assert listener._debounce_seconds == 5 assert len(listener._recent_notifications) == 0 - @pytest.mark.asyncio - async def test_automated_user_filtering(self, listener): - """Test that automated users are correctly identified.""" - # Automated users should be filtered - assert listener._is_automated_user("librarian@schweitz.net") is True - assert listener._is_automated_user("library-desk@system") is True - assert listener._is_automated_user("automation@system") is True - assert listener._is_automated_user("bot@system") is True - - # Case insensitive - assert listener._is_automated_user("LIBRARIAN@SCHWEITZ.NET") is True - - # Regular users should not be filtered - assert listener._is_automated_user("user@example.com") is False - assert listener._is_automated_user("john@example.com") is False - @pytest.mark.asyncio async def test_debouncing_prevents_duplicates(self, listener): """Test that debouncing prevents duplicate processing.""" @@ -163,19 +147,29 @@ class TestWikiChangeListener: assert mock_process.call_args[1]['event'] == 'page.delete' @pytest.mark.asyncio - async def test_automated_user_notification_filtered(self, listener): - """Test that notifications from automated users are filtered out.""" + async def test_any_user_notification_processed(self, listener): + """Test that notifications are processed regardless of user email. + + Note: The user_email in PostgreSQL notifications is the page CREATOR, + not the editor. We cannot filter by user email because: + - A page created by 'librarian' but edited by a human should be processed + - Filtering by creator would break legitimate page ingestion + Loop prevention is handled by debouncing instead. + """ mock_connection = AsyncMock() with patch.object(listener, '_process_page_change', new_callable=AsyncMock) as mock_process: - # Notification from automated user should be skipped + # Even system user notifications should be processed + # (debouncing handles loop prevention, not user filtering) await listener._handle_notification( mock_connection, 1234, 'wiki_page_changes', 'UPDATE:123:librarian@schweitz.net' ) - # Process should NOT be called - mock_process.assert_not_called() + # Process SHOULD be called (user filtering is not used) + mock_process.assert_called_once() + assert mock_process.call_args[1]['page_id'] == 123 + assert mock_process.call_args[1]['event'] == 'page.update' @pytest.mark.asyncio async def test_duplicate_notification_filtered(self, listener):