Skip to content

Commit 64f730d

Browse files
test(server): prove a cancelled setup stops its in-flight branch rename
The rename is held open until after the cancel, so the test fails on every run without the fix instead of only when the rename happens to land late. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent edd68cb commit 64f730d

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,55 @@ it.effect("cancels tracked setup before provider work is released", () =>
24512451
}),
24522452
);
24532453

2454+
it.effect("stops an in-flight branch rename when tracked setup is cancelled", () =>
2455+
Effect.gen(function* () {
2456+
const setupEntered = yield* Deferred.make<void>();
2457+
const branchNameStarted = yield* Deferred.make<void>();
2458+
const allowBranchName = yield* Deferred.make<void>();
2459+
const branchNameInterrupted = yield* Deferred.make<void>();
2460+
const renameAttempted = yield* Deferred.make<void>();
2461+
const harness = makeHarness({
2462+
renameBranch: (input) =>
2463+
Deferred.succeed(renameAttempted, undefined).pipe(Effect.as({ branch: input.newBranch })),
2464+
runSetup: () => Deferred.succeed(setupEntered, undefined).pipe(Effect.andThen(Effect.never)),
2465+
generateBranchName: () =>
2466+
Deferred.succeed(branchNameStarted, undefined).pipe(
2467+
Effect.andThen(Deferred.await(allowBranchName)),
2468+
Effect.as({ branch: "generated-branch" }),
2469+
Effect.onInterrupt(() => Deferred.succeed(branchNameInterrupted, undefined)),
2470+
),
2471+
});
2472+
yield* Effect.gen(function* () {
2473+
const launches = yield* ThreadLaunch.ThreadLaunchService;
2474+
const tracker = yield* WorktreeSetupTracker.WorktreeSetupTracker;
2475+
const threads = yield* ThreadManagement.ThreadManagementService;
2476+
const launched = yield* launches.launch(
2477+
launchInput({
2478+
command: "launch:cancel-renaming",
2479+
thread: "thread:cancel-renaming",
2480+
message: "Start",
2481+
workspace: { type: "worktree", baseRef: "main" },
2482+
}),
2483+
);
2484+
yield* Deferred.await(setupEntered);
2485+
yield* Deferred.await(branchNameStarted);
2486+
assert.isTrue(yield* tracker.cancel(launched.threadId));
2487+
// Let a rename that survived the cancel finish, then check it never ran.
2488+
yield* Deferred.succeed(allowBranchName, undefined);
2489+
yield* Effect.raceFirst(
2490+
Deferred.await(branchNameInterrupted),
2491+
Deferred.await(renameAttempted),
2492+
);
2493+
assert.isTrue(
2494+
yield* Deferred.isDone(branchNameInterrupted),
2495+
"the cancelled setup's branch rename kept running",
2496+
);
2497+
assert.equal(harness.renameBranch.mock.calls.length, 0);
2498+
assert.isNull((yield* threads.getThreadProjection(launched.threadId)).thread.worktreePath);
2499+
}).pipe(Effect.provide(harness.layer));
2500+
}),
2501+
);
2502+
24542503
it.effect.each([0, 1])("releases an async setup before its completion with exit %s", (exitCode) =>
24552504
Effect.gen(function* () {
24562505
const completion = yield* Deferred.make<{ exitCode: number | null; durationMs: number }>();

0 commit comments

Comments
 (0)