@@ -491,7 +491,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
491491 } ) ,
492492 ) ;
493493
494- it . effect ( "pages complete user turns through SQL regardless of tool count or payload size " , ( ) =>
494+ it . effect ( "caps the first snapshot at the row window and pages omitted turns whole " , ( ) =>
495495 Effect . gen ( function * ( ) {
496496 const projectionStore = yield * ProjectionStore . ProjectionStoreV2 ;
497497 const sql = yield * SqlClient . SqlClient ;
@@ -607,34 +607,48 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
607607 ) ,
608608 ( parse ) => Effect . sync ( ( ) => parse . mockRestore ( ) ) ,
609609 ) ;
610- // Only the selected turn cohort and two lookahead anchors are decoded.
611- assert . lengthOf ( initial . projection . turnItems , 12 * 102 ) ;
610+ // The first connect reads the row cap, not every tool row in the turn window.
611+ assert . isTrue ( initial . olderHistoryExists ) ;
612+ assert . lengthOf ( initial . projection . turnItems , 77 ) ;
613+ assert . strictEqual ( initial . projection . turnItems . at ( - 1 ) ?. id , allIds . at ( - 1 ) ) ;
614+ assert . isFalse ( initial . projection . turnItems . some ( ( item ) => item . id === allIds [ 0 ] ) ) ;
612615 const bounded = buildBoundedThreadProjection ( {
613616 projection : initial . projection ,
614617 snapshotSequence : 0 ,
618+ olderHistoryExists : initial . olderHistoryExists ,
619+ olderHistoryThreadId : initial . olderHistoryThreadId ,
615620 } ) ;
616- assert . lengthOf ( bounded . projection . visibleTurnItems , 10 * 102 ) ;
617- assert . strictEqual ( bounded . projection . visibleTurnItems [ 0 ] ?. sourceItemId , allIds [ 35 * 102 ] ) ;
621+ assert . isTrue ( bounded . hasMoreHistory ) ;
618622 const loaded = bounded . projection . visibleTurnItems . map ( ( row ) => String ( row . sourceItemId ) ) ;
619623 let cursor = bounded . historyCursor ;
620- for ( const turns of [ 20 , 15 ] ) {
621- assert . isNotNull ( cursor ) ;
622- const anchor = decodeThreadHistoryCursor ( cursor ! ) ;
624+ let sawWholeTurnPage = false ;
625+ let pages = 1 ;
626+ while ( cursor !== null ) {
627+ const anchor = decodeThreadHistoryCursor ( cursor ) ;
623628 const snapshot = yield * projectionStore . getThreadSnapshotWindow ( threadId , {
624629 rowLimit : 77 ,
625630 userTurnLimit : 20 ,
626631 anchorItemId : TurnItemId . make ( anchor . si ) ,
627632 anchorThreadId : ThreadId . make ( anchor . st ) ,
628633 } ) ;
634+ if ( snapshot . projection . turnItems . length > 77 ) sawWholeTurnPage = true ;
629635 const page = selectHistoryPageFromCursor ( {
630636 items : snapshot . projection . visibleTurnItems ,
631- cursor : cursor ! ,
637+ cursor,
638+ snapshotSequence : 0 ,
639+ } ) ;
640+ const revealed = revealOlderSqlHistory ( {
641+ page,
642+ olderHistoryExists : snapshot . olderHistoryExists ,
643+ olderHistoryThreadId : snapshot . olderHistoryThreadId ,
632644 snapshotSequence : 0 ,
633645 } ) ;
634- assert . lengthOf ( page . items , turns * 102 ) ;
635646 loaded . unshift ( ...page . items . map ( ( row ) => String ( row . sourceItemId ) ) ) ;
636- cursor = page . nextCursor ;
647+ cursor = revealed . nextCursor ;
648+ pages += 1 ;
649+ if ( pages > 20 ) break ;
637650 }
651+ assert . isTrue ( sawWholeTurnPage ) ;
638652 assert . isNull ( cursor ) ;
639653 assert . deepEqual ( loaded , allIds ) ;
640654 } ) ,
0 commit comments