@@ -50,6 +50,7 @@ import * as Stream from "effect/Stream";
5050import * as TestClock from "effect/testing/TestClock" ;
5151import * as SqlClient from "effect/sql/SqlClient" ;
5252
53+ import { createAttachmentId } from "../attachmentStore.ts" ;
5354import * as CheckpointStore from "../checkpointing/CheckpointStore.ts" ;
5455import * as GitWorkflow from "../git/GitWorkflowService.ts" ;
5556import * as ServerConfig from "../config.ts" ;
@@ -2838,7 +2839,158 @@ it.layer(layerLegacyImportTest)("OrchestrationV2 legacy import", (it) => {
28382839 ) ;
28392840} ) ;
28402841
2842+ const writeHtmlRenderRun = Effect . fn ( "test.writeHtmlRenderRun" ) ( function * ( input : {
2843+ readonly threadId : ThreadId ;
2844+ readonly key : string ;
2845+ readonly ordinal : number ;
2846+ } ) {
2847+ const eventSink = yield * EventSink . EventSinkV2 ;
2848+ const now = yield * DateTime . now ;
2849+ const runId = RunId . make ( `html-fork-run:${ input . key } ` ) ;
2850+ const messageId = MessageId . make ( `html-fork-message:${ input . key } ` ) ;
2851+ const attachmentId = createAttachmentId ( input . threadId , "html" ) ! ;
2852+ yield * eventSink . write ( {
2853+ events : [
2854+ {
2855+ id : EventId . make ( `html-fork-run:${ input . key } ` ) ,
2856+ type : "run.created" ,
2857+ threadId : input . threadId ,
2858+ runId,
2859+ occurredAt : now ,
2860+ payload : {
2861+ id : runId ,
2862+ threadId : input . threadId ,
2863+ ordinal : input . ordinal ,
2864+ providerInstanceId : modelSelection . instanceId ,
2865+ modelSelection,
2866+ providerThreadId : null ,
2867+ userMessageId : messageId ,
2868+ rootNodeId : null ,
2869+ activeAttemptId : null ,
2870+ status : "completed" ,
2871+ requestedAt : now ,
2872+ startedAt : now ,
2873+ completedAt : now ,
2874+ checkpointId : null ,
2875+ contextHandoffId : null ,
2876+ } ,
2877+ } ,
2878+ {
2879+ id : EventId . make ( `html-fork-message:${ input . key } ` ) ,
2880+ type : "message.updated" ,
2881+ threadId : input . threadId ,
2882+ runId,
2883+ occurredAt : now ,
2884+ payload : {
2885+ id : messageId ,
2886+ threadId : input . threadId ,
2887+ runId,
2888+ nodeId : null ,
2889+ role : "user" ,
2890+ text : "Publish a page" ,
2891+ attachments : [ ] ,
2892+ streaming : false ,
2893+ createdBy : "user" ,
2894+ creationSource : "web" ,
2895+ createdAt : now ,
2896+ updatedAt : now ,
2897+ } ,
2898+ } ,
2899+ {
2900+ id : EventId . make ( `html-fork-item:${ input . key } ` ) ,
2901+ type : "turn-item.updated" ,
2902+ threadId : input . threadId ,
2903+ runId,
2904+ occurredAt : now ,
2905+ payload : {
2906+ id : TurnItemId . make ( `html-fork-item:${ input . key } ` ) ,
2907+ type : "dynamic_tool" ,
2908+ threadId : input . threadId ,
2909+ runId,
2910+ nodeId : null ,
2911+ providerThreadId : null ,
2912+ providerTurnId : null ,
2913+ nativeItemRef : null ,
2914+ parentItemId : null ,
2915+ ordinal : 0 ,
2916+ status : "completed" ,
2917+ title : null ,
2918+ startedAt : now ,
2919+ completedAt : now ,
2920+ updatedAt : now ,
2921+ toolName : "mcp__t3-code__html_render" ,
2922+ input : { } ,
2923+ output : [
2924+ {
2925+ type : "text" ,
2926+ text : JSON . stringify ( { htmlRender : { attachmentId, title : "Page" , height : 300 } } ) ,
2927+ } ,
2928+ ] ,
2929+ } ,
2930+ } ,
2931+ ] ,
2932+ } ) ;
2933+ return { runId, attachmentId } ;
2934+ } ) ;
2935+
28412936it . layer ( layerTest ) ( "OrchestrationV2LayerLive lifecycle" , ( it ) => {
2937+ it . effect ( "deleting a source keeps the html_render page its live fork shows" , ( ) =>
2938+ Effect . gen ( function * ( ) {
2939+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
2940+ const outbox = yield * EffectOutbox . EffectOutboxV2 ;
2941+ const sourceThreadId = ThreadId . make ( "html-fork-source" ) ;
2942+ const forkThreadId = ThreadId . make ( "html-fork-target" ) ;
2943+ yield * orchestrator . dispatch ( {
2944+ type : "thread.create" ,
2945+ commandId : CommandId . make ( "html-fork-create" ) ,
2946+ threadId : sourceThreadId ,
2947+ projectId : ProjectId . make ( "html-fork-project" ) ,
2948+ title : "Page source" ,
2949+ modelSelection,
2950+ runtimeMode : "full-access" ,
2951+ interactionMode : "default" ,
2952+ branch : null ,
2953+ worktreePath : null ,
2954+ createdBy : "user" ,
2955+ creationSource : "web" ,
2956+ } ) ;
2957+ const inherited = yield * writeHtmlRenderRun ( {
2958+ threadId : sourceThreadId ,
2959+ key : "inherited" ,
2960+ ordinal : 1 ,
2961+ } ) ;
2962+ yield * orchestrator . dispatch ( {
2963+ type : "thread.fork" ,
2964+ commandId : CommandId . make ( "html-fork-fork" ) ,
2965+ sourceThreadId,
2966+ targetThreadId : forkThreadId ,
2967+ sourcePoint : { type : "run" , runId : inherited . runId } ,
2968+ createdBy : "user" ,
2969+ creationSource : "web" ,
2970+ } ) ;
2971+ const later = yield * writeHtmlRenderRun ( {
2972+ threadId : sourceThreadId ,
2973+ key : "later" ,
2974+ ordinal : 2 ,
2975+ } ) ;
2976+ const deleteCommandId = CommandId . make ( "html-fork-delete-source" ) ;
2977+ yield * orchestrator . dispatch ( {
2978+ type : "thread.delete" ,
2979+ commandId : deleteCommandId ,
2980+ threadId : sourceThreadId ,
2981+ } ) ;
2982+ const cleaned = ( yield * outbox . listByCommandId ( deleteCommandId ) ) . flatMap ( ( effect ) =>
2983+ effect . request . type === "attachment.cleanup" ? effect . request . attachmentIds : [ ] ,
2984+ ) ;
2985+ assert . include ( cleaned , later . attachmentId ) ;
2986+ assert . notInclude (
2987+ cleaned ,
2988+ inherited . attachmentId ,
2989+ "deleted a page its live fork still shows" ,
2990+ ) ;
2991+ } ) ,
2992+ ) ;
2993+
28422994 it . effect ( "applies lifecycle commands idempotently and emits archive/removal shell deltas" , ( ) =>
28432995 Effect . gen ( function * ( ) {
28442996 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
0 commit comments