refactor(agent-manager): isolate failed deletion progress handling

This commit is contained in:
marius-kilocode
2026-08-27 12:00:33 +02:00
parent 672f48fa9e
commit cf0a209229
3 changed files with 43 additions and 6 deletions
@@ -1,6 +1,11 @@
import { describe, expect, it } from "bun:test"
import { createProjectStore } from "../../webview-ui/agent-manager/project/store"
import { clearMultiVersionBusy, markMultiVersionBusy } from "../../webview-ui/agent-manager/project/progress"
import {
clearFailedDelete,
clearMultiVersionBusy,
markMultiVersionBusy,
} from "../../webview-ui/agent-manager/project/progress"
import { createProjectRegistry } from "../../webview-ui/agent-manager/project/registry"
const state = (projectId: string) => ({
type: "agentManager.state" as const,
@@ -20,6 +25,31 @@ const state = (projectId: string) => ({
})
describe("multi-project progress state", () => {
it.each([undefined, "b"])("clears failed deletion only for the resolved project %s", (projectId) => {
const registry = createProjectRegistry({ persisted: {}, activeId: () => "a" })
for (const id of ["a", "b"]) {
registry.ensure(id).setBusy(
new Map([
["same", { reason: "deleting" as const }],
["other", { reason: "deleting" as const }],
]),
)
}
const store = registry.ensure(projectId ?? "a")
const peer = registry.ensure(projectId ? "a" : "b")
clearFailedDelete({ type: "error", message: "failed", code: "unrelated", projectId, worktreeId: "same" }, registry)
expect(store.busy().has("same")).toBe(true)
clearFailedDelete(
{ type: "error", message: "failed", code: "agentManager.worktreeDeleteFailed", projectId, worktreeId: "same" },
registry,
)
expect(store.busy().has("same")).toBe(false)
expect(peer.busy().has("same")).toBe(true)
expect(store.busy().has("other")).toBe(true)
})
it("updates only the owning project's grouped worktrees", () => {
const first = createProjectStore("a")
const second = createProjectStore("b")
@@ -104,7 +104,7 @@ import {
setReviewOpen,
} from "./project/review-state"
import { applyRunStatus } from "./project/run-status"
import { clearMultiVersionBusy, markMultiVersionBusy } from "./project/progress"
import { clearFailedDelete, clearMultiVersionBusy, markMultiVersionBusy } from "./project/progress"
import {
createSessionRestore,
createTabMemory,
@@ -1386,10 +1386,7 @@ const AgentManagerContent: Component = () => {
})
const unsub = vscode.onMessage((msg) => {
if (msg.type === "error" && msg.code === "agentManager.worktreeDeleteFailed" && msg.worktreeId) {
const store = msg.projectId ? registry.ensure(msg.projectId) : registry.active()
store.setBusy((prev) => new Map([...prev].filter(([id]) => id !== msg.worktreeId)))
}
clearFailedDelete(msg, registry)
if (msg.type === "agentManager.repoInfo") {
const info = msg as AgentManagerRepoInfoMessage
setRepoBranch(info.branch)
@@ -1,4 +1,14 @@
import type { ProjectStore } from "./store"
import type { ExtensionMessage } from "../../src/types/messages"
export function clearFailedDelete(
msg: ExtensionMessage,
stores: { ensure: (id: string) => ProjectStore; active: () => ProjectStore },
): void {
if (msg.type !== "error" || msg.code !== "agentManager.worktreeDeleteFailed" || !msg.worktreeId) return
const store = msg.projectId ? stores.ensure(msg.projectId) : stores.active()
store.setBusy((prev) => new Map([...prev].filter(([id]) => id !== msg.worktreeId)))
}
/** Clear setup indicators for every worktree in one multi-version group. */
export function clearMultiVersionBusy(store: ProjectStore, groupId: string): void {