@@ -1159,6 +1159,100 @@ it.effect("shows the fetch diagnosis when preparing a worktree from origin fails
11591159 } ) . pipe ( Effect . provide ( harness . layer ) ) ;
11601160} ) ;
11611161
1162+ it . effect ( "rejects a preparation retry after the project disables its provider" , ( ) => {
1163+ let fetchAttempts = 0 ;
1164+ const harness = makeHarness ( {
1165+ fetchWorktreeBaseCommit : ( ) =>
1166+ fetchAttempts ++ === 0
1167+ ? Effect . fail (
1168+ new GitCommandError ( {
1169+ operation : "GitVcsDriver.fetchRemote" ,
1170+ command : "git" ,
1171+ cwd : project . workspaceRoot ,
1172+ detail : "Git could not reach the remote." ,
1173+ exitCode : 128 ,
1174+ } ) ,
1175+ )
1176+ : Effect . succeed ( { commitSha : "remote-main-sha" , remoteRefName : "origin/main" } ) ,
1177+ } ) ;
1178+ return Effect . gen ( function * ( ) {
1179+ const launches = yield * ThreadLaunch . ThreadLaunchService ;
1180+ const settings = yield * ServerSettings . ServerSettingsService ;
1181+ const threads = yield * ThreadManagement . ThreadManagementService ;
1182+ const launched = yield * launches . launch (
1183+ launchInput ( {
1184+ command : "command:launch:disabled-preparation-retry" ,
1185+ thread : "thread:launch:disabled-preparation-retry" ,
1186+ message : "Start from origin" ,
1187+ workspace : { type : "worktree" , baseRef : "main" , startFromOrigin : true } ,
1188+ } ) ,
1189+ ) ;
1190+ yield * preparationSettled ( launched . threadId ) ;
1191+ yield * settings . updateSettings ( {
1192+ projectSettingsOverrides : {
1193+ [ projectId ] : { providerInstances : { [ modelSelection . instanceId ] : { enabled : false } } } ,
1194+ } ,
1195+ } ) ;
1196+
1197+ const error = yield * launches
1198+ . retryPreparation ( {
1199+ commandId : CommandId . make ( "command:launch:disabled-preparation-retry:retry" ) ,
1200+ threadId : launched . threadId ,
1201+ runId : launched . projection . runs [ 0 ] ! . id ,
1202+ } )
1203+ . pipe ( Effect . flip ) ;
1204+
1205+ assert . equal ( error . _tag , "ThreadManagementProviderInstanceDisabledError" ) ;
1206+ assert . equal ( ( yield * threads . getThreadProjection ( launched . threadId ) ) . runs [ 0 ] ?. status , "failed" ) ;
1207+ assert . equal ( fetchAttempts , 1 ) ;
1208+ } ) . pipe ( Effect . provide ( harness . layer ) ) ;
1209+ } ) ;
1210+
1211+ it . effect ( "does not release a prepared run after the project disables its provider" , ( ) => {
1212+ return Effect . gen ( function * ( ) {
1213+ const setupEntered = yield * Deferred . make < void > ( ) ;
1214+ const allowSetup = yield * Deferred . make < void > ( ) ;
1215+ const harness = makeHarness ( {
1216+ runSetup : ( ) =>
1217+ Deferred . succeed ( setupEntered , undefined ) . pipe (
1218+ Effect . andThen ( Deferred . await ( allowSetup ) ) ,
1219+ Effect . as ( { status : "no-script" as const } ) ,
1220+ ) ,
1221+ } ) ;
1222+ yield * Effect . gen ( function * ( ) {
1223+ const launches = yield * ThreadLaunch . ThreadLaunchService ;
1224+ const settings = yield * ServerSettings . ServerSettingsService ;
1225+ const launched = yield * launches . launch (
1226+ launchInput ( {
1227+ command : "command:launch:disable-during-preparation" ,
1228+ thread : "thread:launch:disable-during-preparation" ,
1229+ message : "Prepare a worktree" ,
1230+ workspace : { type : "worktree" , baseRef : "main" } ,
1231+ } ) ,
1232+ ) ;
1233+ yield * Deferred . await ( setupEntered ) ;
1234+ yield * settings . updateSettings ( {
1235+ projectSettingsOverrides : {
1236+ [ projectId ] : { providerInstances : { [ modelSelection . instanceId ] : { enabled : false } } } ,
1237+ } ,
1238+ } ) ;
1239+ yield * Deferred . succeed ( allowSetup , undefined ) ;
1240+ const projection = yield * preparationSettled ( launched . threadId ) ;
1241+ assert . equal ( projection . runs [ 0 ] ?. status , "failed" ) ;
1242+ const effects = yield * ( yield * EffectOutbox . EffectOutboxV2 ) . listByCommandId (
1243+ CommandId . make ( "command:launch:disable-during-preparation:release" ) ,
1244+ ) ;
1245+ assert . isFalse (
1246+ effects . some (
1247+ ( effect ) =>
1248+ effect . request . type === "provider-turn.start" &&
1249+ effect . request . runId === launched . projection . runs [ 0 ] ?. id ,
1250+ ) ,
1251+ ) ;
1252+ } ) . pipe ( Effect . provide ( harness . layer ) ) ;
1253+ } ) ;
1254+ } ) ;
1255+
11621256it . effect . each ( [ "fails" , "is interrupted" ] as const ) (
11631257 "holds a message queued during setup when the workspace preparation %s" ,
11641258 ( ending ) =>
0 commit comments