@@ -2090,6 +2090,7 @@ it.effect("MCP replays accepted launches and checks worktree membership", () =>
20902090 title : "Only once" ,
20912091 projectId,
20922092 clientRequestId : "lost-response" ,
2093+ runtimeMode : "approval-required" as const ,
20932094 message : "Do the work" ,
20942095 workspaceStrategy : { type : "worktree" as const , baseRef : "temporary-base" } ,
20952096 } ;
@@ -2166,7 +2167,24 @@ it.effect("MCP replays accepted launches and checks worktree membership", () =>
21662167 { code : "invalid_request" } ,
21672168 ) ;
21682169 const threadId = ThreadId . make ( "mcp:launch:client%3Alaunch-retry:lost-response" ) ;
2170+ assert . equal ( ( yield * threads . getThreadShell ( threadId ) ) ?. runtimeMode , "approval-required" ) ;
2171+ yield * threads . dispatch ( {
2172+ type : "thread.runtime-mode.set" ,
2173+ commandId : CommandId . make ( "owner:raise-launch-modes" ) ,
2174+ threadId,
2175+ runtimeMode : "full-access" ,
2176+ } ) ;
2177+ assert . include (
2178+ yield * launch ( input ) . pipe (
2179+ Effect . provideService ( McpInvocationContext . McpInvocationContext , {
2180+ ...context ,
2181+ client : { ...context . client ! , access : "approval-required" } ,
2182+ } ) ,
2183+ ) ,
2184+ { code : "orchestration_error" } ,
2185+ ) ;
21692186 const projection = yield * threads . getThreadProjection ( threadId ) ;
2187+ assert . equal ( projection . thread . runtimeMode , "full-access" ) ;
21702188 assert . equal ( projection . messages . length , 1 ) ;
21712189 assert . equal ( projection . runs . length , 1 ) ;
21722190 assert . equal ( projection . runs [ 0 ] ?. status , "preparing" ) ;
@@ -2183,6 +2201,15 @@ it.effect("MCP replays accepted launches and checks worktree membership", () =>
21832201 ) ,
21842202 Stream . runHead ,
21852203 ) ;
2204+ assert . include (
2205+ yield * launch ( input ) . pipe (
2206+ Effect . provideService ( McpInvocationContext . McpInvocationContext , {
2207+ ...context ,
2208+ client : { ...context . client ! , access : "approval-required" } ,
2209+ } ) ,
2210+ ) ,
2211+ { threadId, status : "starting" } ,
2212+ ) ;
21862213 } ) . pipe ( Effect . provide ( dependencies ) ) ;
21872214 } ) ,
21882215) ;
@@ -2588,19 +2615,38 @@ it.effect("schedules an accepted preparing message exactly once across concurren
25882615 text : "Resume preparation" ,
25892616 attachments : [ ] ,
25902617 modelSelection : input . modelSelection ,
2591- dispatchMode : { type : "defer_start" } ,
2618+ dispatchMode : { type : "defer_start" , workspaceStrategy : input . workspaceStrategy } ,
25922619 createdBy : input . createdBy ,
25932620 creationSource : input . creationSource ,
25942621 } ) ;
25952622 const preparing = yield * threads . getThreadProjection ( input . threadId ) ;
25962623 assert . equal ( preparing . runs [ 0 ] ?. status , "preparing" ) ;
25972624
2598- const [ first , second ] = yield * Effect . all ( [ launches . launch ( input ) , launches . launch ( input ) ] , {
2625+ const retry = { ...input , workspaceStrategy : { type : "root" as const } } ;
2626+ const [ first , second ] = yield * Effect . all ( [ launches . launch ( retry ) , launches . launch ( retry ) ] , {
25992627 concurrency : "unbounded" ,
26002628 } ) ;
2601- yield * Deferred . await ( setupEntered ) ;
2629+ const prepared = yield * Effect . raceFirst (
2630+ Deferred . await ( setupEntered ) . pipe ( Effect . as ( true ) ) ,
2631+ threads . streamStoredEventsFrom ( { threadId : input . threadId } ) . pipe (
2632+ Stream . filter (
2633+ ( stored ) =>
2634+ stored . commandId === CommandId . make ( input . commandId + ":release" ) &&
2635+ stored . event . type === "run.updated" ,
2636+ ) ,
2637+ Stream . runHead ,
2638+ Effect . as ( false ) ,
2639+ ) ,
2640+ ) ;
2641+ assert . isTrue ( prepared , "the accepted worktree setup must run before releasing the run" ) ;
26022642 assert . isTrue ( first . resumed ) ;
26032643 assert . isTrue ( second . resumed ) ;
2644+ assert . equal ( harness . createWorktree . mock . calls . length , 1 ) ;
2645+ assert . equal ( harness . runSetup . mock . calls [ 0 ] ?. [ 0 ] . worktreePath , "/repo-worktrees/feature" ) ;
2646+ assert . deepEqual (
2647+ ( yield * threads . getThreadProjection ( input . threadId ) ) . runs [ 0 ] ?. workspacePreparation ,
2648+ input . workspaceStrategy ,
2649+ ) ;
26042650 assert . equal ( harness . runSetup . mock . calls . length , 1 ) ;
26052651 yield * Deferred . succeed ( allowSetup , undefined ) ;
26062652 } ) . pipe ( Effect . provide ( harness . layer ) ) ;
0 commit comments