@@ -474,4 +474,66 @@ describe('the commit doors: restoring a row bound to the base is closed, removin
474474 expect ( rows ( VIEW . type , VIEW . name ) ) . toEqual ( [ { package_id : PAIR , state : 'active' , label : 'PairFirst' } ] ) ;
475475 expect ( ( await protocol . getMetaItem ( { type : VIEW . type , name : VIEW . name } ) ) . item . label ) . toBe ( 'PairFirst' ) ;
476476 } ) ;
477+
478+ // [#29414] The plan and both revert limbs address the committing package's
479+ // own row. Before, each read any package's active row, so the pair's
480+ // commit beside a row bound to the base addressed the base row.
481+ const planOf = async ( protocol : any , packageId : string , commitId : string ) =>
482+ ( ( await protocol . listCommits ( { packageId } ) ) as Array < { id : string ; items : unknown [ ] } > ) . find ( ( c ) => c . id === commitId ) ?. items ;
483+
484+ it ( '[#29414] the pair\'s first commit beside a row bound to the base records a create, and its revert removes the pair row; the base row is served again' , async ( ) => {
485+ const { protocol, rows } = makeProtocol ( ) ;
486+ await intoBaseBeforeClose ( protocol , 'BaseRow' ) ;
487+ const created = await publishCommit ( protocol , PAIR , declared ( 'PairFirst' ) ) ;
488+ expect ( await planOf ( protocol , PAIR , created ) ) . toEqual ( [
489+ expect . objectContaining ( { type : VIEW . type , name : VIEW . name , existedBefore : false , prevVersion : null } ) ,
490+ ] ) ;
491+
492+ tick ( ) ;
493+ const result = await protocol . revertCommit ( { commitId : created , packageId : PAIR , actor : 'admin' } ) ;
494+
495+ expect ( result ) . toMatchObject ( { success : true , revertedCount : 1 , failed : [ ] , reverted : [ { type : VIEW . type , name : VIEW . name , action : 'removed' } ] } ) ;
496+ expect ( rows ( VIEW . type , VIEW . name ) ) . toEqual ( [ { package_id : BASE , state : 'active' , label : 'BaseRow' } ] ) ;
497+ expect ( ( await protocol . getMetaItem ( { type : VIEW . type , name : VIEW . name } ) ) . item . label ) . toBe ( 'BaseRow' ) ;
498+ } ) ;
499+
500+ it ( '[#29414] the pair\'s edit commit beside a row bound to the base restores the pair\'s own row; the base row is untouched' , async ( ) => {
501+ const { protocol, rows } = makeProtocol ( ) ;
502+ await intoBaseBeforeClose ( protocol , 'BaseRow' ) ;
503+ await publishCommit ( protocol , PAIR , declared ( 'PairFirst' ) ) ;
504+ const edit = await publishCommit ( protocol , PAIR , declared ( 'PairSecond' ) ) ;
505+ expect ( await planOf ( protocol , PAIR , edit ) ) . toEqual ( [
506+ expect . objectContaining ( { type : VIEW . type , name : VIEW . name , existedBefore : true } ) ,
507+ ] ) ;
508+
509+ tick ( ) ;
510+ const result = await protocol . revertCommit ( { commitId : edit , packageId : PAIR , actor : 'admin' } ) ;
511+
512+ expect ( result ) . toMatchObject ( { success : true , revertedCount : 1 , failed : [ ] , reverted : [ { type : VIEW . type , name : VIEW . name , action : 'restored' } ] } ) ;
513+ expect ( rows ( VIEW . type , VIEW . name ) ) . toEqual ( [
514+ { package_id : BASE , state : 'active' , label : 'BaseRow' } ,
515+ { package_id : PAIR , state : 'active' , label : 'PairFirst' } ,
516+ ] ) ;
517+ } ) ;
518+
519+ it ( '[#29414] a revert of the base\'s edit commit whose row was since deleted is refused by the package-less close, as the per-item rollback is; nothing is written' , async ( ) => {
520+ const { protocol, rows } = makeProtocol ( ) ;
521+ await intoBaseBeforeClose ( protocol , 'First' ) ;
522+ const edit = await intoBaseBeforeClose ( protocol , 'Second' ) ;
523+ expect ( await protocol . deleteMetaItem ( { type : VIEW . type , name : VIEW . name , packageId : BASE } ) ) . toMatchObject ( { success : true } ) ;
524+ expect ( rows ( VIEW . type , VIEW . name ) ) . toEqual ( [ ] ) ;
525+ // The per-item rollback on the same `null` binding: the one predicate, its rollback sentence.
526+ const rollback = await thrown ( ( ) => protocol . rollbackMetaItem ( { type : VIEW . type , name : VIEW . name , toVersion : 1 } ) ) ;
527+ expect ( resolveThrownHttpError ( rollback ) ) . toMatchObject ( { status : 403 , code : 'NOT_OVERRIDABLE' } ) ;
528+
529+ tick ( ) ;
530+ const result = await protocol . revertCommit ( { commitId : edit , packageId : BASE , actor : 'admin' } ) ;
531+
532+ expect ( result ) . toMatchObject ( { success : false , revertedCount : 0 , failedCount : 1 , reverted : [ ] } ) ;
533+ expect ( result . failed ) . toEqual ( [ expect . objectContaining ( { type : VIEW . type , name : VIEW . name , code : 'NOT_OVERRIDABLE' } ) ] ) ;
534+ expect ( result . failed [ 0 ] . error ) . toBe ( rollback . message ) ;
535+ expect ( result . failed [ 0 ] . error ) . toContain ( 'a rollback of its package-less row is closed' ) ;
536+ expect ( rows ( VIEW . type , VIEW . name ) ) . toEqual ( [ ] ) ;
537+ expect ( ( await protocol . getMetaItem ( { type : VIEW . type , name : VIEW . name } ) ) . item . label ) . toBe ( PACKAGED ) ;
538+ } ) ;
477539} ) ;
0 commit comments