Require client action IDs for git stacked action progress
- Add `actionId` to `GitRunStackedActionInput` and related API calls - Pass client-generated `actionId` from web UI through WS server to progress events - Update server/web/contracts tests to assert deterministic progress correlation
This commit is contained in:
1 parent
dd75189844
commit
c474896f7e
8 files changed
+41
-14
No files matched your search
@@ -450,13 +450,20 @@ function runStackedAction(
|
||||
input: {
|
||||
cwd: string;
|
||||
action: "commit" | "commit_push" | "commit_push_pr";
|
||||
actionId?: string;
|
||||
commitMessage?: string;
|
||||
featureBranch?: boolean;
|
||||
filePaths?: readonly string[];
|
||||
},
|
||||
options?: Parameters<GitManagerShape["runStackedAction"]>[1],
|
||||
) {
|
||||
return manager.runStackedAction(input, options);
|
||||
return manager.runStackedAction(
|
||||
{
|
||||
...input,
|
||||
actionId: input.actionId ?? "test-action-id",
|
||||
},
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
function resolvePullRequest(manager: GitManagerShape, input: { cwd: string; reference: string }) {
|
||||
|
||||
@@ -1811,6 +1811,7 @@ describe("WebSocket Server", () => {
|
||||
connections.push(ws);
|
||||
|
||||
const response = await sendRequest(ws, WS_METHODS.gitRunStackedAction, {
|
||||
actionId: "client-action-1",
|
||||
cwd: "/test",
|
||||
action: "commit_push",
|
||||
});
|
||||
@@ -1818,11 +1819,12 @@ describe("WebSocket Server", () => {
|
||||
expect(response.error?.message).toContain("detached HEAD");
|
||||
expect(runStackedAction).toHaveBeenCalledWith(
|
||||
{
|
||||
actionId: "client-action-1",
|
||||
cwd: "/test",
|
||||
action: "commit_push",
|
||||
},
|
||||
expect.objectContaining({
|
||||
actionId: expect.any(String),
|
||||
actionId: "client-action-1",
|
||||
progressReporter: expect.any(Object),
|
||||
}),
|
||||
);
|
||||
@@ -1872,13 +1874,14 @@ describe("WebSocket Server", () => {
|
||||
connections.push(initiatingWs, otherWs);
|
||||
|
||||
const responsePromise = sendRequest(initiatingWs, WS_METHODS.gitRunStackedAction, {
|
||||
actionId: "client-action-2",
|
||||
cwd: "/test",
|
||||
action: "commit",
|
||||
});
|
||||
const progressPush = await waitForPush(initiatingWs, WS_CHANNELS.gitActionProgress);
|
||||
|
||||
expect(progressPush.data).toEqual({
|
||||
actionId: expect.any(String),
|
||||
actionId: "client-action-2",
|
||||
cwd: "/test",
|
||||
action: "commit",
|
||||
kind: "phase_started",
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
import http from "node:http";
|
||||
import type { Duplex } from "node:stream";
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
import Mime from "@effect/platform-node/Mime";
|
||||
import {
|
||||
@@ -795,7 +794,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
||||
case WS_METHODS.gitRunStackedAction: {
|
||||
const body = stripRequestTag(request.body);
|
||||
return yield* gitManager.runStackedAction(body, {
|
||||
actionId: randomUUID(),
|
||||
actionId: body.actionId,
|
||||
progressReporter: {
|
||||
publish: (event) =>
|
||||
pushBus.publishClient(ws, WS_CHANNELS.gitActionProgress, event).pipe(Effect.asVoid),
|
||||
|
||||
@@ -48,6 +48,7 @@ import {
|
||||
gitStatusQueryOptions,
|
||||
invalidateGitQueries,
|
||||
} from "~/lib/gitReactQuery";
|
||||
import { randomUUID } from "~/lib/utils";
|
||||
import { resolvePathLinkTarget } from "~/terminal-links";
|
||||
import { readNativeApi } from "~/nativeApi";
|
||||
|
||||
@@ -70,7 +71,7 @@ type GitActionToastId = ReturnType<typeof toastManager.add>;
|
||||
|
||||
interface ActiveGitActionProgress {
|
||||
toastId: GitActionToastId;
|
||||
actionId: string | null;
|
||||
actionId: string;
|
||||
title: string;
|
||||
phaseStartedAtMs: number | null;
|
||||
hookStartedAtMs: number | null;
|
||||
@@ -313,15 +314,11 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
|
||||
if (gitCwd && event.cwd !== gitCwd) {
|
||||
return;
|
||||
}
|
||||
if (progress.actionId !== null && progress.actionId !== event.actionId) {
|
||||
if (progress.actionId !== event.actionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
if (progress.actionId === null) {
|
||||
progress.actionId = event.actionId;
|
||||
}
|
||||
|
||||
switch (event.kind) {
|
||||
case "action_started":
|
||||
progress.phaseStartedAtMs = now;
|
||||
@@ -457,6 +454,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
|
||||
forcePushOnly: forcePushOnlyProgress,
|
||||
featureBranch,
|
||||
});
|
||||
const actionId = randomUUID();
|
||||
const resolvedProgressToastId =
|
||||
progressToastId ??
|
||||
toastManager.add({
|
||||
@@ -469,7 +467,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
|
||||
|
||||
activeGitActionProgressRef.current = {
|
||||
toastId: resolvedProgressToastId,
|
||||
actionId: null,
|
||||
actionId,
|
||||
title: progressStages[0] ?? "Running git action...",
|
||||
phaseStartedAtMs: null,
|
||||
hookStartedAtMs: null,
|
||||
@@ -489,6 +487,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
|
||||
}
|
||||
|
||||
const promise = runImmediateGitActionMutation.mutateAsync({
|
||||
actionId,
|
||||
action,
|
||||
...(commitMessage ? { commitMessage } : {}),
|
||||
...(featureBranch ? { featureBranch } : {}),
|
||||
|
||||
@@ -117,11 +117,13 @@ export function gitRunStackedActionMutationOptions(input: {
|
||||
return mutationOptions({
|
||||
mutationKey: gitMutationKeys.runStackedAction(input.cwd),
|
||||
mutationFn: async ({
|
||||
actionId,
|
||||
action,
|
||||
commitMessage,
|
||||
featureBranch,
|
||||
filePaths,
|
||||
}: {
|
||||
actionId: string;
|
||||
action: GitStackedAction;
|
||||
commitMessage?: string;
|
||||
featureBranch?: boolean;
|
||||
@@ -130,6 +132,7 @@ export function gitRunStackedActionMutationOptions(input: {
|
||||
const api = ensureNativeApi();
|
||||
if (!input.cwd) throw new Error("Git action is unavailable.");
|
||||
return api.git.runStackedAction({
|
||||
actionId,
|
||||
cwd: input.cwd,
|
||||
action,
|
||||
...(commitMessage ? { commitMessage } : {}),
|
||||
|
||||
@@ -350,11 +350,11 @@ describe("wsNativeApi", () => {
|
||||
const { createWsNativeApi } = await import("./wsNativeApi");
|
||||
|
||||
const api = createWsNativeApi();
|
||||
await api.git.runStackedAction({ cwd: "/repo", action: "commit" });
|
||||
await api.git.runStackedAction({ actionId: "action-1", cwd: "/repo", action: "commit" });
|
||||
|
||||
expect(requestMock).toHaveBeenCalledWith(
|
||||
WS_METHODS.gitRunStackedAction,
|
||||
{ cwd: "/repo", action: "commit" },
|
||||
{ actionId: "action-1", cwd: "/repo", action: "commit" },
|
||||
{ timeoutMs: null },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Schema } from "effect";
|
||||
import {
|
||||
GitCreateWorktreeInput,
|
||||
GitPreparePullRequestThreadInput,
|
||||
GitRunStackedActionInput,
|
||||
GitResolvePullRequestResult,
|
||||
} from "./git";
|
||||
|
||||
@@ -11,6 +12,7 @@ const decodeCreateWorktreeInput = Schema.decodeUnknownSync(GitCreateWorktreeInpu
|
||||
const decodePreparePullRequestThreadInput = Schema.decodeUnknownSync(
|
||||
GitPreparePullRequestThreadInput,
|
||||
);
|
||||
const decodeRunStackedActionInput = Schema.decodeUnknownSync(GitRunStackedActionInput);
|
||||
const decodeResolvePullRequestResult = Schema.decodeUnknownSync(GitResolvePullRequestResult);
|
||||
|
||||
describe("GitCreateWorktreeInput", () => {
|
||||
@@ -56,3 +58,16 @@ describe("GitResolvePullRequestResult", () => {
|
||||
expect(parsed.pullRequest.headBranch).toBe("feature/pr-threads");
|
||||
});
|
||||
});
|
||||
|
||||
describe("GitRunStackedActionInput", () => {
|
||||
it("requires a client-provided actionId for progress correlation", () => {
|
||||
const parsed = decodeRunStackedActionInput({
|
||||
actionId: "action-1",
|
||||
cwd: "/repo",
|
||||
action: "commit",
|
||||
});
|
||||
|
||||
expect(parsed.actionId).toBe("action-1");
|
||||
expect(parsed.action).toBe("commit");
|
||||
});
|
||||
});
|
||||
@@ -72,6 +72,7 @@ export const GitPullInput = Schema.Struct({
|
||||
export type GitPullInput = typeof GitPullInput.Type;
|
||||
|
||||
export const GitRunStackedActionInput = Schema.Struct({
|
||||
actionId: TrimmedNonEmptyStringSchema,
|
||||
cwd: TrimmedNonEmptyStringSchema,
|
||||
action: GitStackedAction,
|
||||
commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))),
|
||||
|
||||
Reference in new issue
Block a user