@@ -861,6 +861,63 @@ it.effect.each([1_700_000_000, 1_700_000_000.9999])(
861861 } ) . pipe ( Effect . scoped , Effect . provide ( layerGitContract ) ) ,
862862) ;
863863
864+ it . effect ( "a branch switch landing after the snapshot belongs to the next checkpoint" , ( ) =>
865+ Effect . gen ( function * ( ) {
866+ const fileSystem = yield * FileSystem . FileSystem ;
867+ const path = yield * Path . Path ;
868+ const liveProcess = yield * VcsProcess . VcsProcess ;
869+ const driver = yield * GitVcsDriver . makeVcsDriverShape ( ) ;
870+ const cwd = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3-checkpoint-switch-race-" } ) ;
871+ const git = ( args : ReadonlyArray < string > ) =>
872+ driver . execute ( { operation : "checkpoint-test" , cwd, args } ) ;
873+ yield * git ( [ "init" ] ) ;
874+ yield * git ( [ "config" , "user.name" , "Test" ] ) ;
875+ yield * git ( [ "config" , "user.email" , "[email protected] " ] ) ; 876+ yield * fileSystem . writeFileString ( path . join ( cwd , "f.txt" ) , "A\n" ) ;
877+ yield * git ( [ "add" , "." ] ) ;
878+ yield * git ( [ "commit" , "-m" , "a" ] ) ;
879+ yield * git ( [ "checkout" , "-b" , "b" ] ) ;
880+ yield * fileSystem . writeFileString ( path . join ( cwd , "f.txt" ) , "B\n" ) ;
881+ yield * git ( [ "commit" , "-am" , "b" ] ) ;
882+ yield * git ( [ "checkout" , "-" ] ) ;
883+ const [ first , second , third ] = [ "1" , "2" , "3" ] . map ( ( turn ) =>
884+ CheckpointRef . make ( `refs/t3/checkpoints/switch-race/${ turn } ` ) ,
885+ ) as [ CheckpointRef , CheckpointRef , CheckpointRef ] ;
886+ const racedDriver = yield * GitVcsDriver . makeVcsDriverShape ( ) . pipe (
887+ Effect . provideService ( VcsProcess . VcsProcess , {
888+ run : Effect . fn ( function * ( input : VcsProcess . VcsProcessInput ) {
889+ const result = yield * liveProcess . run ( input ) ;
890+ if ( input . args . includes ( "write-tree" ) ) yield * git ( [ "checkout" , "b" ] ) . pipe ( Effect . orDie ) ;
891+ return result ;
892+ } ) ,
893+ } ) ,
894+ ) ;
895+ const changedSince = ( fromCheckpointRef : CheckpointRef , toCheckpointRef : CheckpointRef ) =>
896+ Effect . gen ( function * ( ) {
897+ const refs = { cwd, fromCheckpointRef, toCheckpointRef } ;
898+ return {
899+ patch : yield * driver . checkpoints . diffCheckpoints ( { ...refs , ignoreWhitespace : false } ) ,
900+ authored : yield * driver . checkpoints . listAuthoredPaths ( refs ) ,
901+ } ;
902+ } ) ;
903+
904+ yield * driver . checkpoints . captureCheckpoint ( { cwd, checkpointRef : first } ) ;
905+ yield * racedDriver . checkpoints . captureCheckpoint ( {
906+ cwd,
907+ checkpointRef : second ,
908+ previousCheckpointRef : first ,
909+ } ) ;
910+ yield * driver . checkpoints . captureCheckpoint ( {
911+ cwd,
912+ checkpointRef : third ,
913+ previousCheckpointRef : second ,
914+ } ) ;
915+
916+ assert . deepEqual ( yield * changedSince ( first , second ) , { patch : "" , authored : null } ) ;
917+ assert . deepEqual ( yield * changedSince ( second , third ) , { patch : "" , authored : null } ) ;
918+ } ) . pipe ( Effect . scoped , Effect . provide ( layerGitContract ) ) ,
919+ ) ;
920+
864921it . effect ( "checkpoint capture preserves racy edits made after resetting the index" , ( ) =>
865922 Effect . gen ( function * ( ) {
866923 const fileSystem = yield * FileSystem . FileSystem ;
@@ -1051,6 +1108,7 @@ it.effect.each(["committed", "unborn"] as const)(
10511108
10521109 assert . deepStrictEqual ( commands , [
10531110 "rev-parse" ,
1111+ ...( head === "committed" ? [ "log" ] : [ ] ) ,
10541112 "config" ,
10551113 ...( head === "committed" ? [ "read-tree" , "ls-files" ] : [ ] ) ,
10561114 "add" ,
0 commit comments