11import { assert , it } from "@effect/vitest" ;
22import {
33 CheckpointId ,
4+ CheckpointRef ,
5+ CheckpointScopeId ,
46 CommandId ,
57 EventId ,
68 MessageId ,
@@ -17,6 +19,7 @@ import {
1719} from "@t3tools/contracts" ;
1820import * as DateTime from "effect/DateTime" ;
1921import * as Effect from "effect/Effect" ;
22+ import * as Statement from "effect/sql/Statement" ;
2023import * as TestClock from "effect/testing/TestClock" ;
2124
2225import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts" ;
@@ -865,6 +868,61 @@ const askSideChat = (threadId: ThreadId, commandId: string) =>
865868 } ) ;
866869 } ) ;
867870
871+ it . effect ( "resolves an explicit checkpoint fork to its source run" , ( ) =>
872+ Effect . gen ( function * ( ) {
873+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
874+ const eventSink = yield * EventSink . EventSinkV2 ;
875+ const now = yield * DateTime . now ;
876+ const parentId = ThreadId . make ( "checkpoint-fork-parent" ) ;
877+ const childId = ThreadId . make ( "checkpoint-fork-child" ) ;
878+ const runId = RunId . make ( "checkpoint-fork-run" ) ;
879+ const checkpointId = CheckpointId . make ( "checkpoint-fork-checkpoint" ) ;
880+ yield * createParent ( parentId ) ;
881+ yield * writeParentRun ( {
882+ threadId : parentId ,
883+ runId,
884+ ordinal : 1 ,
885+ status : "completed" ,
886+ text : "Work" ,
887+ } ) ;
888+ yield * eventSink . write ( {
889+ events : [
890+ {
891+ id : EventId . make ( "checkpoint-fork-captured" ) ,
892+ type : "checkpoint.captured" ,
893+ threadId : parentId ,
894+ occurredAt : now ,
895+ payload : {
896+ id : checkpointId ,
897+ threadId : parentId ,
898+ scopeId : CheckpointScopeId . make ( "checkpoint-fork-scope" ) ,
899+ runId,
900+ nodeId : NodeId . make ( "checkpoint-fork-node" ) ,
901+ parentCheckpointId : null ,
902+ ordinalWithinScope : 1 ,
903+ appRunOrdinal : 1 ,
904+ ref : CheckpointRef . make ( "refs/t3/checkpoint-fork/1" ) ,
905+ status : "ready" ,
906+ files : [ ] ,
907+ capturedAt : now ,
908+ } ,
909+ } ,
910+ ] ,
911+ } ) ;
912+ yield * orchestrator . dispatch ( {
913+ type : "thread.fork" ,
914+ commandId : CommandId . make ( "checkpoint-fork" ) ,
915+ sourceThreadId : parentId ,
916+ targetThreadId : childId ,
917+ sourcePoint : { type : "checkpoint" , checkpointId } ,
918+ createdBy : "user" ,
919+ creationSource : "mcp" ,
920+ } ) ;
921+ const child = yield * orchestrator . getThreadShell ( childId ) ;
922+ assert . deepEqual ( child ?. forkedFrom , { type : "run" , threadId : parentId , runId } ) ;
923+ } ) . pipe ( Effect . provide ( forkCases [ 0 ] ! . layer ) ) ,
924+ ) ;
925+
868926it . effect ( "a side chat of an idle parent still starts with the framing note" , ( ) =>
869927 Effect . gen ( function * ( ) {
870928 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
@@ -880,7 +938,22 @@ it.effect("a side chat of an idle parent still starts with the framing note", ()
880938 stable : true ,
881939 } ) ;
882940
883- yield * forkSideChat ( "side-chat-idle-fork" , parentId , sideChatId ) ;
941+ const reads : Array < string > = [ ] ;
942+ const recordReads : Statement . Transformer = ( statement ) => {
943+ const [ query ] = statement . compile ( ) ;
944+ if ( / ^ \s * S E L E C T / i. test ( query ) ) reads . push ( query ) ;
945+ return Effect . succeed ( statement ) ;
946+ } ;
947+ yield * forkSideChat ( "side-chat-idle-fork" , parentId , sideChatId ) . pipe (
948+ Effect . provideService ( Statement . CurrentTransformer , recordReads ) ,
949+ ) ;
950+ assert . isEmpty (
951+ reads . filter (
952+ ( query ) =>
953+ query . includes ( "FROM orchestration_v2_projection_checkpoints" ) ||
954+ query . includes ( "FROM orchestration_v2_projection_context_transfers" ) ,
955+ ) ,
956+ ) ;
884957 yield * askSideChat ( sideChatId , "side-chat-idle-first-message" ) ;
885958
886959 const started = yield * orchestrator . getThreadProjection ( sideChatId ) ;
0 commit comments