@@ -26,6 +26,7 @@ import {
2626 type ServerProvider ,
2727 ThreadId ,
2828 TextGenerationError ,
29+ ServerSettingsError ,
2930} from "@t3tools/contracts" ;
3031import * as Cause from "effect/Cause" ;
3132import * as Deferred from "effect/Deferred" ;
@@ -127,6 +128,7 @@ interface HarnessOptions {
127128 readonly generateTitle ?: TextGeneration . TextGeneration [ "Service" ] [ "generateThreadTitle" ] ;
128129 readonly generateBranchName ?: TextGeneration . TextGeneration [ "Service" ] [ "generateBranchName" ] ;
129130 readonly serverSettings ?: Parameters < typeof ServerSettings . layerTest > [ 0 ] ;
131+ readonly getLaunchSettings ?: ServerSettings . ServerSettingsService [ "Service" ] [ "getSettings" ] ;
130132 readonly providers ?: ReadonlyArray < ServerProvider > ;
131133 readonly git ?: Partial < GitWorkflow . GitWorkflowService [ "Service" ] > ;
132134}
@@ -229,6 +231,11 @@ function makeHarness(options: HarnessOptions = {}) {
229231 layerThreadManagement ,
230232 layerReceipts ,
231233 IdAllocator . layer ,
234+ options . getLaunchSettings === undefined
235+ ? Layer . empty
236+ : Layer . mock ( ServerSettings . ServerSettingsService ) ( {
237+ getSettings : options . getLaunchSettings ,
238+ } ) ,
232239 ) ,
233240 ) ,
234241 ) ;
@@ -962,6 +969,35 @@ it.effect.each([
962969 } ) ,
963970) ;
964971
972+ it . effect (
973+ "starts a worktree with the default temporary name when settings secrets cannot be read" ,
974+ ( ) => {
975+ const harness = makeHarness ( {
976+ getLaunchSettings : Effect . fail (
977+ new ServerSettingsError ( { settingsPath : "/settings.json" , operation : "read-secret" } ) ,
978+ ) ,
979+ } ) ;
980+ return Effect . gen ( function * ( ) {
981+ const launches = yield * ThreadLaunch . ThreadLaunchService ;
982+ const launched = yield * launches . launch (
983+ launchInput ( {
984+ command : "settings-fallback" ,
985+ thread : "settings-fallback-thread" ,
986+ message : "Fix the parser" ,
987+ workspace : { type : "worktree" , baseRef : "main" } ,
988+ } ) ,
989+ ) ;
990+ const projection = yield * preparationSettled ( launched . threadId ) ;
991+ assert . equal ( projection . runs [ 0 ] ?. status , "starting" ) ;
992+ assert . match ( projection . thread . branch ! , / ^ t 3 \/ [ 0 - 9 a - f ] { 8 } $ / ) ;
993+ assert . equal ( harness . createWorktree . mock . calls [ 0 ] ?. [ 0 ] ?. newRefName , projection . thread . branch ) ;
994+ assert . equal ( harness . runSetup . mock . calls . length , 1 ) ;
995+ assert . equal ( harness . renameBranch . mock . calls . length , 0 ) ;
996+ assert . isFalse ( projection . turnItems . some ( ( item ) => item . type === "error" ) ) ;
997+ } ) . pipe ( Effect . provide ( harness . layer ) ) ;
998+ } ,
999+ ) ;
1000+
9651001it . effect ( "renames a temporary branch with a configured prefix when generation succeeds" , ( ) => {
9661002 const harness = makeHarness ( {
9671003 serverSettings : { branchNamingMode : "static" , branchNamePrefix : "my-prefix" } ,
0 commit comments