TypeScript
fix(web): identify cleanup results by machine and folder (#20211)
Kolja5803c8b299da
diff --git a/apps/server/src/storageCleanup.test.ts b/apps/server/src/storageCleanup.test.tsindex fe2c8b86fb2..1f5645c87f7 100644--- a/apps/server/src/storageCleanup.test.ts+++ b/apps/server/src/storageCleanup.test.ts@@ -896,6 +896,7 @@ describe("orphan worktree reports", () => {outcome: "kept",reason: "No thread uses this worktree",path: orphan,+ projectPath: null,threadId: null,threadTitle: null,bytes: sizes.reduce((sum, size) => sum + size, 0),@@ -1472,7 +1473,7 @@ describe("storage cleanup reports and local file policies", () => {it.live("compares the checked-out branch without a full status", () =>runCleanupTest(Effect.gen(function* () {- const { service, fs, worktree, command, setThreads, fullStatusCalls } =+ const { service, fs, repo, worktree, command, setThreads, fullStatusCalls } =yield* cleanupFixture();const changed = { outcome: "kept", reason: "Repository or branch changed" };yield* command(worktree, ["checkout", "--detach"]);@@ -1490,8 +1491,15 @@ describe("storage cleanup reports and local file policies", () => {const index = (yield* command(worktree, ["rev-parse", "--git-path", "index"])).stdout;yield* fs.writeFileString(`${index.trim()}.lock`, "");const locked = (yield* service.runNow).entries[0];- expect(locked).toMatchObject({ outcome: "failed" });+ expect(locked).toMatchObject({+ outcome: "failed",+ projectPath: repo,+ path: worktree,+ threadId: "thread-1",+ threadTitle: "Thread",+ });expect(locked?.reason).toContain("Git index is locked");+ expect(yield* fs.readFileString(`${worktree}/tracked.txt`)).toBe("original\n");yield* fs.remove(`${index.trim()}.lock`);const gitFile = yield* fs.readFileString(`${worktree}/.git`);yield* fs.writeFileString(`${worktree}/.git`, "gitdir: /missing-git-directory\n");@@ -1502,7 +1510,7 @@ describe("storage cleanup reports and local file policies", () => {}),),);- it("decodes reports from servers without size fields", () => {+ it("decodes reports from servers without size or project fields", () => {const report = decodeCleanupReport({trigger: "manual",startedAt: "2026-06-10T12:00:00.000Z",@@ -1521,7 +1529,7 @@ describe("storage cleanup reports and local file policies", () => {omittedCount: 0,});expect(report.bytesFreed).toBe(0);- expect(report.entries[0]).toMatchObject({ bytes: null, files: null });+ expect(report.entries[0]).toMatchObject({ bytes: null, files: null, projectPath: null });});it.live.each([["any-local-files", ".env", "kept"],diff --git a/apps/server/src/storageCleanup.ts b/apps/server/src/storageCleanup.tsindex 098f53cc254..55275e5976b 100644--- a/apps/server/src/storageCleanup.ts+++ b/apps/server/src/storageCleanup.ts@@ -414,6 +414,7 @@ const make = Effect.gen(function* () {? "No thread uses this worktree": "No thread uses this folder, and it isn't a git worktree",path: worktreePath,+ projectPath: null,threadId: null,threadTitle: null,bytes,@@ -616,6 +617,7 @@ const make = Effect.gen(function* () {outcome: "kept",reason: "",path: worktreePath,+ projectPath: project?.workspaceRoot ?? null,threadId: thread.id,threadTitle: thread.title,bytes: null,@@ -947,6 +949,7 @@ const make = Effect.gen(function* () {outcome: "failed",reason: cleanupFailureReason(error),path: null,+ projectPath: null,threadId: null,threadTitle: null,bytes: null,@@ -979,6 +982,7 @@ const make = Effect.gen(function* () {outcome: files > 0 ? "removed" : "kept",reason: files === 0 ? "No expired files" : `Removed ${files} ${category.label}`,path: null,+ projectPath: null,threadId: null,threadTitle: null,bytes: files > 0 ? bytes : null,@@ -992,6 +996,7 @@ const make = Effect.gen(function* () {outcome: "failed",reason: cleanupFailureReason(error),path: null,+ projectPath: null,threadId: null,threadTitle: null,bytes: removed.files > 0 ? removed.bytes : null,diff --git a/apps/web/src/components/settings/StorageSettings.browser.test.tsx b/apps/web/src/components/settings/StorageSettings.browser.test.tsxindex dacb009d332..9573f3b3fb4 100644--- a/apps/web/src/components/settings/StorageSettings.browser.test.tsx+++ b/apps/web/src/components/settings/StorageSettings.browser.test.tsx@@ -8,6 +8,7 @@ import {import { act, type ReactNode } from "react";import { createRoot, type Root } from "react-dom/client";import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";+import { page } from "vite-plus/test/browser";const state = vi.hoisted(() => ({settings: {} as typeof DEFAULT_SERVER_SETTINGS,@@ -41,7 +42,7 @@ vi.mock(import("./SettingsScopeContext"), async (original) => ({useSettingsScope: (() => {const environment = {environmentId: "env",- label: "Machine",+ label: "Build workstation",serverConfig: {settings: state.settings,environment: {@@ -188,7 +189,7 @@ it("keeps cleanup disabled when settled retention and all other rules are off",expect(state.run).not.toHaveBeenCalled();});-it("shows an orphan's full path and size while keeping thread row titles unchanged", async () => {+it("shows orphan sizes and identifies failed worktrees with one connected machine", async () => {state.settings = {...state.settings,storageCleanup: { ...state.settings.storageCleanup, worktreeSettledAfterDays: 0 },@@ -202,6 +203,7 @@ it("shows an orphan's full path and size while keeping thread row titles unchangkind: "worktree",outcome: "kept",path: "/worktrees/repo/orphan",+ projectPath: null,threadId: null,threadTitle: null,reason: "No thread uses this folder, and it isn't a git worktree",@@ -210,16 +212,17 @@ it("shows an orphan's full path and size while keeping thread row titles unchang},{kind: "worktree",- outcome: "kept",+ outcome: "failed",path: "/worktrees/repo/thread-checkout",+ projectPath: "/projects/repo",threadId: ThreadId.make("thread"),threadTitle: "Thread title",- reason: "Thread is running or has pending work",+ reason: "Git index is locked. Status will resume when the index lock is removed.",bytes: null,files: null,},],- counts: { removed: 0, kept: 2, failed: 0 },+ counts: { removed: 0, kept: 1, failed: 1 },omittedCount: 0,bytesFreed: 0,};@@ -231,6 +234,23 @@ it("shows an orphan's full path and size while keeping thread row titles unchangconst titles = Array.from(container.querySelectorAll("h3"), (heading) => heading.textContent);expect(titles).toContain("/worktrees/repo/orphan");expect(titles).toContain("thread-checkout");+ const failedRow = page.elementLocator(+ page.getByRole("heading", { name: "thread-checkout", exact: true }).element().parentElement!,+ );+ await expect.element(failedRow.getByText("Build workstation", { exact: true })).toBeVisible();+ await expect.element(failedRow.getByText("/projects/repo", { exact: true })).toBeVisible();+ await expect+ .element(failedRow.getByText("/worktrees/repo/thread-checkout", { exact: true }))+ .toBeVisible();+ await expect.element(failedRow.getByText("Thread title", { exact: true })).toBeVisible();+ await expect+ .element(+ failedRow.getByText(+ "Git index is locked. Status will resume when the index lock is removed.",+ { exact: true },+ ),+ )+ .toBeVisible();expect(titles).not.toContain("/worktrees/repo/thread-checkout");expect(container.textContent).toContain("No thread uses this folder, and it isn't a git worktree",diff --git a/apps/web/src/components/settings/StorageSettings.tsx b/apps/web/src/components/settings/StorageSettings.tsxindex 69dc98c1f4d..78dd750109a 100644--- a/apps/web/src/components/settings/StorageSettings.tsx+++ b/apps/web/src/components/settings/StorageSettings.tsx@@ -192,7 +192,7 @@ function CleanupResults({environmentLabel,}: {report: StorageCleanupReport;- environmentLabel: string | undefined;+ environmentLabel: string;}) {return (<>@@ -208,13 +208,34 @@ function CleanupResults({return (<SettingsRowkey={`${entry.path ?? entry.kind}:${entry.threadId ?? index}`}- title={environmentLabel ? `${environmentLabel}: ${name}` : name}+ title={<span className="wrap-anywhere select-text">{name}</span>}description={- <span- className={`wrap-anywhere ${entry.outcome === "failed" ? "text-destructive" : ""}`}- >- {entry.threadTitle && entry.threadTitle !== name ? `${entry.threadTitle}. ` : ""}- {entry.reason}+ <span className="block space-y-2 wrap-anywhere select-text">+ <span className={`block ${entry.outcome === "failed" ? "text-destructive" : ""}`}>+ {entry.reason}+ </span>+ <span className="grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 border-l border-border/60 pl-3">+ <span>Machine</span>+ <span className="text-foreground/80">{environmentLabel}</span>+ {entry.projectPath && (+ <>+ <span>Project</span>+ <code className="text-foreground/80">{entry.projectPath}</code>+ </>+ )}+ {entry.path && (+ <>+ <span>Folder</span>+ <code className="text-foreground/80">{entry.path}</code>+ </>+ )}+ {entry.threadTitle && (+ <>+ <span>Thread</span>+ <span>{entry.threadTitle}</span>+ </>+ )}+ </span></span>}control={@@ -237,13 +258,12 @@ function CleanupResults({})}{report.omittedCount > 0 && (<p className="px-3 py-2.5 text-xs text-muted-foreground sm:px-4">- {environmentLabel ? `${environmentLabel}: ` : ""}- {report.omittedCount.toLocaleString()} more results.+ {environmentLabel}: {report.omittedCount.toLocaleString()} more results.</p>)}{report.entries.length === 0 && report.omittedCount === 0 && (<p className="px-3 py-2.5 text-xs text-muted-foreground sm:px-4">- {environmentLabel ? `${environmentLabel}: ` : ""}Nothing needed cleanup.+ {environmentLabel}: Nothing needed cleanup.</p>)}</>@@ -392,7 +412,7 @@ function CleanupSection() {<CleanupResultskey={environment.environmentId}report={report}- environmentLabel={connectedEnvironments.length > 1 ? label : undefined}+ environmentLabel={label}/>),)}diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.tsindex 3de6188d41c..707c5d0cf63 100644--- a/packages/contracts/src/settings.ts+++ b/packages/contracts/src/settings.ts@@ -1053,6 +1053,7 @@ export const StorageCleanupReportEntry = Schema.Struct({outcome: Schema.Literals(["removed", "kept", "failed"]),reason: Schema.String,path: Schema.NullOr(Schema.String),+ projectPath: Schema.NullOr(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed(null))),threadId: Schema.NullOr(ThreadId),threadTitle: Schema.NullOr(Schema.String),bytes: Schema.NullOr(Schema.Number).pipe(Schema.withDecodingDefault(Effect.succeed(null))),