@@ -3333,6 +3333,55 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
33333333 } ) . pipe ( Effect . scoped ) ,
33343334 ) ;
33353335
3336+ it . effect ( "rejects unreadable rollback history before cutting the native session" , ( ) =>
3337+ Effect . gen ( function * ( ) {
3338+ const { runtime, thread } = yield * resumed ( [
3339+ out ( "message.list" , { sessionID : SESSION , limit : "100" , type : undefined } ) ,
3340+ reply ( "message.list" , {
3341+ data : [
3342+ { id : "msg_kept" , time : { created : 1 } , text : "first" , type : "user" } ,
3343+ {
3344+ id : "msg_compaction" ,
3345+ time : { created : 2 } ,
3346+ type : "compaction" ,
3347+ status : "completed" ,
3348+ reason : "auto" ,
3349+ summary : "First turn summary" ,
3350+ } ,
3351+ { id : "msg_dropped" , time : { created : 3 } , text : "second" , type : "user" } ,
3352+ ] ,
3353+ cursor : { } ,
3354+ } ) ,
3355+ ] ) ;
3356+ const now = yield * DateTime . now ;
3357+ const turns = [ "msg_kept" , "msg_dropped" ] . map ( ( nativeId , index ) => ( {
3358+ id : ProviderTurnId . make ( `provider-turn:rollback-history:${ index } ` ) ,
3359+ providerThreadId : thread . id ,
3360+ nodeId : NodeId . make ( `node:rollback-history:${ index } ` ) ,
3361+ runAttemptId : RunAttemptId . make ( `attempt:rollback-history:${ index } ` ) ,
3362+ nativeTurnRef : { driver : OPENCODE_PROVIDER , nativeId, strength : "weak" as const } ,
3363+ ordinal : index + 1 ,
3364+ status : "completed" as const ,
3365+ startedAt : now ,
3366+ completedAt : now ,
3367+ } ) ) ;
3368+ const failure = yield * runtime
3369+ . rollbackThread ( {
3370+ providerThread : thread ,
3371+ target : {
3372+ type : "provider_turn" ,
3373+ checkpointId : CheckpointId . make ( "checkpoint:rollback-history" ) ,
3374+ appRunOrdinal : 1 ,
3375+ providerTurn : turns [ 0 ] ! ,
3376+ } ,
3377+ providerThreadTurns : turns ,
3378+ } )
3379+ . pipe ( Effect . flip ) ;
3380+ assert . equal ( failure . _tag , "ProviderAdapterRollbackThreadError" ) ;
3381+ assert . include ( Cause . pretty ( Cause . fail ( failure ) ) , '["recent"]' ) ;
3382+ } ) . pipe ( Effect . scoped ) ,
3383+ ) ;
3384+
33363385 it . effect ( "clears a staged revert whose commit failed, before the next prompt too" , ( ) =>
33373386 Effect . gen ( function * ( ) {
33383387 const kept = "msg_t3_turn_run-attempt:kept:1" ;
@@ -4120,8 +4169,22 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
41204169 Effect . gen ( function * ( ) {
41214170 const FORK = "ses_f1484db83ffeLGtrRCFimo1H0e" ;
41224171 const { runtime, thread, first, second } = yield * continued ( [
4123- out ( "message.list" , "<any>" ) ,
4124- reply ( "message.list" , continuedHistory ) ,
4172+ out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "user" } ) ,
4173+ reply ( "message.list" , { data : [ continuedHistory . data [ 1 ] ] , cursor : { } } ) ,
4174+ out ( "message.list" , { sessionID : SESSION , limit : "100" , type : "synthetic" } ) ,
4175+ reply ( "message.list" , {
4176+ data : [
4177+ { id : "msg_later_report" , time : { created : 3 } , text : "later" , type : "synthetic" } ,
4178+ ] ,
4179+ cursor : { next : "synthetic-page-2" } ,
4180+ } ) ,
4181+ out ( "message.list" , {
4182+ sessionID : SESSION ,
4183+ limit : "100" ,
4184+ type : "synthetic" ,
4185+ cursor : "synthetic-page-2" ,
4186+ } ) ,
4187+ reply ( "message.list" , { data : [ continuedHistory . data [ 0 ] ] , cursor : { } } ) ,
41254188 out ( "session.fork" , { sessionID : SESSION , before : "msg_report" } ) ,
41264189 replyData ( "session.fork" , sessionInfo ( { id : FORK } ) ) ,
41274190 out ( "session.update" , { sessionID : FORK , permissions : "<any>" } ) ,
0 commit comments