fix(server): refuse worktree removal while another thread references it #9185
ClosedNurozen(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/9185/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/ws.ts line 2262OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2255,4 +2259,4 @@22552259 [WS_METHODS.vcsRemoveWorktree]: (input) =>22562260 observeRpcEffect(22572261 WS_METHODS.vcsRemoveWorktree,2258- gitWorkflow.removeWorktree(input).pipe(Effect.tap(() => refreshGitStatus(input.cwd))),2262+ Effect.all([
- @@ -0,0 +18,21 @@18+ operation: "ws.vcsRemoveWorktree",19+ command: "git",20+ cwd: input.cwd,21+ detail: `refused to remove worktree ${input.path}: ${input.referencingThreadIds.length} thread(s) still reference it`,22+ });23+24+/**25+ * Wraps a failure of the thread-reference lookup so the handler stays within26+ * the vcsRemoveWorktree wire error union.27+ */28+export const worktreeOwnershipQueryError = (29+ input: { readonly cwd: string; readonly path: string },30+ cause: unknown,31+): GitCommandError =>32+ new GitCommandError({33+ operation: "ws.vcsRemoveWorktree",34+ command: "git",35+ cwd: input.cwd,36+ detail: `failed to check which threads reference worktree ${input.path}`,37+ cause,38+ });@@ -0,0 +17,21 @@17+ ).toBeNull();18+ });19+20+ it("refuses removal while any thread, archived included, references the path", () => {21+ const error = worktreeRemovalBlockedError({22+ cwd: "/repo",23+ path: "/wt",24+ referencingThreadIds: [ThreadId.make("thread-archived"), ThreadId.make("thread-live")],25+ });26+ expect(error?._tag).toBe("GitCommandError");27+ expect(error?.detail).toContain("2 thread(s) still reference it");28+ });29+});30+31+describe("worktreeOwnershipQueryError", () => {32+ it("wraps lookup failures as a wire-compatible git command error", () => {33+ const cause = new Error("db unavailable");34+ const error = worktreeOwnershipQueryError({ cwd: "/repo", path: "/wt" }, cause);35+ expect(error._tag).toBe("GitCommandError");36+ expect(error.cause).toBe(cause);37+ });
Mnigos(GitHub profile, opens in a new tab) approved these changes
juliusmarminge added labelsmacroscope-review
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed