@@ -179,6 +179,7 @@ it.effect("rejects a rollback when another provider thread became active", () =>
179179 const resolveRuntimePolicy = vi . fn ( ( ) => Effect . die ( "runtime policy resolution must not run" ) ) ;
180180 const projection = {
181181 thread : {
182+ worktreePath : null ,
182183 activeProviderThreadId,
183184 modelSelection : { instanceId : providerInstanceId , model : "test-model" } ,
184185 } ,
@@ -390,41 +391,18 @@ it.effect("rejects an unavailable rollback target before opening a session", ()
390391 } ) . pipe ( Effect . provide ( layerTest ) ) ;
391392} ) ;
392393
393- it . effect . each (
394- [
395- { order : "normal" , restoreFiles : true , mutation : "none" , alias : "none" } ,
396- { order : "cleanup-first" , restoreFiles : true , mutation : "none" , alias : "none" } ,
397- { order : "cleanup-first" , restoreFiles : false , mutation : "none" , alias : "none" } ,
398- { order : "rollback-first" , restoreFiles : true , mutation : "none" , alias : "none" } ,
399- { order : "cleanup-first" , restoreFiles : true , mutation : "none" , alias : "direct" } ,
400- { order : "cleanup-first" , restoreFiles : false , mutation : "none" , alias : "parent" } ,
401- { order : "cleanup-first" , restoreFiles : true , mutation : "none" , alias : "missing-parent" } ,
402- { order : "cleanup-first" , restoreFiles : false , mutation : "none" , alias : "dangling" } ,
403- { order : "rollback-first" , restoreFiles : true , mutation : "none" , alias : "direct" } ,
404- { order : "rollback-first" , restoreFiles : false , mutation : "none" , alias : "parent" } ,
405- { order : "rollback-first" , restoreFiles : true , mutation : "none" , alias : "missing-parent" } ,
406- { order : "rollback-first" , restoreFiles : false , mutation : "none" , alias : "dangling" } ,
407- { order : "cleanup-first" , restoreFiles : true , mutation : "worktree" , alias : "none" } ,
408- { order : "cleanup-first" , restoreFiles : true , mutation : "root" , alias : "none" } ,
409- ] . filter ( ( { alias } ) => alias === "none" || symlinksSupported ) ,
410- ) ( "locks rollback with %s" , ( { order, restoreFiles, alias, mutation } ) =>
394+ it . effect . each ( [
395+ { order : "normal" , restoreFiles : true } ,
396+ { order : "cleanup-first" , restoreFiles : true } ,
397+ { order : "cleanup-first" , restoreFiles : false } ,
398+ { order : "rollback-first" , restoreFiles : true } ,
399+ ] ) ( "locks rollback with %s" , ( { order, restoreFiles } ) =>
411400 Effect . gen ( function * ( ) {
412401 const fileSystem = yield * FileSystem . FileSystem ;
413402 const path = yield * Path . Path ;
414403 const workspaceRoot = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3-rollback-" } ) ;
415- let worktreePath = path . join ( workspaceRoot , "worktree" ) ;
416- const initialWorktreePath = worktreePath ;
404+ const worktreePath = path . join ( workspaceRoot , "worktree" ) ;
417405 yield * fileSystem . makeDirectory ( worktreePath ) ;
418- const aliasPath = path . join ( workspaceRoot , "alias" ) ;
419- const parentAlias = alias === "parent" || alias === "missing-parent" ;
420- if ( alias !== "none" ) {
421- yield * fileSystem . symlink ( parentAlias ? workspaceRoot : worktreePath , aliasPath ) ;
422- }
423- const threadPath =
424- alias === "none" ? worktreePath : parentAlias ? path . join ( aliasPath , "worktree" ) : aliasPath ;
425- if ( alias === "missing-parent" || alias === "dangling" ) {
426- yield * fileSystem . remove ( worktreePath , { recursive : true } ) ;
427- }
428406 const threadId = ThreadId . make ( "rollback-worktree" ) ;
429407 const projectId = ProjectId . make ( "rollback-worktree-project" ) ;
430408 const providerThreadId = ProviderThreadId . make ( "rollback-worktree-provider-thread" ) ;
@@ -434,19 +412,15 @@ it.effect.each(
434412 const scopeId = CheckpointScopeId . make ( "rollback-worktree-scope" ) ;
435413 const branch = "feature/rollback" ;
436414 const release = Deferred . makeUnsafe < void > ( ) ;
437- const releaseNew = Deferred . makeUnsafe < void > ( ) ;
438- const readEntered = Deferred . makeUnsafe < void > ( ) ;
439- let readCount = 0 ;
440- let newLeaseReleased = false ;
441415 const openEntered = Deferred . makeUnsafe < void > ( ) ;
442416 const calls : string [ ] = [ ] ;
443417 let cleanupEntered = false ;
444418 const providerThread = { id : providerThreadId , providerSessionId, providerInstanceId } ;
445- let projection = {
419+ const projection = {
446420 thread : {
447421 id : threadId ,
448422 projectId,
449- worktreePath : mutation === "root" ? null : threadPath ,
423+ worktreePath,
450424 branch,
451425 activeProviderThreadId : providerThreadId ,
452426 modelSelection : { instanceId : providerInstanceId , model : "test-model" } ,
@@ -505,16 +479,7 @@ it.effect.each(
505479 } ) ,
506480 IdAllocator . layer ,
507481 Layer . mock ( ProjectionStore . ProjectionStoreV2 ) ( {
508- getThreadRecords : ( ) => {
509- const current = projection ;
510- readCount ++ ;
511- return readCount === 1 && mutation !== "none"
512- ? Deferred . succeed ( readEntered , undefined ) . pipe (
513- Effect . andThen ( Deferred . await ( release ) ) ,
514- Effect . as ( current ) ,
515- )
516- : Effect . succeed ( current ) ;
517- } ,
482+ getThreadRecords : ( ) => Effect . succeed ( projection ) ,
518483 getShellSnapshot : ( ) =>
519484 Effect . succeed ( {
520485 schemaVersion : 1 ,
@@ -526,7 +491,6 @@ it.effect.each(
526491 Layer . mock ( ProviderSessionManager . ProviderSessionManagerV2 ) ( {
527492 open : ( input ) =>
528493 Effect . gen ( function * ( ) {
529- if ( mutation !== "none" ) assert . isTrue ( newLeaseReleased ) ;
530494 assert . equal ( input . runtimePolicy . cwd , worktreePath ) ;
531495 if ( ! ( yield * fileSystem . exists ( worktreePath ) . pipe ( Effect . orDie ) ) ) {
532496 return yield * new ProviderWorkspaceMissingError ( { threadId, cwd : worktreePath } ) ;
@@ -549,11 +513,11 @@ it.effect.each(
549513 yield * Effect . gen ( function * ( ) {
550514 const service = yield * CheckpointRollbackService . CheckpointRollbackServiceV2 ;
551515 const cleanupEffect = withWorkspaceLease (
552- initialWorktreePath ,
516+ worktreePath ,
553517 Effect . gen ( function * ( ) {
554518 cleanupEntered = true ;
555519 if ( order === "cleanup-first" ) yield * Deferred . await ( release ) ;
556- yield * fileSystem . remove ( initialWorktreePath , { recursive : true , force : true } ) ;
520+ yield * fileSystem . remove ( worktreePath , { recursive : true , force : true } ) ;
557521 calls . push ( "cleanup" ) ;
558522 } ) ,
559523 ) ;
@@ -564,32 +528,6 @@ it.effect.each(
564528 const rollback = yield * service
565529 . execute ( { threadId, providerThreadId, checkpointId, scopeId, restoreFiles } )
566530 . pipe ( Effect . forkChild ( { startImmediately : true } ) ) ;
567- if ( mutation !== "none" ) yield * Deferred . await ( readEntered ) ;
568- const newPath = path . join ( workspaceRoot , "new-worktree" ) ;
569- const newHolder =
570- mutation !== "none"
571- ? yield * withWorkspaceLease (
572- newPath ,
573- Deferred . await ( releaseNew ) . pipe (
574- Effect . andThen (
575- Effect . sync ( ( ) => {
576- newLeaseReleased = true ;
577- } ) ,
578- ) ,
579- ) ,
580- ) . pipe ( Effect . forkChild ( { startImmediately : true } ) )
581- : undefined ;
582- if ( mutation !== "none" ) {
583- worktreePath = newPath ;
584- projection = {
585- ...projection ,
586- thread : { ...projection . thread , worktreePath } ,
587- checkpointScopes : projection . checkpointScopes . map ( ( scope ) => ( {
588- ...scope ,
589- cwd : worktreePath ,
590- } ) ) ,
591- } ;
592- }
593531 if ( order === "cleanup-first" ) assert . deepEqual ( calls , [ ] ) ;
594532 if ( order === "rollback-first" ) yield * Deferred . await ( openEntered ) ;
595533 const laterCleanup =
@@ -599,11 +537,6 @@ it.effect.each(
599537 if ( order === "rollback-first" ) assert . isFalse ( cleanupEntered ) ;
600538 yield * Deferred . succeed ( release , undefined ) ;
601539 if ( cleanup !== undefined ) yield * Fiber . join ( cleanup ) ;
602- if ( newHolder !== undefined ) {
603- assert . deepEqual ( calls , [ "cleanup" ] ) ;
604- yield * Deferred . succeed ( releaseNew , undefined ) ;
605- yield * Fiber . join ( newHolder ) ;
606- }
607540 yield * Fiber . join ( rollback ) ;
608541 if ( laterCleanup !== undefined ) yield * Fiber . join ( laterCleanup ) ;
609542 const rollbackCalls = restoreFiles
@@ -614,11 +547,7 @@ it.effect.each(
614547 order === "cleanup-first"
615548 ? [ "cleanup" , "prune" , "create" , ...rollbackCalls ]
616549 : order === "rollback-first"
617- ? [
618- ...( alias === "missing-parent" || alias === "dangling" ? [ "prune" , "create" ] : [ ] ) ,
619- ...rollbackCalls ,
620- "cleanup" ,
621- ]
550+ ? [ ...rollbackCalls , "cleanup" ]
622551 : rollbackCalls ,
623552 ) ;
624553 } ) . pipe ( Effect . provide ( testLayer ) ) ;
0 commit comments