@@ -961,6 +961,82 @@ it.effect("serves the shared thread's files to its guest, never another thread's
961961 } ) . pipe ( Effect . scoped , Effect . provide ( layerTest ) ) ,
962962) ;
963963
964+ it . effect ( "gives a fork's guest the files on messages the fork shows from its source" , ( ) =>
965+ Effect . gen ( function * ( ) {
966+ const { orchestrator } = yield * shareThread ;
967+ const guestShares = yield * GuestShareService . GuestShareService ;
968+ const { attachmentsDir } = yield * ServerConfig . ServerConfig ;
969+ const fileSystem = yield * FileSystem . FileSystem ;
970+ const ownerImage = Effect . fn ( function * ( name : string ) {
971+ const image = {
972+ type : "image" as const ,
973+ id : ChatAttachmentId . make ( createAttachmentId ( threadId ) ! ) ,
974+ name,
975+ mimeType : "image/png" ,
976+ sizeBytes : PNG . length ,
977+ } ;
978+ yield * fileSystem . writeFile (
979+ resolveAttachmentPath ( { attachmentsDir, attachment : image } ) ! ,
980+ PNG ,
981+ ) ;
982+ yield * orchestrator . dispatch ( {
983+ type : "message.dispatch" ,
984+ commandId : CommandId . make ( `owner:${ name } ` ) ,
985+ threadId,
986+ messageId : MessageId . make ( `message:${ name } ` ) ,
987+ text : name ,
988+ attachments : [ image ] ,
989+ dispatchMode : { type : "defer_start" } ,
990+ createdBy : "user" ,
991+ creationSource : "web" ,
992+ } ) ;
993+ return image ;
994+ } ) ;
995+ const inherited = yield * ownerImage ( "before.png" ) ;
996+ const run = ( yield * orchestrator . getThreadRecords ( threadId , [ "runs" ] ) ) . runs [ 0 ] ! ;
997+ const now = yield * DateTime . now ;
998+ yield * ( yield * EventSink . EventSinkV2 ) . write ( {
999+ events : [
1000+ {
1001+ id : EventId . make ( "event:run-done" ) ,
1002+ type : "run.updated" ,
1003+ threadId,
1004+ runId : run . id ,
1005+ providerInstanceId : instanceId ,
1006+ occurredAt : now ,
1007+ payload : { ...run , status : "completed" , completedAt : now } ,
1008+ } ,
1009+ ] ,
1010+ } ) ;
1011+ const forkId = ThreadId . make ( "thread:guest-share-fork" ) ;
1012+ yield * orchestrator . dispatch ( {
1013+ type : "thread.fork" ,
1014+ commandId : CommandId . make ( "fork" ) ,
1015+ sourceThreadId : threadId ,
1016+ targetThreadId : forkId ,
1017+ sourcePoint : { type : "run" , runId : run . id } ,
1018+ createdBy : "user" ,
1019+ creationSource : "web" ,
1020+ } ) ;
1021+ const later = yield * ownerImage ( "after.png" ) ;
1022+ const { url } = yield * guestShares . create ( { threadId : forkId } ) ;
1023+ const { token : session } = yield * guestShares . redeem ( {
1024+ credential : url . slice ( url . indexOf ( "#" ) + 1 ) ,
1025+ name : "Sam" ,
1026+ } ) ;
1027+
1028+ assert . equal (
1029+ ( yield * guestShares . attachment ( session , inherited . id ) ) . attachment . id ,
1030+ inherited . id ,
1031+ ) ;
1032+ // The source's messages after the fork point are not part of the fork.
1033+ assert . equal (
1034+ ( yield * Effect . flip ( guestShares . attachment ( session , later . id ) ) ) . reason ,
1035+ "unavailable" ,
1036+ ) ;
1037+ } ) . pipe ( Effect . provide ( layerTest ) ) ,
1038+ ) ;
1039+
9641040it . effect ( "serves an image on the host only when an agent reply the guest sees shows it" , ( ) =>
9651041 Effect . gen ( function * ( ) {
9661042 const { orchestrator, guestShares } = yield * shareThread ;
0 commit comments