@@ -392,12 +392,13 @@ function findOr(where: any): any[] {
392392describe ( '[ADR-0139 E7] backfillCommentParentPair' , ( ) => {
393393 let kernel : ObjectKernel ;
394394 let engine : ObjectQL ;
395+ let driver : SqliteWasmDriver ;
395396 const rowIds : string [ ] = [ ] ;
396397 const stampedAt = new Map < string , unknown > ( ) ;
397398 const logger = ( ) => ( { info : vi . fn ( ) , warn : vi . fn ( ) } ) ;
398399
399400 beforeAll ( async ( ) => {
400- const driver = new SqliteWasmDriver ( { filename : ':memory:' } ) ;
401+ driver = new SqliteWasmDriver ( { filename : ':memory:' } ) ;
401402 ( { kernel, engine } = await bootKernel ( driver ) ) ;
402403 engine . registry . registerObject ( objectOf ( DOC ) as any , HARNESS_PACKAGE ) ;
403404 await engine . syncSchemas ( ) ;
@@ -451,6 +452,26 @@ describe('[ADR-0139 E7] backfillCommentParentPair', () => {
451452 expect ( await all ( ) ) . toEqual ( before ) ;
452453 } ) ;
453454
455+ it ( 'a row re-pointed between the page read and the write keeps the re-pointed pair' , async ( ) => {
456+ const doc = String ( ( await engine . insert ( DOC , { name : 'race' } , { context : SYS } ) ) . id ) ;
457+ const moved = String ( ( await engine . insert ( DOC , { name : 'race target' } , { context : SYS } ) ) . id ) ;
458+ const id = String ( ( await engine . insert ( COMMENT , commentOn ( DOC , doc , 'race' ) , { context : SYS } ) ) . id ) ;
459+ await driver . update ( COMMENT , id , { object_name : null , record_id : null } ) ;
460+ // The engine the backfill drives re-points the row right after reading the page.
461+ const racing = {
462+ find : async ( ...args : any [ ] ) => {
463+ const page = await ( engine . find as any ) ( ...args ) ;
464+ await engine . update ( COMMENT , { id, thread_id : `${ DOC } :${ moved } ` } , { context : SYS } ) ;
465+ return page ;
466+ } ,
467+ update : ( ...args : any [ ] ) => ( engine . update as any ) ( ...args ) ,
468+ } ;
469+ await backfillCommentParentPair ( racing as any , logger ( ) , { apply : true , pageSize : 500 } ) ;
470+ expect ( await engine . findOne ( COMMENT , { where : { id } , context : SYS } ) ) . toMatchObject ( {
471+ thread_id : `${ DOC } :${ moved } ` , object_name : DOC , record_id : moved ,
472+ } ) ;
473+ } ) ;
474+
454475 it ( 'a read the table refuses is a failure, never a clean report' , async ( ) => {
455476 const log = logger ( ) ;
456477 const failing = { find : vi . fn ( async ( ) => { throw new Error ( 'no such table' ) ; } ) , update : vi . fn ( ) } ;
0 commit comments