-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(rss): deliver unseen items published before the last poll #7792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+136
−6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { createLogger } from '@sim/logger' | ||
| import { createWorkflowRecord } from '@sim/testing' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const { mockFetch, mockValidateUrl, mockProcessEvent, mockUpdateConfig } = vi.hoisted(() => ({ | ||
| mockFetch: vi.fn(), | ||
| mockValidateUrl: vi.fn(), | ||
| mockProcessEvent: vi.fn(), | ||
| mockUpdateConfig: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@/lib/core/security/input-validation.server', () => ({ | ||
| secureFetchWithPinnedIP: mockFetch, | ||
| validateUrlWithDNS: mockValidateUrl, | ||
| })) | ||
|
|
||
| vi.mock('@/lib/core/idempotency/service', () => ({ | ||
| pollingIdempotency: { | ||
| executeWithIdempotency: vi.fn( | ||
| async (_provider: string, _key: string, execute: () => Promise<unknown>) => execute() | ||
| ), | ||
| }, | ||
| })) | ||
|
|
||
| vi.mock('@/lib/webhooks/processor', () => ({ | ||
| processPolledWebhookEvent: mockProcessEvent, | ||
| })) | ||
|
|
||
| vi.mock('@/lib/webhooks/polling/utils', () => ({ | ||
| markWebhookSuccess: vi.fn(), | ||
| markWebhookFailed: vi.fn(), | ||
| updateWebhookProviderConfig: mockUpdateConfig, | ||
| })) | ||
|
|
||
| import { rssPollingHandler } from '@/lib/webhooks/polling/rss' | ||
| import type { PollWebhookContext, WebhookRecord } from '@/lib/webhooks/polling/types' | ||
|
|
||
| const SUBSCRIBED_AT = new Date('2026-08-27T18:36:16.000Z') | ||
| const LAST_CHECKED_AT = '2026-09-11T23:26:27.000Z' | ||
| const GUID = 'https://example.com/news/late-item' | ||
|
|
||
| function context(lastSeenGuids: string[] = []): PollWebhookContext { | ||
| const webhookData: WebhookRecord = { | ||
| id: 'rss-webhook', | ||
| workflowId: 'rss-listener', | ||
| deploymentVersionId: null, | ||
| registrationStatus: null, | ||
| registrationGeneration: null, | ||
| configFingerprint: null, | ||
| preparedAt: null, | ||
| blockId: null, | ||
| path: 'rss-listener', | ||
| routingKey: null, | ||
| provider: 'rss', | ||
| providerConfig: { | ||
| feedUrl: 'https://example.com/feed.xml', | ||
| lastCheckedTimestamp: LAST_CHECKED_AT, | ||
| lastSeenGuids, | ||
| }, | ||
| isActive: true, | ||
| failedCount: 0, | ||
| lastFailedAt: null, | ||
| archivedAt: null, | ||
| createdAt: SUBSCRIBED_AT, | ||
| updatedAt: new Date(LAST_CHECKED_AT), | ||
| } | ||
| return { | ||
| webhookData, | ||
| workflowData: createWorkflowRecord({ | ||
| id: 'rss-listener', | ||
| }) as PollWebhookContext['workflowData'], | ||
| requestId: 'rss-request', | ||
| logger: createLogger('RssTest'), | ||
| } | ||
| } | ||
|
|
||
| function feed(pubDate: string) { | ||
| return new Response( | ||
| `<?xml version="1.0"?><rss version="2.0"><channel> | ||
| <title>Canary fixture</title><link>https://example.com</link><description>RSS fixture</description> | ||
| <item><title>Late item</title><guid>${GUID}</guid><pubDate>${pubDate}</pubDate></item> | ||
| </channel></rss>`, | ||
| { headers: { 'Content-Type': 'application/rss+xml' } } | ||
| ) | ||
| } | ||
|
|
||
| describe('RSS delivery across delayed feed updates', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| mockValidateUrl.mockResolvedValue({ isValid: true, resolvedIP: '203.0.113.1' }) | ||
| mockProcessEvent.mockResolvedValue({ success: true }) | ||
| mockUpdateConfig.mockResolvedValue(undefined) | ||
| }) | ||
|
|
||
| it('delivers an unseen item published before the last poll but after subscription', async () => { | ||
| mockFetch.mockResolvedValue(feed('Fri, 11 Sep 2026 21:25:32 GMT')) | ||
|
|
||
| expect(await rssPollingHandler.pollWebhook(context())).toBe('success') | ||
| expect(mockProcessEvent).toHaveBeenCalledExactlyOnceWith( | ||
| expect.anything(), | ||
| expect.anything(), | ||
| expect.objectContaining({ item: expect.objectContaining({ guid: GUID }) }), | ||
| 'rss-request' | ||
| ) | ||
| expect(mockUpdateConfig).toHaveBeenCalledWith( | ||
| 'rss-webhook', | ||
| expect.objectContaining({ lastSeenGuids: [GUID] }), | ||
| expect.anything() | ||
| ) | ||
| }) | ||
|
|
||
| it('does not redeliver a known GUID when its publication date changes', async () => { | ||
| mockFetch.mockResolvedValue(feed('Fri, 11 Sep 2026 23:28:00 GMT')) | ||
|
|
||
| expect(await rssPollingHandler.pollWebhook(context([GUID]))).toBe('success') | ||
| expect(mockProcessEvent).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('does not backfill items published before the subscription existed', async () => { | ||
| mockFetch.mockResolvedValue(feed('Thu, 27 Aug 2026 18:30:00 GMT')) | ||
|
|
||
| expect(await rssPollingHandler.pollWebhook(context())).toBe('success') | ||
| expect(mockProcessEvent).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a feed retains an item after its GUID falls out of the 500-entry
lastSeenGuidswindow, this subscription-time cutoff allows that already-delivered item through again because its publication date remains after the subscription began. The idempotency key expires after three days, so feeds containing more than 500 retained items can cause old entries to be delivered repeatedly. Deduplication needs to remain durable for every item admitted by this broader timestamp window.