From be2a08debc61af95b5efec727977ea9caa4f6d4e Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:46:51 -0800 Subject: [PATCH] fix(cleanup): hold row order while the delete dialog is open Rows no longer jump when git evidence, sizes or agent state stream in after the scan settles. The order is captured once and re-derived only on sort/filter change, open, Refresh, Ignore/Restore, or an idle settle. Row data still updates in place. Selection un-checks rows that become unselectable, bulk controls act on displayed rows, git status gets a fixed slot, size column is reserved, and streamed git evidence no longer rebuilds every evidenced row. --- .../workspace-cleanup-sort-header.test.tsx | 67 ++++++++++++++++ ...leanup-git-evidence.merge-identity.test.ts | 68 ++++++++++++++++ ...pace-cleanup-candidate-row.height.test.tsx | 78 +++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 src/renderer/src/components/workspace-cleanup/browse/workspace-cleanup-sort-header.test.tsx create mode 100644 src/renderer/src/components/workspace-cleanup/candidate-evidence/workspace-cleanup-git-evidence.merge-identity.test.ts create mode 100644 src/renderer/src/components/workspace-cleanup/candidate-list/workspace-cleanup-candidate-row.height.test.tsx diff --git a/src/renderer/src/components/workspace-cleanup/browse/workspace-cleanup-sort-header.test.tsx b/src/renderer/src/components/workspace-cleanup/browse/workspace-cleanup-sort-header.test.tsx new file mode 100644 index 00000000000..436a5a3ae5c --- /dev/null +++ b/src/renderer/src/components/workspace-cleanup/browse/workspace-cleanup-sort-header.test.tsx @@ -0,0 +1,67 @@ +// @vitest-environment happy-dom +import { act } from 'react' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, describe, expect, it, vi } from 'vitest' +import { DEFAULT_WORKSPACE_CLEANUP_SORT } from '../../../../../shared/workspace-cleanup/workspace-cleanup-filter-model' +import { WorkspaceCleanupSortHeader } from './workspace-cleanup-sort-header' + +let root: Root | null = null +afterEach(() => { + act(() => root?.unmount()) + root = null +}) + +function mount(counts: { bulk: number; selectedBulk: number; selectedDisplayed: number }) { + const onToggleSelectAll = vi.fn() + const container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) + act(() => + root!.render( + {}} + onToggleSelectAll={onToggleSelectAll} + onDeleteSelected={() => {}} + /> + ) + ) + const box = container.querySelector('[role="checkbox"]') as HTMLElement + return { box, onToggleSelectAll } +} + +describe('WorkspaceCleanupSortHeader select-all control', () => { + it('selects all from empty', () => { + const { box, onToggleSelectAll } = mount({ bulk: 3, selectedBulk: 0, selectedDisplayed: 0 }) + expect(box.getAttribute('aria-checked')).toBe('false') + act(() => box.click()) + expect(onToggleSelectAll).toHaveBeenCalledWith(true) + }) + + it('clears from mixed instead of filling', () => { + const { box, onToggleSelectAll } = mount({ bulk: 3, selectedBulk: 1, selectedDisplayed: 1 }) + expect(box.getAttribute('aria-checked')).toBe('mixed') + act(() => box.click()) + expect(onToggleSelectAll).toHaveBeenCalledWith(false) + }) + + it('clears from fully checked', () => { + const { box, onToggleSelectAll } = mount({ bulk: 3, selectedBulk: 3, selectedDisplayed: 3 }) + expect(box.getAttribute('aria-checked')).toBe('true') + act(() => box.click()) + expect(onToggleSelectAll).toHaveBeenCalledWith(false) + }) + + it('shows mixed and stays enabled when only an ignored row is ticked', () => { + const { box, onToggleSelectAll } = mount({ bulk: 0, selectedBulk: 0, selectedDisplayed: 1 }) + expect(box.getAttribute('aria-checked')).toBe('mixed') + expect(box.hasAttribute('disabled')).toBe(false) + act(() => box.click()) + expect(onToggleSelectAll).toHaveBeenCalledWith(false) + }) +}) diff --git a/src/renderer/src/components/workspace-cleanup/candidate-evidence/workspace-cleanup-git-evidence.merge-identity.test.ts b/src/renderer/src/components/workspace-cleanup/candidate-evidence/workspace-cleanup-git-evidence.merge-identity.test.ts new file mode 100644 index 00000000000..b8b3af22fbe --- /dev/null +++ b/src/renderer/src/components/workspace-cleanup/candidate-evidence/workspace-cleanup-git-evidence.merge-identity.test.ts @@ -0,0 +1,68 @@ +import { describe, expect, it } from 'vitest' +import { getWorkspaceCleanupCandidateIdentity } from '../../../../../shared/workspace-cleanup/workspace-cleanup-host-identity' +import type { WorkspaceCleanupCandidate } from '../../../../../shared/workspace-cleanup/workspace-cleanup' +import { makeCandidate } from '../query/workspace-cleanup-candidate-state.test-fixture' +import { + computeWorkspaceCleanupFacetList, + createWorkspaceCleanupFacetListCache +} from '../query/workspace-cleanup-facet-row-caches' +import { applyWorkspaceCleanupGitEvidence } from './workspace-cleanup-git-evidence' + +function unchecked(i: number): WorkspaceCleanupCandidate { + return makeCandidate({ + worktreeId: `repo-1::/repo/w${i}`, + displayName: `w${i}`, + path: `/repo/w${i}`, + git: { clean: true, upstreamAhead: 0, upstreamBehind: 0, checkedAt: null } + }) +} + +describe('applyWorkspaceCleanupGitEvidence identity', () => { + it('reuses merged rows so streamed evidence only rebuilds the rows that changed', () => { + const rows = Array.from({ length: 300 }, (_, i) => unchecked(i)) + const evidence = new Map() + const sources = { + worktreeById: new Map(), + workspaceStatuses: [], + sizeBytesByWorktreeId: new Map(), + lastVisitedAtByWorktreeId: {}, + liveAgentStatusByWorktreeId: new Map(), + reviewInfoByWorktreeId: new Map(), + dismissedIdentities: new Set() + } + const cache = createWorkspaceCleanupFacetListCache() + let rebuilt = 0 + for (let start = 0; start < rows.length; start += 5) { + for (const row of rows.slice(start, start + 5)) { + evidence.set(getWorkspaceCleanupCandidateIdentity(row), { + ...row, + git: { clean: false, upstreamAhead: 1, upstreamBehind: 0, checkedAt: 2 } + }) + } + const applied = applyWorkspaceCleanupGitEvidence(rows, evidence) + rebuilt += applied.filter((candidate) => !cache.byCandidate.has(candidate)).length + computeWorkspaceCleanupFacetList({ candidates: applied, sources: sources as never, cache }) + } + // Each row builds once unmerged and once when its own evidence lands (~600 total). Re-merging + // every evidenced row per publish rebuilt ~9.4k of 18k facets for the same stream. + expect(rebuilt).toBeLessThanOrEqual(rows.length * 2) + }) + + it('returns the same merged row until its evidence entry changes', () => { + const [row] = [unchecked(1)] + const first = new Map([ + [ + getWorkspaceCleanupCandidateIdentity(row), + { ...row, git: { clean: false, upstreamAhead: 0, upstreamBehind: 0, checkedAt: 2 } } + ] + ]) + const a = applyWorkspaceCleanupGitEvidence([row], first)[0] + expect(applyWorkspaceCleanupGitEvidence([row], new Map(first))[0]).toBe(a) + const next = new Map(first) + next.set(getWorkspaceCleanupCandidateIdentity(row), { + ...row, + git: { clean: true, upstreamAhead: 0, upstreamBehind: 0, checkedAt: 3 } + }) + expect(applyWorkspaceCleanupGitEvidence([row], next)[0]).not.toBe(a) + }) +}) diff --git a/src/renderer/src/components/workspace-cleanup/candidate-list/workspace-cleanup-candidate-row.height.test.tsx b/src/renderer/src/components/workspace-cleanup/candidate-list/workspace-cleanup-candidate-row.height.test.tsx new file mode 100644 index 00000000000..676aad6af25 --- /dev/null +++ b/src/renderer/src/components/workspace-cleanup/candidate-list/workspace-cleanup-candidate-row.height.test.tsx @@ -0,0 +1,78 @@ +// @vitest-environment happy-dom +import { act } from 'react' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, describe, expect, it, vi } from 'vitest' +import { TooltipProvider } from '@/components/ui/tooltip' +import { makeCandidate } from '../query/workspace-cleanup-candidate-state.test-fixture' +import { CandidateRow } from './workspace-cleanup-candidate-row' + +vi.mock('@/store', () => ({ useAppStore: () => undefined })) + +let root: Root | null = null +afterEach(() => { + act(() => root?.unmount()) + root = null +}) + +function render(overrides: { gitEvidencePending: boolean; dirty: boolean }): HTMLElement { + const candidate = makeCandidate({ + git: { + clean: !overrides.dirty, + upstreamAhead: overrides.dirty ? 2 : 0, + upstreamBehind: 0, + checkedAt: overrides.gitEvidencePending ? null : 1 + }, + blockers: overrides.dirty ? ['dirty-files'] : [] + }) + const noop = (): void => {} + const container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) + act(() => + root!.render( + + + + ) + ) + return container +} + +// jsdom has no layout, so assert the reservation itself: one fixed-height, fixed-width, +// non-wrapping slot holds every git state, so evidence swaps contents without resizing the row. +function gitSlotClass(container: HTMLElement): string | undefined { + return container.querySelector('span.h-5.w-60')?.className +} + +describe('CandidateRow git status slot', () => { + it('uses the same fixed slot while checking, clean and dirty', () => { + const checking = gitSlotClass(render({ gitEvidencePending: true, dirty: false })) + act(() => root?.unmount()) + const clean = gitSlotClass(render({ gitEvidencePending: false, dirty: false })) + act(() => root?.unmount()) + const dirty = gitSlotClass(render({ gitEvidencePending: false, dirty: true })) + expect(checking).toBeDefined() + expect(clean).toBe(checking) + expect(dirty).toBe(checking) + expect(checking).toContain('overflow-hidden') + expect(checking).toContain('shrink-0') + }) +})