@@ -37,6 +37,7 @@ function makeProjection(): ProjectionCheckpointContext {
3737 {
3838 scopeId : secondScopeId ,
3939 runId : secondRunId ,
40+ ordinalWithinScope : 1 ,
4041 appRunOrdinal : 2 ,
4142 status : "ready" ,
4243 ref : secondRef ,
@@ -200,6 +201,90 @@ it.effect("excludes ready checkpoints from rolled-back runs", () => {
200201 } ) . pipe ( Effect . provide ( layer ) ) ;
201202} ) ;
202203
204+ function makeProjectionAfterStoppedRun ( stoppedRunCheckpoint : boolean ) {
205+ const thirdRunId = RunId . make ( "run:checkpoint-diff-v2:3" ) ;
206+ const checkpoint = (
207+ ordinalWithinScope : number ,
208+ runId : RunId | null ,
209+ ) : ProjectionCheckpointContext [ "checkpoints" ] [ number ] => ( {
210+ scopeId : firstScopeId ,
211+ runId,
212+ ordinalWithinScope,
213+ appRunOrdinal : runId === null ? null : ordinalWithinScope ,
214+ status : "ready" ,
215+ ref : CheckpointRef . make ( `refs/t3/test/ordinal/${ ordinalWithinScope } ` ) ,
216+ } ) ;
217+ return {
218+ runs : [
219+ { id : firstRunId , ordinal : 1 , status : "completed" } ,
220+ { id : secondRunId , ordinal : 2 , status : "interrupted" } ,
221+ { id : thirdRunId , ordinal : 3 , status : "completed" } ,
222+ ] ,
223+ checkpointScopes : [
224+ { id : firstScopeId , runId : thirdRunId , kind : "root_run" , cwd : "/repo" } ,
225+ { id : secondScopeId , runId : secondRunId , kind : "tool" , cwd : "/repo" } ,
226+ ] ,
227+ checkpoints : [
228+ {
229+ ...checkpoint ( 2 , null ) ,
230+ scopeId : secondScopeId ,
231+ ref : CheckpointRef . make ( "refs/t3/test/tool/2" ) ,
232+ } ,
233+ checkpoint ( 0 , null ) ,
234+ checkpoint ( 1 , firstRunId ) ,
235+ checkpoint ( 2 , stoppedRunCheckpoint ? secondRunId : null ) ,
236+ checkpoint ( 3 , thirdRunId ) ,
237+ ] ,
238+ } satisfies ProjectionCheckpointContext ;
239+ }
240+
241+ it . effect . each ( [ false , true ] ) (
242+ "diffs the turn after a stopped run from its parent checkpoint (stopped run captured: %s)" ,
243+ ( stoppedRunCheckpoint ) => {
244+ const diffCheckpoints = vi . fn ( ( _input : CheckpointStore . DiffCheckpointsInput ) =>
245+ Effect . succeed ( "diff --git a/file b/file" ) ,
246+ ) ;
247+ const layer = layerFor ( {
248+ projection : Effect . succeed ( makeProjectionAfterStoppedRun ( stoppedRunCheckpoint ) ) ,
249+ diffCheckpoints,
250+ } ) ;
251+
252+ return Effect . gen ( function * ( ) {
253+ const query = yield * CheckpointDiffQuery . CheckpointDiffQuery ;
254+ const result = yield * query . getTurnDiff ( { threadId, fromTurnCount : 2 , toTurnCount : 3 } ) ;
255+
256+ assert . strictEqual ( result . diff , "diff --git a/file b/file" ) ;
257+ yield * query . getTurnDiff ( { threadId, fromTurnCount : 1 , toTurnCount : 3 } ) ;
258+ yield * query . getFullThreadDiff ( { threadId, toTurnCount : 3 } ) ;
259+ assert . deepEqual (
260+ diffCheckpoints . mock . calls . map ( ( [ input ] ) => ( {
261+ from : input . fromCheckpointRef ,
262+ to : input . toCheckpointRef ,
263+ } ) ) ,
264+ [
265+ { from : "refs/t3/test/ordinal/2" , to : "refs/t3/test/ordinal/3" } ,
266+ { from : "refs/t3/test/ordinal/1" , to : "refs/t3/test/ordinal/3" } ,
267+ {
268+ from : yield * checkpointRefForScopeOrdinal ( {
269+ scopeId : firstScopeId ,
270+ ordinalWithinScope : 0 ,
271+ } ) ,
272+ to : "refs/t3/test/ordinal/3" ,
273+ } ,
274+ ] ,
275+ ) ;
276+ const stoppedTurnError = yield * query
277+ . getTurnDiff ( { threadId, fromTurnCount : 1 , toTurnCount : 2 } )
278+ . pipe ( Effect . flip ) ;
279+ assert . instanceOf ( stoppedTurnError , CheckpointRefUnavailableError ) ;
280+ assert . deepEqual (
281+ { checkpoint : stoppedTurnError . checkpoint , turnCount : stoppedTurnError . turnCount } ,
282+ { checkpoint : "to" , turnCount : 2 } ,
283+ ) ;
284+ } ) . pipe ( Effect . provide ( layer ) ) ;
285+ } ,
286+ ) ;
287+
203288it . effect ( "preserves the typed missing-baseline-ref error contract" , ( ) => {
204289 const projection = makeProjection ( ) ;
205290 const layer = layerFor ( {
0 commit comments