Skip to content

Commit 85cd0f8

Browse files
donjorrsi-pr-agent
authored andcommitted
fix(upstream-fixes): mobile checkout moves keep upstream's task-permission gate
Upstream `2eda8ac6a31` gates every thread metadata write on the operate scope. The fork's worktree checkout move now runs behind that gate, and upstream's new Git actions test emulates the server move with an appended, marked hook. Fork-Domain: upstream-fixes Fork-Tier: bugfix Fork-Upstreamable: no
1 parent 259246d commit 85cd0f8

2 files changed

Lines changed: 56 additions & 10 deletions

File tree

‎apps/mobile/src/state/use-selected-thread-git-actions.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,28 @@ describe("thread Git mutation permissions", () => {
231231
},
232232
);
233233
});
234+
235+
beforeEach(async () => {
236+
// The fork attaches a new worktree through the server's checkout move, which records the
237+
// worktree's path and branch on the thread as the metadata update above does.
238+
type Command = (request: {
239+
environmentId: string;
240+
input: Record<string, unknown>;
241+
}) => Promise<unknown>;
242+
const threads = (await import("./threads")) as unknown as {
243+
threadEnvironment: Record<string, Command>;
244+
};
245+
const vcs = (await import("./vcs")) as unknown as { vcsEnvironment: Record<string, Command> };
246+
if (threads.threadEnvironment.moveCheckout) return;
247+
let worktreeBranch: unknown;
248+
const createWorktree = vcs.vcsEnvironment.createWorktree!;
249+
vcs.vcsEnvironment.createWorktree = (request) => {
250+
worktreeBranch = request.input.newRefName;
251+
return createWorktree(request);
252+
};
253+
threads.threadEnvironment.moveCheckout = ({ environmentId, input }) =>
254+
threads.threadEnvironment.updateMetadata!({
255+
environmentId,
256+
input: { branch: worktreeBranch, worktreePath: input.requestedPath },
257+
});
258+
}); // fork-hook: zmux-estate/checkout-move-git-actions-test

‎apps/mobile/src/state/use-selected-thread-git-actions.ts‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ export function useSelectedThreadGitActions() {
113113
),
114114
);
115115
}
116+
const checkoutMove = checkoutMoveRequestFork(thread, nextState, selectedThreadProject); // fork-hook: zmux-estate/checkout-move-request
117+
if (checkoutMove) {
118+
// A new worktree moves through the server, so the thread's sessions follow it.
119+
return moveThreadCheckout({ environmentId: thread.environmentId, input: checkoutMove });
120+
} // fork-hook: zmux-estate/checkout-move-update-result
116121
return updateThreadMetadata({
117122
environmentId: thread.environmentId,
118123
input: {
@@ -122,7 +127,7 @@ export function useSelectedThreadGitActions() {
122127
},
123128
});
124129
},
125-
[updateThreadMetadata],
130+
[moveThreadCheckout, selectedThreadProject, updateThreadMetadata], // fork-hook: zmux-estate/checkout-move-update-result
126131
);
127132

128133
const refreshSelectedThreadGitStatus = useCallback(
@@ -237,9 +242,13 @@ export function useSelectedThreadGitActions() {
237242
};
238243
}): Promise<AtomCommandResult<void, unknown>> => {
239244
// Git already changed; refresh even if metadata updates fail so the sheet shows the current branch.
240-
const updateResult = input.nextThreadState
245+
const checkoutMoveRequested =
246+
input.nextThreadState !== undefined &&
247+
checkoutMoveRequestFork(input.thread, input.nextThreadState, selectedThreadProject) !==
248+
null; // fork-hook: zmux-estate/checkout-move-request
249+
const updateResult: AtomCommandResult<unknown, unknown> = input.nextThreadState
241250
? await updateThreadGitContext(input.thread, input.nextThreadState)
242-
: AsyncResult.success(undefined);
251+
: AsyncResult.success(undefined); // fork-hook: zmux-estate/checkout-move-update-result
243252
branchState.refresh();
244253
if (!checkoutMoveRequested) {
245254
await refreshSelectedThreadGitStatus({ quiet: true, cwd: input.cwd });
@@ -248,13 +257,7 @@ export function useSelectedThreadGitActions() {
248257
? AsyncResult.failure(updateResult.cause)
249258
: AsyncResult.success(undefined);
250259
},
251-
[
252-
branchState,
253-
moveThreadCheckout,
254-
refreshSelectedThreadGitStatus,
255-
selectedThreadProject,
256-
updateThreadGitContext,
257-
],
260+
[branchState, refreshSelectedThreadGitStatus, selectedThreadProject, updateThreadGitContext], // fork-hook: zmux-estate/checkout-move-request
258261
);
259262

260263
const onCheckoutSelectedThreadBranch = useCallback(
@@ -451,3 +454,21 @@ export function useSelectedThreadGitActions() {
451454
onRunSelectedThreadGitAction,
452455
};
453456
}
457+
458+
function checkoutMoveRequestFork(
459+
thread: EnvironmentThreadShell,
460+
nextState: { readonly worktreePath?: string | null },
461+
project: EnvironmentProject | null,
462+
) {
463+
// The server checkout move a thread's next worktree needs, or null when it stays put.
464+
if (!project || nextState.worktreePath === undefined) return null;
465+
if (nextState.worktreePath === thread.worktreePath) return null;
466+
return {
467+
threadId: thread.id,
468+
requestedPath: nextState.worktreePath ?? project.workspaceRoot,
469+
expectedCheckoutRoot:
470+
(thread.checkoutMove ? checkoutMoveExpectedRoot(thread.checkoutMove) : null) ??
471+
thread.worktreePath ??
472+
project.workspaceRoot,
473+
};
474+
} // fork-hook: zmux-estate/checkout-move-request

0 commit comments

Comments
 (0)