[codex] feat(web): show git progress in the commit button (#4963)

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex authored and GitHub committed 2026-07-30 14:38:07 +02:00
1 parent a73a9ffc6d
commit 14dd128a68
6 files changed
+338 -208

No files matched your search

@@ -3,9 +3,12 @@ import { assert, describe, it } from "vite-plus/test";
import {
buildGitActionProgressStages,
buildMenuItems,
formatGitActionElapsed,
requiresDefaultBranchConfirmation,
resolveAutoFeatureBranchName,
resolveDefaultBranchActionDialogCopy,
resolveGitActionProgressPresentation,
resolveGitActionResultToastTiming,
resolveLiveThreadBranchUpdate,
resolveQuickAction,
resolveThreadBranchUpdate,
@@ -32,6 +35,96 @@ function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
};
}
describe("git action progress presentation", () => {
it("keeps the phase on the first row and hook output on the second", () => {
assert.deepEqual(
resolveGitActionProgressPresentation({
isRunning: true,
operation: "run_change_request",
currentLabel: "Running pre-commit...",
lastOutputLine: "Checking formatting and lint rules",
phaseStartedAtMs: 1_000,
hookStartedAtMs: 2_000,
}),
{
status: "Running pre-commit...",
output: "Checking formatting and lint rules",
startedAtMs: 2_000,
},
);
});
it("omits empty output and supplies a brief startup label", () => {
assert.deepEqual(
resolveGitActionProgressPresentation({
isRunning: true,
operation: "run_change_request",
currentLabel: "Running source control action",
lastOutputLine: " ",
phaseStartedAtMs: 1_000,
hookStartedAtMs: null,
}),
{
status: "Starting source control action...",
output: null,
startedAtMs: 1_000,
},
);
});
it("presents pull progress inline without a second row", () => {
assert.deepEqual(
resolveGitActionProgressPresentation({
isRunning: true,
operation: "pull",
currentLabel: "Pulling latest changes...",
lastOutputLine: null,
phaseStartedAtMs: 1_000,
hookStartedAtMs: null,
}),
{
status: "Pulling latest changes...",
output: null,
startedAtMs: 1_000,
},
);
});
it("does not present unrelated or completed actions", () => {
const input = {
isRunning: true,
operation: "publish_repository",
currentLabel: "Publishing repository",
lastOutputLine: null,
phaseStartedAtMs: 1_000,
hookStartedAtMs: null,
};
assert.isNull(resolveGitActionProgressPresentation(input));
assert.isNull(resolveGitActionProgressPresentation({ ...input, isRunning: false }));
});
it("formats compact elapsed time without allowing negative values", () => {
assert.isNull(formatGitActionElapsed(null, 10_000));
assert.equal(formatGitActionElapsed(10_000, 9_000), "0s");
assert.equal(formatGitActionElapsed(10_000, 14_900), "4s");
assert.equal(formatGitActionElapsed(10_000, 75_000), "1m 5s");
});
});
describe("git action result toast timing", () => {
it("keeps errors sticky and dismisses successes after visible time", () => {
assert.deepEqual(resolveGitActionResultToastTiming("error"), {
timeout: 0,
dismissAfterVisibleMs: null,
});
assert.deepEqual(resolveGitActionResultToastTiming("success"), {
timeout: 0,
dismissAfterVisibleMs: 10_000,
});
});
});
describe("when: ref is clean and has an open PR", () => {
it("resolveQuickAction opens the existing PR", () => {
const quick = resolveQuickAction(
@@ -37,12 +37,34 @@ export interface DefaultBranchActionDialogCopy {
continueLabel: string;
}
export interface GitActionProgressPresentation {
readonly status: string;
readonly output: string | null;
readonly startedAtMs: number | null;
}
export interface GitActionResultToastTiming {
readonly timeout: 0;
readonly dismissAfterVisibleMs: number | null;
}
export type DefaultBranchConfirmableAction =
| "push"
| "create_pr"
| "commit_push"
| "commit_push_pr";
const GIT_ACTION_SUCCESS_TOAST_VISIBLE_MS = 10_000;
export function resolveGitActionResultToastTiming(
type: "error" | "success",
): GitActionResultToastTiming {
return {
timeout: 0,
dismissAfterVisibleMs: type === "success" ? GIT_ACTION_SUCCESS_TOAST_VISIBLE_MS : null,
};
}
function resolveChangeRequestTerminology(
gitStatus: VcsStatusResult | null,
): ChangeRequestTerminology {
@@ -51,6 +73,53 @@ function resolveChangeRequestTerminology(
: DEFAULT_CHANGE_REQUEST_TERMINOLOGY;
}
export function resolveGitActionProgressPresentation(input: {
readonly isRunning: boolean;
readonly operation: string | null;
readonly currentLabel: string | null;
readonly lastOutputLine: string | null;
readonly phaseStartedAtMs: number | null;
readonly hookStartedAtMs: number | null;
}): GitActionProgressPresentation | null {
if (
!input.isRunning ||
(input.operation !== "run_change_request" && input.operation !== "pull")
) {
return null;
}
const currentLabel = input.currentLabel?.trim();
const output = input.lastOutputLine?.trim();
const isPull = input.operation === "pull";
return {
status:
currentLabel && currentLabel !== "Running source control action"
? currentLabel
: isPull
? "Pulling latest changes..."
: "Starting source control action...",
output: !isPull && output ? output : null,
startedAtMs: isPull
? input.phaseStartedAtMs
: (input.hookStartedAtMs ?? input.phaseStartedAtMs),
};
}
export function formatGitActionElapsed(startedAtMs: number | null, nowMs: number): string | null {
if (startedAtMs === null) {
return null;
}
const elapsedSeconds = Math.max(0, Math.floor((nowMs - startedAtMs) / 1_000));
if (elapsedSeconds < 60) {
return `${elapsedSeconds}s`;
}
const minutes = Math.floor(elapsedSeconds / 60);
const seconds = elapsedSeconds % 60;
return `${minutes}m ${seconds}s`;
}
export function buildGitActionProgressStages(input: {
action: GitStackedAction;
hasCustomCommitMessage: boolean;
+117 -189
View File
@@ -5,7 +5,6 @@ import {
squashAtomCommandFailure,
} from "@t3tools/client-runtime/state/runtime";
import type {
GitActionProgressEvent,
GitRunStackedActionResult,
GitStackedAction,
SourceControlCloneProtocol,
@@ -37,14 +36,17 @@ import { RadioGroup } from "~/components/ui/radio-group";
import { Spinner } from "~/components/ui/spinner";
import { cn } from "~/lib/utils";
import {
buildGitActionProgressStages,
buildMenuItems,
formatGitActionElapsed,
type GitActionProgressPresentation,
type GitActionIconName,
type GitActionMenuItem,
type GitQuickAction,
type DefaultBranchConfirmableAction,
requiresDefaultBranchConfirmation,
resolveDefaultBranchActionDialogCopy,
resolveGitActionProgressPresentation,
resolveGitActionResultToastTiming,
resolveLiveThreadBranchUpdate,
resolveThreadBranchMetadataPatch,
resolveQuickAction,
@@ -68,7 +70,7 @@ import { Menu, MenuItem, MenuPopup, MenuTrigger } from "~/components/ui/menu";
import { Popover, PopoverPopup, PopoverTrigger } from "~/components/ui/popover";
import { ScrollArea } from "~/components/ui/scroll-area";
import { Textarea } from "~/components/ui/textarea";
import { stackedThreadToast, toastManager, type ThreadToastData } from "~/components/ui/toast";
import { stackedThreadToast, toastManager } from "~/components/ui/toast";
import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
import { useOpenInPreferredEditor } from "~/editorPreferences";
import {
@@ -84,7 +86,7 @@ import { serverEnvironment } from "~/state/server";
import { sourceControlEnvironment } from "~/state/sourceControl";
import { threadEnvironment } from "~/state/threads";
import { useAtomCommand } from "~/state/use-atom-command";
import { vcsEnvironment } from "~/state/vcs";
import { vcsActionManager, vcsEnvironment } from "~/state/vcs";
import { randomUUID } from "~/lib/utils";
import { resolvePathLinkTarget } from "~/terminal-links";
import { type DraftId, useComposerDraftStore } from "~/composerDraftStore";
@@ -126,18 +128,6 @@ type PublishProviderKind = Extract<
type GitActionToastId = ReturnType<typeof toastManager.add>;
interface ActiveGitActionProgress {
toastId: GitActionToastId;
toastData: ThreadToastData | undefined;
actionId: string;
title: string;
phaseStartedAtMs: number | null;
hookStartedAtMs: number | null;
hookName: string | null;
lastOutputLine: string | null;
currentPhaseLabel: string | null;
}
interface RunGitActionWithToastInput {
action: GitStackedAction;
commitMessage?: string;
@@ -145,7 +135,6 @@ interface RunGitActionWithToastInput {
skipDefaultBranchPrompt?: boolean;
statusOverride?: VcsStatusResult | null;
featureBranch?: boolean;
progressToastId?: GitActionToastId;
filePaths?: string[];
}
@@ -250,26 +239,6 @@ function getPublishProviderReadiness(input: {
return { ready: true, hint: null };
}
function formatElapsedDescription(startedAtMs: number | null): string | undefined {
if (startedAtMs === null) {
return undefined;
}
const elapsedSeconds = Math.max(0, Math.floor((Date.now() - startedAtMs) / 1000));
if (elapsedSeconds < 60) {
return `Running for ${elapsedSeconds}s`;
}
const minutes = Math.floor(elapsedSeconds / 60);
const seconds = elapsedSeconds % 60;
return `Running for ${minutes}m ${seconds}s`;
}
function resolveProgressDescription(progress: ActiveGitActionProgress): string | undefined {
if (progress.lastOutputLine) {
return progress.lastOutputLine;
}
return formatElapsedDescription(progress.hookStartedAtMs ?? progress.phaseStartedAtMs);
}
function getMenuActionDisabledReason({
item,
gitStatus,
@@ -379,6 +348,59 @@ function GitQuickActionIcon({
return <InfoIcon className={iconClassName} />;
}
function GitActionProgressButtonContent({ progress }: { progress: GitActionProgressPresentation }) {
const [nowMs, setNowMs] = useState(() => Date.now());
useEffect(() => {
if (progress.startedAtMs === null) {
return;
}
const intervalId = window.setInterval(() => {
setNowMs(Date.now());
}, 1_000);
return () => window.clearInterval(intervalId);
}, [progress.startedAtMs]);
const elapsed = formatGitActionElapsed(progress.startedAtMs, nowMs);
const hasOutput = progress.output !== null;
return (
<div
aria-atomic="false"
aria-live="polite"
className="grid min-w-0 flex-1 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-2.5 gap-y-0.5"
role="status"
>
<Spinner
aria-hidden="true"
className="row-start-1 -mx-0.5 size-4 shrink-0 text-muted-foreground"
/>
<p className="row-start-1 min-w-0 truncate text-left">{progress.status}</p>
{elapsed ? (
<p className="row-start-1 text-[11px] font-normal tabular-nums text-muted-foreground">
{elapsed}
</p>
) : null}
<div
className={cn(
"col-span-2 col-start-2 grid min-w-0 transition-[grid-template-rows,opacity] duration-200 ease-out motion-reduce:transition-none",
hasOutput ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0",
)}
>
<div className="min-h-0 overflow-hidden">
<p
className="truncate text-left text-[11px] font-normal text-muted-foreground"
title={progress.output ?? undefined}
>
{progress.output}
</p>
</div>
</div>
</div>
);
}
interface PublishRepositoryDialogProps {
readonly open: boolean;
readonly onOpenChange: (open: boolean) => void;
@@ -1022,27 +1044,13 @@ export default function GitActionsControl({
const [isPublishDialogOpen, setIsPublishDialogOpen] = useState(false);
const [pendingDefaultBranchAction, setPendingDefaultBranchAction] =
useState<PendingDefaultBranchAction | null>(null);
const activeGitActionProgressRef = useRef<ActiveGitActionProgress | null>(null);
const sourceControlScope = useMemo(
() => ({ environmentId: activeEnvironmentId, cwd: gitCwd }),
[activeEnvironmentId, gitCwd],
);
const vcsActionState = useAtomValue(vcsActionManager.stateAtom(sourceControlScope));
let runGitActionWithToast: (input: RunGitActionWithToastInput) => Promise<void>;
const updateActiveProgressToast = useCallback(() => {
const progress = activeGitActionProgressRef.current;
if (!progress) {
return;
}
toastManager.update(progress.toastId, {
type: "loading",
title: progress.title,
description: resolveProgressDescription(progress),
timeout: 0,
data: progress.toastData,
});
}, []);
const persistThreadBranchSync = useCallback(
(branch: string | null) => {
if (!activeThreadRef) {
@@ -1175,6 +1183,7 @@ export default function GitActionsControl({
const quickActionDisabledReason = quickAction.disabled
? (quickAction.hint ?? "This action is currently unavailable.")
: null;
const gitActionProgress = resolveGitActionProgressPresentation(vcsActionState);
const pendingDefaultBranchActionCopy = pendingDefaultBranchAction
? resolveDefaultBranchActionDialogCopy({
action: pendingDefaultBranchAction.action,
@@ -1184,19 +1193,6 @@ export default function GitActionsControl({
})
: null;
useEffect(() => {
const interval = window.setInterval(() => {
if (!activeGitActionProgressRef.current) {
return;
}
updateActiveProgressToast();
}, 1000);
return () => {
window.clearInterval(interval);
};
}, [updateActiveProgressToast]);
useEffect(() => {
if (gitCwd === null) {
return;
@@ -1270,7 +1266,6 @@ export default function GitActionsControl({
skipDefaultBranchPrompt = false,
statusOverride,
featureBranch = false,
progressToastId,
filePaths,
}: RunGitActionWithToastInput) => {
const actionStatus = statusOverride ?? gitStatusForActions;
@@ -1306,105 +1301,8 @@ export default function GitActionsControl({
}
onConfirmed?.();
const progressStages = buildGitActionProgressStages({
action,
hasCustomCommitMessage: !!commitMessage?.trim(),
hasWorkingTreeChanges: !!actionStatus?.hasWorkingTreeChanges,
featureBranch,
terminology: changeRequestTerminology,
shouldPushBeforePr:
action === "create_pr" &&
(!actionStatus?.hasUpstream || (actionStatus?.aheadCount ?? 0) > 0),
});
const scopedToastData = threadToastData ? { ...threadToastData } : undefined;
const actionId = randomUUID();
const resolvedProgressToastId =
progressToastId ??
toastManager.add({
type: "loading",
title: progressStages[0] ?? "Running git action...",
description: "Waiting for Git...",
timeout: 0,
data: scopedToastData,
});
activeGitActionProgressRef.current = {
toastId: resolvedProgressToastId,
toastData: scopedToastData,
actionId,
title: progressStages[0] ?? "Running git action...",
phaseStartedAtMs: null,
hookStartedAtMs: null,
hookName: null,
lastOutputLine: null,
currentPhaseLabel: progressStages[0] ?? "Running git action...",
};
if (progressToastId) {
toastManager.update(progressToastId, {
type: "loading",
title: progressStages[0] ?? "Running git action...",
description: "Waiting for Git...",
timeout: 0,
data: scopedToastData,
});
}
const applyProgressEvent = (event: GitActionProgressEvent) => {
const progress = activeGitActionProgressRef.current;
if (!progress) {
return;
}
if (gitCwd && event.cwd !== gitCwd) {
return;
}
if (progress.actionId !== event.actionId) {
return;
}
const now = Date.now();
switch (event.kind) {
case "action_started":
progress.phaseStartedAtMs = now;
progress.hookStartedAtMs = null;
progress.hookName = null;
progress.lastOutputLine = null;
break;
case "phase_started":
progress.title = event.label;
progress.currentPhaseLabel = event.label;
progress.phaseStartedAtMs = now;
progress.hookStartedAtMs = null;
progress.hookName = null;
progress.lastOutputLine = null;
break;
case "hook_started":
progress.title = `Running ${event.hookName}...`;
progress.hookName = event.hookName;
progress.hookStartedAtMs = now;
progress.lastOutputLine = null;
break;
case "hook_output":
progress.lastOutputLine = event.text;
break;
case "hook_finished":
progress.title = progress.currentPhaseLabel ?? "Committing...";
progress.hookName = null;
progress.hookStartedAtMs = null;
progress.lastOutputLine = null;
break;
case "action_finished":
// Let the resolved mutation update the toast so we keep the
// elapsed description visible until the final success state renders.
return;
case "action_failed":
// Let the settled mutation publish the error toast to avoid a
// transient intermediate state before the final failure message.
return;
}
updateActiveProgressToast();
};
const result = await runImmediateGitAction.run({
actionId,
@@ -1412,23 +1310,21 @@ export default function GitActionsControl({
...(commitMessage ? { commitMessage } : {}),
...(featureBranch ? { featureBranch } : {}),
...(filePaths ? { filePaths } : {}),
onProgress: applyProgressEvent,
});
activeGitActionProgressRef.current = null;
if (result._tag === "Failure") {
if (isAtomCommandInterrupted(result)) {
toastManager.close(resolvedProgressToastId);
return;
}
const error = squashAtomCommandFailure(result);
toastManager.update(
resolvedProgressToastId,
const errorToastTiming = resolveGitActionResultToastTiming("error");
toastManager.add(
stackedThreadToast({
type: "error",
title: "Action failed",
description: error instanceof Error ? error.message : "An error occurred.",
timeout: errorToastTiming.timeout,
...(scopedToastData !== undefined ? { data: scopedToastData } : {}),
}),
);
@@ -1437,8 +1333,11 @@ export default function GitActionsControl({
const actionResult = result.value;
syncThreadBranchAfterGitAction(actionResult);
let resultToastId: GitActionToastId | null = null;
const closeResultToast = () => {
toastManager.close(resolvedProgressToastId);
if (resultToastId !== null) {
toastManager.close(resultToastId);
}
};
const toastCta = actionResult.toast.cta;
@@ -1468,29 +1367,31 @@ export default function GitActionsControl({
};
}
const successToastTiming = resolveGitActionResultToastTiming("success");
const successToastData = {
...scopedToastData,
dismissAfterVisibleMs: 10_000,
...(successToastTiming.dismissAfterVisibleMs !== null
? { dismissAfterVisibleMs: successToastTiming.dismissAfterVisibleMs }
: {}),
};
if (toastActionProps) {
toastManager.update(
resolvedProgressToastId,
resultToastId = toastManager.add(
stackedThreadToast({
type: "success",
title: actionResult.toast.title,
description: actionResult.toast.description,
timeout: 0,
timeout: successToastTiming.timeout,
actionProps: toastActionProps,
data: successToastData,
}),
);
} else {
toastManager.update(resolvedProgressToastId, {
resultToastId = toastManager.add({
type: "success",
title: actionResult.toast.title,
description: actionResult.toast.description,
timeout: 0,
timeout: successToastTiming.timeout,
data: successToastData,
});
}
@@ -1552,26 +1453,20 @@ export default function GitActionsControl({
return;
}
if (quickAction.kind === "run_pull") {
const toastId = toastManager.add({
type: "loading",
title: "Pulling...",
timeout: 0,
data: threadToastData,
});
void (async () => {
const result = await pullAction.run();
if (result._tag === "Failure") {
if (isAtomCommandInterrupted(result)) {
toastManager.close(toastId);
return;
}
const error = squashAtomCommandFailure(result);
toastManager.update(
toastId,
const errorToastTiming = resolveGitActionResultToastTiming("error");
toastManager.add(
stackedThreadToast({
type: "error",
title: "Pull failed",
description: error instanceof Error ? error.message : "An error occurred.",
timeout: errorToastTiming.timeout,
...(threadToastData !== undefined ? { data: threadToastData } : {}),
}),
);
@@ -1579,14 +1474,21 @@ export default function GitActionsControl({
}
const pullResult = result.value;
toastManager.update(toastId, {
const successToastTiming = resolveGitActionResultToastTiming("success");
toastManager.add({
type: "success",
title: pullResult.status === "pulled" ? "Pulled" : "Already up to date",
description:
pullResult.status === "pulled"
? `Updated ${pullResult.refName} from ${pullResult.upstreamRef ?? "upstream"}`
: `${pullResult.refName} is already synchronized.`,
data: threadToastData,
timeout: successToastTiming.timeout,
data: {
...threadToastData,
...(successToastTiming.dismissAfterVisibleMs !== null
? { dismissAfterVisibleMs: successToastTiming.dismissAfterVisibleMs }
: {}),
},
});
})();
return;
@@ -1708,9 +1610,32 @@ export default function GitActionsControl({
role="group"
aria-label="Git actions"
{...(isPanel ? { ref: panelAnchorRef } : {})}
className={cn("shrink-0", isPanel && THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS)}
className={cn(
"shrink-0",
isPanel && THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS,
isPanel && gitActionProgress && "bg-black/[0.035] dark:bg-white/[0.055]",
)}
>
{quickActionDisabledReason ? (
{gitActionProgress ? (
<Button
aria-label={
gitActionProgress.output
? `${gitActionProgress.status} ${gitActionProgress.output}`
: gitActionProgress.status
}
className={cn(
isPanel
? THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS
: "h-auto min-h-7 max-w-72 py-1 sm:h-auto sm:min-h-6",
isPanel && "h-auto min-h-9 py-1 disabled:opacity-100 sm:h-auto sm:min-h-9",
)}
disabled
size="xs"
variant={isPanel ? "ghost" : "outline"}
>
<GitActionProgressButtonContent progress={gitActionProgress} />
</Button>
) : quickActionDisabledReason ? (
<Popover>
<PopoverTrigger
openOnHover
@@ -1785,7 +1710,10 @@ export default function GitActionsControl({
aria-label="Git action options"
size={isPanel ? "sm" : "icon-xs"}
variant={isPanel ? "ghost" : "outline"}
className={isPanel ? THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS : undefined}
className={cn(
isPanel && THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS,
isPanel && gitActionProgress && "h-auto self-stretch sm:h-auto",
)}
/>
}
disabled={isGitActionRunning}
+1 -1
View File
@@ -191,7 +191,7 @@ export function useVcsPullAction(scope: SourceControlActionScope) {
}, [pull, scope]);
return useAction({
kind: "pull",
label: "Pulling latest changes",
label: "Pulling latest changes...",
scope,
action,
onSuccess: status.refresh,
@@ -203,7 +203,7 @@ describe("vcsActionState", () => {
});
});
it("clears running presentation state once the action finishes", () => {
it("keeps running presentation state until the finished action settles", () => {
const initial = beginVcsActionState({
operation: "run_change_request",
label: "Running source control action",
@@ -232,18 +232,18 @@ describe("vcsActionState", () => {
);
expect(finished).toMatchObject({
isRunning: false,
isRunning: true,
operation: "run_change_request",
actionId,
action,
currentLabel: null,
currentPhaseLabel: null,
currentLabel: "Pushing...",
currentPhaseLabel: "Pushing...",
lastOutputLine: null,
error: null,
});
});
it("retains a terminal action error for presentation", () => {
it("keeps running presentation state and retains a terminal action error until settle", () => {
const initial = beginVcsActionState({
operation: "run_change_request",
label: "Running source control action",
@@ -262,7 +262,7 @@ describe("vcsActionState", () => {
);
expect(failed).toMatchObject({
isRunning: false,
isRunning: true,
operation: "run_change_request",
actionId,
action,
@@ -583,11 +583,16 @@ describe("vcsActionState", () => {
const targetKey = { environmentId, cwd };
const successfulActionId = "invalidate-success";
const failedActionId = "invalidate-failure";
const interruptedActionId = "invalidate-interrupted";
const successfulTransportActionId = createVcsActionTransportId(
targetKey,
successfulActionId,
);
const failedTransportActionId = createVcsActionTransportId(targetKey, failedActionId);
const interruptedTransportActionId = createVcsActionTransportId(
targetKey,
interruptedActionId,
);
const client = {
[WS_METHODS.gitRunStackedAction]: (input: { readonly actionId: string }) =>
input.actionId === successfulTransportActionId
@@ -600,16 +605,18 @@ describe("vcsActionState", () => {
result,
}),
)
: Stream.make(
progress({
kind: "action_failed",
actionId: failedTransportActionId,
cwd,
action,
phase: "push",
message: "push failed after creating the branch",
}),
),
: input.actionId === interruptedTransportActionId
? Stream.fromEffect(Effect.interrupt)
: Stream.make(
progress({
kind: "action_failed",
actionId: failedTransportActionId,
cwd,
action,
phase: "push",
message: "push failed after creating the branch",
}),
),
} as unknown as WsRpcProtocolClient;
const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
target,
@@ -659,6 +666,7 @@ describe("vcsActionState", () => {
);
expect(AsyncResult.isSuccess(successfulResult)).toBe(true);
expect(registry.get(manager.stateAtom(targetKey))).toEqual(EMPTY_VCS_ACTION_STATE);
expect(registry.get(state).revision).toBe(1);
expect(removed).toEqual([`${environmentId}:*`]);
@@ -670,8 +678,29 @@ describe("vcsActionState", () => {
);
expect(AsyncResult.isFailure(failedResult)).toBe(true);
expect(registry.get(manager.stateAtom(targetKey))).toMatchObject({
isRunning: false,
operation: "run_change_request",
actionId: failedActionId,
error: "Source control action 'commit_push' failed during push.",
});
expect(registry.get(state).revision).toBe(2);
expect(removed).toEqual([`${environmentId}:*`, `${environmentId}:*`]);
const interruptedResult = yield* Effect.promise(() =>
manager.runStackedAction(targetKey).run(registry, {
actionId: interruptedActionId,
action,
}),
);
expect(AsyncResult.isFailure(interruptedResult)).toBe(true);
if (AsyncResult.isFailure(interruptedResult)) {
expect(Cause.hasInterruptsOnly(interruptedResult.cause)).toBe(true);
}
expect(registry.get(manager.stateAtom(targetKey))).toEqual(EMPTY_VCS_ACTION_STATE);
expect(registry.get(state).revision).toBe(3);
expect(removed).toEqual([`${environmentId}:*`, `${environmentId}:*`, `${environmentId}:*`]);
}),
),
);
+13 -2
View File
@@ -388,14 +388,17 @@ export function applyVcsActionProgressEvent(
};
case "action_finished":
return {
...EMPTY_VCS_ACTION_STATE,
...current,
isRunning: true,
actionId: event.actionId,
action: event.action,
operation: "run_change_request",
error: null,
};
case "action_failed":
return {
...EMPTY_VCS_ACTION_STATE,
...current,
isRunning: true,
actionId: event.actionId,
action: event.action,
operation: "run_change_request",
@@ -464,6 +467,12 @@ export function createVcsActionManager<R, E>(
...(input.featureBranch ? { featureBranch: true } : {}),
...(input.filePaths?.length ? { filePaths: [...input.filePaths] } : {}),
};
const clearOwnedState = Effect.sync(() => {
const current = registry.get(stateAtom);
if (current.actionId === input.actionId) {
registry.set(stateAtom, EMPTY_VCS_ACTION_STATE);
}
});
return consumeVcsActionProgress(
runStreamInEnvironment(
target.environmentId,
@@ -492,6 +501,7 @@ export function createVcsActionManager<R, E>(
},
).pipe(
Effect.ensuring(invalidateCachedVcsRefs(registry, target)),
Effect.tap(() => clearOwnedState),
Effect.tapError((error) =>
Effect.sync(() => {
const current = registry.get(stateAtom);
@@ -503,6 +513,7 @@ export function createVcsActionManager<R, E>(
}
}),
),
Effect.onInterrupt(() => clearOwnedState),
);
},
});