@@ -60,6 +60,10 @@ import { deleteUserAccount } from '@/lib/users/account-deletion'
6060import { fetchAuthorizedServableWorkspaceFileBuffer } from '@/lib/workspace-files/application/fetch-servable-workspace-file-buffer'
6161import { observeWorkspaceFileDelivery } from '@/lib/workspace-files/application/file-delivery-observer'
6262import { searchWorkspaceFileContent } from '@/lib/workspace-files/application/search-workspace-file-content'
63+ import {
64+ FILE_SEARCH_BUILD_ABANDONED_REASON ,
65+ FILE_SEARCH_INDEX_MAX_ABANDONED_BUILDS ,
66+ } from '@/lib/workspace-files/search/constants'
6367import { prepareWorkspaceFileSearchDispatch } from '@/lib/workspace-files/search/dispatcher'
6468import {
6569 appendFileSearchChunks ,
@@ -1108,6 +1112,82 @@ describe('owner-scoped indexed file search on PostgreSQL and stored bytes', () =
11081112 expect ( ( await search ( f , 'newrevisionneedle' ) ) . count ) . toBe ( 1 )
11091113 }
11101114 )
1115+ check (
1116+ 'keeps a revision stopped by killed builds stopped, and its count, when its artifact renders again' ,
1117+ async ( ) => {
1118+ const f = await fixture ( )
1119+ const dependency = await create ( f , 'before' , { name : 'stopped-input.txt' } )
1120+ const source = `getFileBase64('${ dependency . file . id } ')`
1121+ const generated = await create ( f , source , { name : 'stopped.docx' } )
1122+ const [ dependencyRow ] = await db
1123+ . select ( )
1124+ . from ( workspaceFiles )
1125+ . where ( eq ( workspaceFiles . id , dependency . file . id ) )
1126+ const completion = {
1127+ owner : f . owner ,
1128+ file : {
1129+ fileId : generated . file . id ,
1130+ key : generated . file . key ,
1131+ contentUpdatedAt : generated . file . contentUpdatedAt ,
1132+ } ,
1133+ dependencies : [
1134+ {
1135+ fileId : dependency . file . id ,
1136+ key : dependency . file . key ,
1137+ sourceContentUpdatedAt : dependency . file . contentUpdatedAt ,
1138+ } ,
1139+ ] ,
1140+ artifactKey : compiledArtifactKey (
1141+ f . owner ,
1142+ source ,
1143+ 'docx' ,
1144+ fileDocumentCacheIdentity (
1145+ source ,
1146+ await requireDocxFormat ( ) ,
1147+ 'text/plain' ,
1148+ fileDocumentInputIdentity ( f . owner , [ dependencyRow ] )
1149+ )
1150+ ) ,
1151+ }
1152+ const { markFileSearchArtifactReadyInTx } = await import (
1153+ '@/lib/workspace-files/search/artifact-ready'
1154+ )
1155+ const revisionOf = async ( ) =>
1156+ (
1157+ await db
1158+ . select ( )
1159+ . from ( workspaceFileSearchRevision )
1160+ . where ( eq ( workspaceFileSearchRevision . fileId , generated . file . id ) )
1161+ ) [ 0 ]
1162+
1163+ await db
1164+ . update ( workspaceFileSearchRevision )
1165+ . set ( { status : 'pending' , buildId : null , dispatchedAt : null , abandonedBuilds : 1 } )
1166+ . where ( eq ( workspaceFileSearchRevision . fileId , generated . file . id ) )
1167+ expect ( await db . transaction ( ( tx ) => markFileSearchArtifactReadyInTx ( tx , completion ) ) ) . toBe (
1168+ true
1169+ )
1170+ expect ( await revisionOf ( ) ) . toMatchObject ( { status : 'pending' , abandonedBuilds : 1 } )
1171+
1172+ await db
1173+ . update ( workspaceFileSearchRevision )
1174+ . set ( {
1175+ status : 'failed' ,
1176+ buildId : null ,
1177+ failureReason : FILE_SEARCH_BUILD_ABANDONED_REASON ,
1178+ abandonedBuilds : FILE_SEARCH_INDEX_MAX_ABANDONED_BUILDS ,
1179+ } )
1180+ . where ( eq ( workspaceFileSearchRevision . fileId , generated . file . id ) )
1181+ expect ( await db . transaction ( ( tx ) => markFileSearchArtifactReadyInTx ( tx , completion ) ) ) . toBe (
1182+ false
1183+ )
1184+ expect ( await revisionOf ( ) ) . toMatchObject ( {
1185+ status : 'failed' ,
1186+ failureReason : FILE_SEARCH_BUILD_ABANDONED_REASON ,
1187+ abandonedBuilds : FILE_SEARCH_INDEX_MAX_ABANDONED_BUILDS ,
1188+ } )
1189+ }
1190+ )
11111191 check (
11121192 'fences an artifact completion queued behind a concurrent dependency revision' ,
11131193 async ( ) => {
0 commit comments