Skip to content

Commit c4b9a60

Browse files
committed
fix(server): keep worktree creation resilient to settings failures
1 parent 3325bfc commit c4b9a60

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
type ServerProvider,
2727
ThreadId,
2828
TextGenerationError,
29+
ServerSettingsError,
2930
} from "@t3tools/contracts";
3031
import * as Cause from "effect/Cause";
3132
import * 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!, /^t3\/[0-9a-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+
9651001
it.effect("renames a temporary branch with a configured prefix when generation succeeds", () => {
9661002
const harness = makeHarness({
9671003
serverSettings: { branchNamingMode: "static", branchNamePrefix: "my-prefix" },

‎apps/server/src/orchestration-v2/ThreadLaunchService.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,11 @@ const make = Effect.gen(function* () {
369369
if (generatedTemporaryBranch) {
370370
const uuid = yield* randomUuidV4;
371371
branch = buildTemporaryWorktreeBranchName(() => uuid.replaceAll("-", ""));
372-
const settings = resolveProjectSettings(
373-
yield* serverSettings.getSettings,
374-
input.projectId,
375-
).settings;
376-
if (settings.branchNamingMode === "static") {
372+
const settings = yield* serverSettings.getSettings.pipe(
373+
Effect.map((settings) => resolveProjectSettings(settings, input.projectId).settings),
374+
Effect.orElseSucceed(() => null),
375+
);
376+
if (settings?.branchNamingMode === "static") {
377377
branch = formatGeneratedBranchName(branch.slice(-8), {
378378
mode: "static",
379379
prefix: settings.branchNamePrefix,

0 commit comments

Comments
 (0)