Skip to content

Commit 8f362e9

Browse files
committed
test(knowledge): prove sweep dispatches the replacement and keeps worker-reached charges
1 parent 74140e0 commit 8f362e9

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎apps/sim/lib/knowledge/__integration__/connector-lifecycle-locks.integration.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { deferConnectorSync } from '@/lib/knowledge/connectors/sync-deferral'
3232
import { completeSuccessfulSync } from '@/lib/knowledge/connectors/sync-engine'
3333
import { createContentSyncLease } from '@/lib/knowledge/connectors/sync-lock'
3434
import { sweepStuckDocuments } from '@/lib/knowledge/connectors/sync-primitives'
35+
import { processDocumentsWithQueue } from '@/lib/knowledge/documents/service'
3536
import { deleteKnowledgeBase } from '@/lib/knowledge/service'
3637
import { GitHubRequestDeferredError } from '@/connectors/github/request'
3738
import type { SyncResult } from '@/connectors/types'
@@ -282,14 +283,24 @@ describe('source lifecycle KB guards', () => {
282283
.from(document)
283284
.where(eq(document.id, retryDocumentId))
284285
expect(row).toEqual({ status: 'pending', attempts: 1, token: null })
286+
expect(vi.mocked(processDocumentsWithQueue).mock.lastCall?.[0]).toEqual([
287+
expect.objectContaining({ documentId: retryDocumentId }),
288+
])
285289
})
286290

287-
it('keeps the charge of an attempt that reached a worker', async () => {
291+
it.each([
292+
['failed', {}],
293+
['stale processing', { processingStatus: 'processing', processingStartedAt: new Date(0) }],
294+
] as const)('keeps the charge of a %s attempt that reached a worker', async (_state, row) => {
295+
await db
296+
.update(document)
297+
.set({ ...row, processingAttempts: 2, processingQueuedAt: new Date(0) })
298+
.where(eq(document.id, retryDocumentId))
288299
await run('recover')
289-
const [row] = await db
290-
.select({ attempts: document.processingAttempts })
300+
const [after] = await db
301+
.select({ status: document.processingStatus, attempts: document.processingAttempts })
291302
.from(document)
292303
.where(eq(document.id, retryDocumentId))
293-
expect(row.attempts).toBe(1)
304+
expect(after).toEqual({ status: 'pending', attempts: 2 })
294305
})
295306
})

0 commit comments

Comments
 (0)