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