@@ -32,6 +32,7 @@ import { deferConnectorSync } from '@/lib/knowledge/connectors/sync-deferral'
3232import { completeSuccessfulSync } from '@/lib/knowledge/connectors/sync-engine'
3333import { createContentSyncLease } from '@/lib/knowledge/connectors/sync-lock'
3434import { sweepStuckDocuments } from '@/lib/knowledge/connectors/sync-primitives'
35+ import { processDocumentsWithQueue } from '@/lib/knowledge/documents/service'
3536import { deleteKnowledgeBase } from '@/lib/knowledge/service'
3637import { GitHubRequestDeferredError } from '@/connectors/github/request'
3738import 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