From d2fb04cd9a0bb2dd3c3c933bf4da4af84d055483 Mon Sep 17 00:00:00 2001 From: OrcaWin Date: Mon, 2 Nov 2026 20:07:50 -0800 Subject: [PATCH] test: remove 131 low-value renderer store tests (#37648) --- config/flaky-test-pattern-baseline.txt | 1 - config/scripts/ci-shard-timings.json | 4 - .../slices/worktrees-hydration-purge.test.ts | 308 +------- .../worktrees-identity-migration.test.ts | 162 +---- .../slices/worktrees-lineage-state.test.ts | 380 ---------- ...orktrees-linked-review-push-target.test.ts | 117 --- .../worktrees-metadata-persistence.test.ts | 49 +- .../worktrees-multiple-attachments.test.ts | 24 - .../worktrees-pending-creation-state.test.ts | 11 - .../worktrees-purge-terminal-state.test.ts | 73 -- .../worktrees-recent-stamp-switch-on.test.ts | 19 - .../worktrees-remote-runtime-create.test.ts | 205 +----- .../worktrees-remote-runtime-removal.test.ts | 169 +---- .../worktrees-removal-state-cleanup.test.ts | 504 +------------ ...rees-terminal-pr-exact-observation.test.ts | 9 - .../worktrees-terminal-pr-url-linking.test.ts | 187 ----- ...rktrees-terminal-reference-origins.test.ts | 70 -- .../slices/worktrees-unread-state.test.ts | 134 ---- ...orktrees-workspace-selection-state.test.ts | 686 +----------------- .../worktrees/host-scoped-row-merges.test.ts | 17 - .../listing/detected-worktree-meta.test.ts | 91 +-- ...le-listing-purges-created-worktree.test.ts | 26 - .../worktree-host-ownership-repo-host.test.ts | 19 - .../worktree-host-ownership-unstamped.test.ts | 17 - .../listing/worktree-sort-order-patch.test.ts | 21 - .../metadata/worktree-meta-persist.test.ts | 80 -- ...ree-identity-rename-main-agreement.test.ts | 160 ---- .../host-qualified-removal-refusal.test.ts | 50 +- 28 files changed, 13 insertions(+), 3580 deletions(-) delete mode 100644 src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership-repo-host.test.ts delete mode 100644 src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership-unstamped.test.ts delete mode 100644 src/renderer/src/store/slices/worktrees/listing/worktree-sort-order-patch.test.ts delete mode 100644 src/renderer/src/store/slices/worktrees/session/worktree-identity-rename-main-agreement.test.ts diff --git a/config/flaky-test-pattern-baseline.txt b/config/flaky-test-pattern-baseline.txt index e26665af040..006e040f223 100644 --- a/config/flaky-test-pattern-baseline.txt +++ b/config/flaky-test-pattern-baseline.txt @@ -498,7 +498,6 @@ 1 test-no-real-time-wait:src/renderer/src/lib/orca-yaml-trust-prompt-slot-eviction.test.ts 1 test-no-real-time-wait:src/renderer/src/store/slices/github-pr-checks-fetch.test.ts 2 test-no-real-time-wait:src/renderer/src/store/slices/workspace-cleanup-removal-preflight.test.ts -2 test-no-real-time-wait:src/renderer/src/store/slices/worktrees-hydration-purge.test.ts 1 test-no-real-time-wait:src/renderer/src/store/terminals/legacy-relay-bridged-tab-close.test.ts 2 test-no-real-time-wait:src/shared/__tests__/process-host/windows-tree-kill-late-taskkill.win32.test.ts 3 test-no-real-time-wait:src/shared/darwin-process-table-capture.test.ts diff --git a/config/scripts/ci-shard-timings.json b/config/scripts/ci-shard-timings.json index cabbd11f1df..9af63e57fda 100644 --- a/config/scripts/ci-shard-timings.json +++ b/config/scripts/ci-shard-timings.json @@ -11472,11 +11472,7 @@ "src/renderer/src/store/slices/worktrees/host-scoped-row-merges.test.ts": 1805, "src/renderer/src/store/slices/worktrees/listing/detected-worktree-meta.test.ts": 318, "src/renderer/src/store/slices/worktrees/listing/stale-listing-purges-created-worktree.test.ts": 1828, - "src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership-repo-host.test.ts": 289, - "src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership-unstamped.test.ts": 112, - "src/renderer/src/store/slices/worktrees/listing/worktree-sort-order-patch.test.ts": 106, "src/renderer/src/store/slices/worktrees/metadata/worktree-meta-persist.test.ts": 361, - "src/renderer/src/store/slices/worktrees/session/worktree-identity-rename-main-agreement.test.ts": 1677, "src/renderer/src/store/slices/worktrees/session/worktree-no-op-notifications.test.ts": 1129, "src/renderer/src/store/slices/worktrees/teardown/host-qualified-removal-refusal.test.ts": 518, "src/renderer/src/store/slices/worktrees/teardown/remove-worktree-shared-records.test.ts": 2086, diff --git a/src/renderer/src/store/slices/worktrees-hydration-purge.test.ts b/src/renderer/src/store/slices/worktrees-hydration-purge.test.ts index 487d036572f..b942285e8d3 100644 --- a/src/renderer/src/store/slices/worktrees-hydration-purge.test.ts +++ b/src/renderer/src/store/slices/worktrees-hydration-purge.test.ts @@ -9,10 +9,9 @@ import { makeDetectedResult, qualifyDetectedResult } from './worktrees-detected- import { purgeHydratedWorktrees } from './worktrees/listing/hydrated-worktree-purge' import { worktreeCatalogVersionKey } from './worktrees/listing/worktree-catalog-version-state' import { makeTab } from './store-session-test-harness' -import { makeFolderWorkspace, makeLineage, makeWorktree } from './worktrees-slice-test-fixtures' +import { makeFolderWorkspace, makeWorktree } from './worktrees-slice-test-fixtures' import { createTestStore, - listKnownForExecutionHostMock, mockApi, resetRemoteRuntimeMocks, resetWorktreeSliceModuleMemory, @@ -165,121 +164,6 @@ describe('fetchAllWorktrees hydration-time purge (design §4.4)', () => { expect(store.getState().unifiedTabsByWorktree[moved]).toEqual([chat]) }) - it.each([false, true])( - 'hydrates connecting SSH worktrees with hydration purge completed=%s', - async (hasHydratedWorktreePurge) => { - const store = createTestStore() - const sshRepo = { - id: 'repo-ssh', - path: '/home/orca/repo', - displayName: 'SSH Repo', - badgeColor: '#000', - addedAt: 0, - connectionId: 'ssh-1' - } - const queued = makeWorktree({ - id: 'repo-ssh::/home/orca/queued', - repoId: 'repo-ssh', - path: '/home/orca/queued', - displayName: 'queued' - }) - listKnownForExecutionHostMock.mockResolvedValueOnce({ - status: 'complete', - repoId: sshRepo.id, - executionHostId: 'ssh:ssh-1', - result: makeDetectedResult(sshRepo.id, [queued], { - authoritative: false, - source: 'metadata-fallback' - }) - }) - store.setState({ - repos: [sshRepo], - hasHydratedWorktreePurge, - sshConnectionStates: new Map([ - [ - 'ssh-1', - { - targetId: 'ssh-1', - status: 'connecting', - error: null, - reconnectAttempt: 0, - providerEpoch: null - } - ] - ]) - } as Partial) - - await store.getState().fetchAllWorktrees() - - expect(store.getState().worktreesByRepo[sshRepo.id]).toEqual([ - { ...queued, hostId: 'ssh:ssh-1' } - ]) - expect(listKnownForExecutionHostMock).toHaveBeenCalledWith({ - repoId: sshRepo.id, - executionHostId: 'ssh:ssh-1' - }) - expect(mockApi.worktrees.listDetected).not.toHaveBeenCalled() - } - ) - - it('preserves resolved inline legacy lineage when side-map hydration is absent', async () => { - const store = createTestStore() - const parent = makeWorktree({ - id: 'repoA::/a/parent', - instanceId: 'parent-instance', - repoId: 'repoA', - path: '/a/parent' - }) - const child = makeWorktree({ - id: 'repoA::/a/child', - instanceId: 'child-instance', - repoId: 'repoA', - path: '/a/child' - }) - const lineage = makeLineage({ - worktreeId: child.id, - worktreeInstanceId: child.instanceId!, - parentWorktreeId: parent.id, - parentWorktreeInstanceId: parent.instanceId! - }) - const resolvedParent = { - ...parent, - parentWorktreeId: null, - childWorktreeIds: [child.id], - lineage: null, - workspaceLineage: null - } - const resolvedChild = { - ...child, - parentWorktreeId: parent.id, - childWorktreeIds: [], - lineage, - workspaceLineage: null - } - mockApi.worktrees.listDetected.mockResolvedValueOnce( - makeDetectedResult('repoA', [resolvedParent, resolvedChild]) - ) - store.setState({ - repos: [repoA], - hasHydratedWorktreePurge: true, - worktreeLineageById: {} - } as Partial) - - await store.getState().fetchAllWorktrees() - - expect(store.getState().worktreeLineageById).toEqual({}) - expect(store.getState().worktreesByRepo.repoA).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - id: child.id, - parentWorktreeId: parent.id, - lineage, - workspaceLineage: null - }) - ]) - ) - }) - it('defers the purge when a sibling repo fetch fails (F1 regression)', async () => { const store = createTestStore() const wtA = makeWorktree({ id: 'repoA::/a/wt1', repoId: 'repoA', path: '/a/wt1' }) @@ -404,38 +288,6 @@ describe('fetchAllWorktrees hydration-time purge (design §4.4)', () => { expect(store.getState().tabsByWorktree['repoA::/a/new-zombie']).toBeDefined() }) - it('can defer the first successful purge during local-only startup refresh', async () => { - const store = createTestStore() - const wtA = makeWorktree({ id: 'repoA::/a/wt1', repoId: 'repoA', path: '/a/wt1' }) - const wtB = makeWorktree({ id: 'repoB::/b/wt1', repoId: 'repoB', path: '/b/wt1' }) - - worktreeListMock.mockImplementation(async ({ repoId }: { repoId: string }) => - repoId === 'repoA' ? [wtA] : [wtB] - ) - - store.setState({ - repos: [repoA, repoB], - tabsByWorktree: { - 'repoA::/a/wt1': [{ id: 'tab-A', worktreeId: 'repoA::/a/wt1' }], - 'repoA::/a/zombie': [{ id: 'tab-zombie', worktreeId: 'repoA::/a/zombie' }], - 'repoB::/b/wt1': [{ id: 'tab-B', worktreeId: 'repoB::/b/wt1' }] - } - } as unknown as Partial) - - await store.getState().fetchAllWorktrees({ hydrationPurge: 'defer' }) - - expect(store.getState().hasHydratedWorktreePurge).toBe(false) - expect(store.getState().tabsByWorktree['repoA::/a/zombie']).toBeDefined() - - await store.getState().fetchAllWorktrees() - - expect(store.getState().hasHydratedWorktreePurge).toBe(true) - expect(store.getState().tabsByWorktree).toEqual({ - 'repoA::/a/wt1': [{ id: 'tab-A', worktreeId: 'repoA::/a/wt1' }], - 'repoB::/b/wt1': [{ id: 'tab-B', worktreeId: 'repoB::/b/wt1' }] - }) - }) - it('does not consume the one-shot purge before clean workspace session hydration', async () => { const store = createTestStore() const wtA = makeWorktree({ id: 'repoA::/a/wt1', repoId: 'repoA', path: '/a/wt1' }) @@ -477,51 +329,6 @@ describe('fetchAllWorktrees hydration-time purge (design §4.4)', () => { }) }) - // Why: multi-host regression — after hydration a mid-session fetch must never purge, even if a host reports zero worktrees. - it('does not purge another host tab state when hasHydratedWorktreePurge is already true and a host reports zero worktrees', async () => { - const store = createTestStore() - const wtA = makeWorktree({ id: 'repoA::/a/wt1', repoId: 'repoA', path: '/a/wt1' }) - - // repoB reports zero worktrees this round (host briefly empty), repoA fine. - worktreeListMock.mockImplementation(async ({ repoId }: { repoId: string }) => - repoId === 'repoA' ? [wtA] : [] - ) - - store.setState({ - hasHydratedWorktreePurge: true, - repos: [repoA, repoB], - tabsByWorktree: { - 'repoB::/b/wt1': [{ id: 'tab-B', worktreeId: 'repoB::/b/wt1' }] - }, - ptyIdsByTabId: { 'tab-B': ['remote:env-b@@terminal-b'] }, - terminalLayoutsByTabId: { - 'tab-B': { - root: null, - activeLeafId: null, - expandedLeafId: null, - ptyIdsByLeafId: { 'pane:1': 'remote:env-b@@terminal-b' } - } - } - } as unknown as Partial) - - await store.getState().fetchAllWorktrees() - - // The zero-worktree host's live tab/terminal state is untouched. - expect(store.getState().tabsByWorktree).toEqual({ - 'repoB::/b/wt1': [{ id: 'tab-B', worktreeId: 'repoB::/b/wt1' }] - }) - expect(store.getState().ptyIdsByTabId).toEqual({ 'tab-B': ['remote:env-b@@terminal-b'] }) - expect(store.getState().terminalLayoutsByTabId).toEqual({ - 'tab-B': { - root: null, - activeLeafId: null, - expandedLeafId: null, - ptyIdsByLeafId: { 'pane:1': 'remote:env-b@@terminal-b' } - } - }) - expect(store.getState().hasHydratedWorktreePurge).toBe(true) - }) - it('preserves sibling host worktrees during hydrated refresh when repo ids are duplicated', async () => { const store = createTestStore() const localRepo = { @@ -614,67 +421,6 @@ describe('fetchAllWorktrees hydration-time purge (design §4.4)', () => { }) }) - it('bounds concurrent repo scans during hydration-time refresh', async () => { - const store = createTestStore() - const repos = Array.from({ length: WORKTREE_REFRESH_CONCURRENCY + 2 }, (_, index) => ({ - id: `repo-${index}`, - path: `/repos/${index}`, - displayName: `repo-${index}`, - badgeColor: '#000', - addedAt: 0 - })) - let activeScans = 0 - let maxActiveScans = 0 - - worktreeListMock.mockImplementation(async ({ repoId }: { repoId: string }) => { - activeScans += 1 - maxActiveScans = Math.max(maxActiveScans, activeScans) - await new Promise((resolve) => setTimeout(resolve, 5)) - activeScans -= 1 - return [makeWorktree({ id: `${repoId}::/wt`, repoId, path: `/wt/${repoId}` })] - }) - - store.setState({ repos } as unknown as Partial) - - await store.getState().fetchAllWorktrees() - - expect(maxActiveScans).toBeLessThanOrEqual(WORKTREE_REFRESH_CONCURRENCY) - expect(worktreeListMock).toHaveBeenCalledTimes(repos.length) - expect(store.getState().hasHydratedWorktreePurge).toBe(true) - }) - - it('bounds concurrent repo scans after the hydration purge has run', async () => { - const store = createTestStore() - const repos = Array.from({ length: WORKTREE_REFRESH_CONCURRENCY + 2 }, (_, index) => ({ - id: `repo-${index}`, - path: `/repos/${index}`, - displayName: `repo-${index}`, - badgeColor: '#000', - addedAt: 0 - })) - let activeScans = 0 - let maxActiveScans = 0 - - worktreeListMock.mockImplementation(async ({ repoId }: { repoId: string }) => { - activeScans += 1 - maxActiveScans = Math.max(maxActiveScans, activeScans) - await new Promise((resolve) => setTimeout(resolve, 5)) - activeScans -= 1 - return [makeWorktree({ id: `${repoId}::/wt`, repoId, path: `/wt/${repoId}` })] - }) - - store.setState({ - hasHydratedWorktreePurge: true, - repos - } as unknown as Partial) - - await store.getState().fetchAllWorktrees() - - expect(maxActiveScans).toBeLessThanOrEqual(WORKTREE_REFRESH_CONCURRENCY) - expect(worktreeListMock).toHaveBeenCalledTimes(repos.length) - expect(store.getState().hasHydratedWorktreePurge).toBe(true) - }) - it('reuses an offline runtime preflight across hydrated all-worktree refresh repos', async () => { const store = createTestStore() const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {}) @@ -717,58 +463,6 @@ describe('fetchAllWorktrees hydration-time purge (design §4.4)', () => { expect(mockApi.worktrees.listDetected).not.toHaveBeenCalled() }) - it('does not coalesce a foreground re-probe onto a background reuse:true scan for a remote repo', async () => { - // Why: reuse is part of the coalescing key, so a foreground reuse:false scan must re-probe, not reuse a stale background failure. - const store = createTestStore() - const remote = makeWorktree({ id: 'repo1::/remote/wt', repoId: 'repo1', path: '/remote/wt' }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - hasHydratedWorktreePurge: true, - repos: [ - { - id: 'repo1', - path: '/r1', - displayName: 'R1', - badgeColor: '#000', - addedAt: 0, - executionHostId: 'runtime:env-1' - } - ] - } as Partial) - - let scanStartedCount = 0 - const scanReleases: (() => void)[] = [] - runtimeEnvironmentCall.mockImplementation(({ method }: RuntimeEnvironmentCallRequest) => { - if (method === 'worktree.detectedList') { - scanStartedCount += 1 - return new Promise((resolve) => { - scanReleases.push(() => - resolve({ - id: 'rpc', - ok: true, - result: makeDetectedResult('repo1', [remote]), - _meta: { runtimeId: 'runtime-remote' } - }) - ) - }) - } - return Promise.resolve({ id: method, ok: true, result: {}, _meta: {} }) - }) - - const background = store.getState().fetchAllWorktrees() - const foreground = store.getState().fetchWorktrees('repo1') - // Flush microtasks so both compat preflights settle and both scans block. - await new Promise((resolve) => setTimeout(resolve, 0)) - - expect(scanStartedCount).toBe(2) - - scanReleases.forEach((release) => release()) - await Promise.all([background, foreground]) - expect(store.getState().worktreesByRepo.repo1?.map((worktree) => worktree.id)).toEqual([ - remote.id - ]) - }) - it('preserves floating workspace state while purging a real stale worktree', async () => { const store = createTestStore() const wtA = makeWorktree({ id: 'repoA::/a/wt1', repoId: 'repoA', path: '/a/wt1' }) diff --git a/src/renderer/src/store/slices/worktrees-identity-migration.test.ts b/src/renderer/src/store/slices/worktrees-identity-migration.test.ts index 0593b391b23..1f5a576707f 100644 --- a/src/renderer/src/store/slices/worktrees-identity-migration.test.ts +++ b/src/renderer/src/store/slices/worktrees-identity-migration.test.ts @@ -6,11 +6,7 @@ import { hasDismissedHugeRepoWarning, markHugeRepoWarningDismissed } from '@/lib/source-control-huge-repo-warning-dismissals' -import { - getHostedReviewLinkMutationGenerationForTests, - getHostedReviewLinkWorktreeAliasCountForTests, - resetHostedReviewLinkMutationGenerationForTests -} from './worktrees' +import { resetHostedReviewLinkMutationGenerationForTests } from './worktrees' import { worktreeWorkspaceKey } from '../../../../shared/workspace-scope' import { makeWorktree } from './worktrees-slice-test-fixtures' import { @@ -205,92 +201,6 @@ describe('migrateWorktreeIdentity', () => { expect(s.terminalLayoutsByTabId.tab1).toBeDefined() }) - it('is a no-op when the ids match', () => { - const store = createTestStore() - store.setState({ - activeWorktreeId: OLD, - tabsByWorktree: { [OLD]: [{ id: 'tab1' }] } - } as unknown as Partial) - store.getState().migrateWorktreeIdentity(OLD, OLD) - expect(store.getState().tabsByWorktree[OLD]).toEqual([{ id: 'tab1' }]) - expect(store.getState().activeWorktreeId).toBe(OLD) - }) - - it('leaves an unrelated active worktree pointer alone', () => { - const store = createTestStore() - const OTHER = 'repo1::/ws/other' - store.setState({ - activeWorktreeId: OTHER, - tabsByWorktree: { [OLD]: [{ id: 'tab1' }] } - } as unknown as Partial) - store.getState().migrateWorktreeIdentity(OLD, NEW) - expect(store.getState().activeWorktreeId).toBe(OTHER) - expect(store.getState().tabsByWorktree[NEW]).toEqual([{ id: 'tab1' }]) - }) - - it('does not track hosted review aliases for migrations without hosted-review bookkeeping', () => { - const store = createTestStore() - store.setState({ - tabsByWorktree: { [OLD]: [{ id: 'tab1' }] } - } as unknown as Partial) - - store.getState().migrateWorktreeIdentity(OLD, NEW) - - expect(getHostedReviewLinkWorktreeAliasCountForTests()).toBe(0) - }) - - it('re-keys hosted review link generation and clear tombstones', async () => { - const store = createTestStore() - const oldWorktree = makeWorktree({ - id: OLD, - repoId: 'repo1', - path: '/ws/cunner', - branch: 'refs/heads/stack/one', - linkedPR: 101, - pushTarget: { remoteName: 'fork', branchName: 'old/review-head' } - }) - - store.setState({ worktreesByRepo: { repo1: [oldWorktree] } } as Partial) - store.getState().updateWorktreeGitIdentity(OLD, { branch: 'refs/heads/stack/two' }, null) - await vi.waitFor(() => { - expect(getHostedReviewLinkMutationGenerationForTests(OLD)).toBe(0) - expect(mockApi.worktrees.updateMeta).toHaveBeenCalledWith({ - worktreeId: OLD, - updates: { - linkedPR: null, - linkedGitLabMR: null, - linkedBitbucketPR: null, - linkedAzureDevOpsPR: null, - linkedGiteaPR: null, - pushTarget: undefined - } - }) - }) - - const switched = store.getState().worktreesByRepo.repo1[0] - store.setState({ worktreesByRepo: { repo1: [{ ...switched, id: NEW }] } } as Partial) - store.getState().migrateWorktreeIdentity(OLD, NEW) - worktreeListMock.mockResolvedValue([ - { - ...switched, - id: NEW, - path: '/ws/worktree-creation-spinner', - linkedPR: 101, - pushTarget: { remoteName: 'fork', branchName: 'old/review-head' } - } - ]) - - await store.getState().fetchWorktrees('repo1') - - expect(getHostedReviewLinkMutationGenerationForTests(OLD)).toBe(0) - expect(store.getState().worktreesByRepo.repo1[0]).toMatchObject({ - id: NEW, - branch: 'refs/heads/stack/two', - linkedPR: null, - pushTarget: undefined - }) - }) - it('sanitizes lagging old-id worktree refresh rows after hosted review bookkeeping migrates', async () => { const store = createTestStore() const oldWorktree = makeWorktree({ @@ -341,76 +251,6 @@ describe('migrateWorktreeIdentity', () => { }) }) - it('prunes hosted review aliases when manual hosted-review updates supersede a migrated clear', async () => { - const store = createTestStore() - const oldWorktree = makeWorktree({ - id: OLD, - repoId: 'repo1', - path: '/ws/cunner', - branch: 'refs/heads/stack/one', - linkedPR: 101 - }) - - store.setState({ worktreesByRepo: { repo1: [oldWorktree] } } as Partial) - store.getState().updateWorktreeGitIdentity(OLD, { branch: 'refs/heads/stack/two' }, null) - await vi.waitFor(() => { - expect(mockApi.worktrees.updateMeta).toHaveBeenCalledWith({ - worktreeId: OLD, - updates: expect.objectContaining({ linkedPR: null }) - }) - }) - const switched = store.getState().worktreesByRepo.repo1[0] - store.setState({ worktreesByRepo: { repo1: [{ ...switched, id: NEW }] } } as Partial) - store.getState().migrateWorktreeIdentity(OLD, NEW) - expect(getHostedReviewLinkWorktreeAliasCountForTests()).toBeGreaterThan(0) - - await store.getState().updateWorktreeMeta(NEW, { linkedPR: 202 }) - - expect(getHostedReviewLinkWorktreeAliasCountForTests()).toBe(0) - }) - - it('persists a queued branch-switch clear after worktree id migration', async () => { - const store = createTestStore() - const oldWorktree = makeWorktree({ - id: OLD, - repoId: 'repo1', - path: '/ws/cunner', - branch: 'refs/heads/stack/one', - linkedPR: 101, - pushTarget: { remoteName: 'fork', branchName: 'old/review-head' } - }) - - store.setState({ worktreesByRepo: { repo1: [oldWorktree] } } as Partial) - store.getState().updateWorktreeGitIdentity(OLD, { branch: 'refs/heads/stack/two' }, null) - const switched = store.getState().worktreesByRepo.repo1[0] - store.setState({ - worktreesByRepo: { - repo1: [ - { - ...switched, - id: NEW, - path: '/ws/worktree-creation-spinner' - } - ] - } - } as Partial) - store.getState().migrateWorktreeIdentity(OLD, NEW) - - await vi.waitFor(() => { - expect(mockApi.worktrees.updateMeta).toHaveBeenCalledWith({ - worktreeId: NEW, - updates: { - linkedPR: null, - linkedGitLabMR: null, - linkedBitbucketPR: null, - linkedAzureDevOpsPR: null, - linkedGiteaPR: null, - pushTarget: undefined - } - }) - }) - }) - it('persists a queued branch-switch clear when migration happens during the old-id write', async () => { const store = createTestStore() const oldWorktree = makeWorktree({ diff --git a/src/renderer/src/store/slices/worktrees-lineage-state.test.ts b/src/renderer/src/store/slices/worktrees-lineage-state.test.ts index 8cf7a6e3cc7..3c8f364f966 100644 --- a/src/renderer/src/store/slices/worktrees-lineage-state.test.ts +++ b/src/renderer/src/store/slices/worktrees-lineage-state.test.ts @@ -37,83 +37,6 @@ describe('worktree lineage state', () => { resetRemoteRuntimeMocks() }) - it('fetches persisted lineage into the renderer store', async () => { - const store = createTestStore() - const lineage = makeLineage() - mockApi.worktrees.listLineage.mockResolvedValue({ [lineage.worktreeId]: lineage }) - - await store.getState().fetchWorktreeLineage() - - expect(mockApi.worktrees.listLineage).toHaveBeenCalled() - expect(store.getState().worktreeLineageById).toEqual({ [lineage.worktreeId]: lineage }) - expect(store.getState().workspaceLineageByChildKey).toEqual({}) - }) - - it('fetches workspace lineage from the expanded local lineage response', async () => { - const store = createTestStore() - const lineage = makeLineage() - const workspaceLineage = makeWorkspaceLineage() - mockApi.worktrees.listLineage.mockResolvedValue({ - lineage: { [lineage.worktreeId]: lineage }, - workspaceLineage: { [workspaceLineage.childWorkspaceKey]: workspaceLineage } - }) - - await store.getState().fetchWorktreeLineage() - - expect(store.getState().worktreeLineageById).toEqual({ [lineage.worktreeId]: lineage }) - expect(store.getState().workspaceLineageByChildKey).toEqual({ - [workspaceLineage.childWorkspaceKey]: workspaceLineage - }) - }) - - it('keeps lineage map and entry identity across a cloned no-op refresh', async () => { - const lineage = makeLineage({ - capture: { source: 'orchestration-context', confidence: 'explicit' }, - taskId: 'task-42', - coordinatorHandle: 'coord-1' - }) - const workspaceLineage = makeWorkspaceLineage({ - childWorkspaceKey: worktreeWorkspaceKey(lineage.worktreeId), - parentWorkspaceKey: worktreeWorkspaceKey(lineage.parentWorktreeId), - childInstanceId: lineage.worktreeInstanceId, - parentInstanceId: lineage.parentWorktreeInstanceId, - origin: lineage.origin, - capture: lineage.capture, - taskId: lineage.taskId, - coordinatorHandle: lineage.coordinatorHandle, - createdAt: lineage.createdAt - }) - const store = createLocalLineageTestStore(lineage) - const payload = { - lineage: { [lineage.worktreeId]: lineage }, - workspaceLineage: { [workspaceLineage.childWorkspaceKey]: workspaceLineage } - } - mockApi.worktrees.listLineage.mockImplementation(async () => structuredClone(payload)) - - await store.getState().fetchWorktreeLineage() - const afterFirst = store.getState() - const lineageById = afterFirst.worktreeLineageById - const workspaceByKey = afterFirst.workspaceLineageByChildKey - const lineageEntry = lineageById[lineage.worktreeId] - const workspaceEntry = workspaceByKey[workspaceLineage.childWorkspaceKey] - expect(lineageEntry).toEqual(lineage) - expect(lineageEntry).not.toBe(lineage) - const subscriber = vi.fn() - const unsubscribe = store.subscribe(subscriber) - - await store.getState().fetchWorktreeLineage() - unsubscribe() - - expect(store.getState().worktreeLineageById).toBe(lineageById) - expect(store.getState().workspaceLineageByChildKey).toBe(workspaceByKey) - expect(store.getState().worktreeLineageById[lineage.worktreeId]).toBe(lineageEntry) - expect(store.getState().workspaceLineageByChildKey[workspaceLineage.childWorkspaceKey]).toBe( - workspaceEntry - ) - expect(subscriber).not.toHaveBeenCalled() - expect(mockApi.worktrees.listLineage).toHaveBeenCalledTimes(2) - }) - it('preserves other-host lineage row identity across a cloned same-host refresh', async () => { const store = createTestStore() const localWorktree = makeWorktree({ @@ -195,59 +118,6 @@ describe('worktree lineage state', () => { ) }) - it('clears workspace lineage on successful old-shape lineage refresh', async () => { - const store = createTestStore() - const lineage = makeLineage() - const workspaceLineage = makeWorkspaceLineage() - store.setState({ - workspaceLineageByChildKey: { [workspaceLineage.childWorkspaceKey]: workspaceLineage } - } as Partial) - mockApi.worktrees.listLineage.mockResolvedValue({ [lineage.worktreeId]: lineage }) - - await store.getState().fetchWorktreeLineage() - - expect(store.getState().worktreeLineageById).toEqual({ [lineage.worktreeId]: lineage }) - expect(store.getState().workspaceLineageByChildKey).toEqual({}) - }) - - it('updates a child lineage entry and bumps sortEpoch', async () => { - const lineage = makeLineage() - const store = createLocalLineageTestStore(lineage) - mockApi.worktrees.updateLineage.mockResolvedValue(lineage) - store.setState({ sortEpoch: 3 } as Partial) - - await store.getState().updateWorktreeLineage(lineage.worktreeId, { - parentWorktreeId: lineage.parentWorktreeId - }) - - expect(mockApi.worktrees.updateLineage).toHaveBeenCalledWith({ - worktreeId: lineage.worktreeId, - parentWorktreeId: lineage.parentWorktreeId - }) - expect(store.getState().worktreeLineageById).toEqual({ [lineage.worktreeId]: lineage }) - expect(store.getState().sortEpoch).toBe(4) - }) - - it('removes child lineage entries when the backend clears the parent link', async () => { - const lineage = makeLineage() - const store = createLocalLineageTestStore(lineage) - const workspaceLineage = makeWorkspaceLineage({ - childWorkspaceKey: worktreeWorkspaceKey(lineage.worktreeId) - }) - mockApi.worktrees.updateLineage.mockResolvedValue(null) - store.setState({ - worktreeLineageById: { [lineage.worktreeId]: lineage }, - workspaceLineageByChildKey: { [workspaceLineage.childWorkspaceKey]: workspaceLineage }, - sortEpoch: 3 - } as Partial) - - await store.getState().updateWorktreeLineage(lineage.worktreeId, { noParent: true }) - - expect(store.getState().worktreeLineageById).toEqual({}) - expect(store.getState().workspaceLineageByChildKey).toEqual({}) - expect(store.getState().sortEpoch).toBe(4) - }) - it('clears inline local lineage immediately when an inline-only child is unnested', async () => { const store = createTestStore() const lineage = makeLineage() @@ -316,153 +186,6 @@ describe('worktree lineage state', () => { }) }) - it('refetches lineage and rethrows after an update failure', async () => { - const lineage = makeLineage() - const store = createLocalLineageTestStore(lineage) - mockApi.worktrees.updateLineage.mockRejectedValueOnce(new Error('stale parent')) - mockApi.worktrees.listLineage.mockResolvedValue({ [lineage.worktreeId]: lineage }) - vi.spyOn(console, 'error').mockImplementation(() => {}) - - await expect( - store.getState().updateWorktreeLineage(lineage.worktreeId, { - parentWorktreeId: lineage.parentWorktreeId - }) - ).rejects.toThrow('stale parent') - - expect(mockApi.worktrees.listLineage).toHaveBeenCalled() - expect(store.getState().worktreeLineageById).toEqual({ [lineage.worktreeId]: lineage }) - }) - - it('refetches lineage and rethrows when explicit parent assignment fails', async () => { - const lineage = makeLineage() - const store = createLocalLineageTestStore(lineage) - mockApi.worktrees.updateLineage.mockRejectedValueOnce(new Error('stale parent')) - mockApi.worktrees.listLineage.mockResolvedValue({ [lineage.worktreeId]: lineage }) - vi.spyOn(console, 'error').mockImplementation(() => {}) - - await expect( - store.getState().assignWorktreeParent(lineage.worktreeId, { - parentWorktreeId: lineage.parentWorktreeId - }) - ).rejects.toThrow('stale parent') - - expect(mockApi.worktrees.listLineage).toHaveBeenCalled() - expect(store.getState().worktreeLineageById).toEqual({ [lineage.worktreeId]: lineage }) - }) - - it('fetches raw lineage from the active remote runtime environment', async () => { - const store = createTestStore() - const lineage = makeLineage() - runtimeEnvironmentCall.mockResolvedValue({ - id: 'rpc-lineage-list', - ok: true, - result: { lineage: { [lineage.worktreeId]: lineage } }, - _meta: { runtimeId: 'runtime-remote' } - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - worktreesByRepo: {} - } as Partial) - - await store.getState().fetchWorktreeLineage() - - expect(runtimeEnvironmentCall).toHaveBeenCalledWith({ - selector: 'env-1', - method: 'worktree.lineageList', - params: undefined, - timeoutMs: 15_000 - }) - expect(mockApi.worktrees.listLineage).not.toHaveBeenCalled() - expect(store.getState().worktreeLineageById).toEqual({ [lineage.worktreeId]: lineage }) - }) - - it('pins lineage refresh to the event runtime when the default is local', async () => { - const store = createTestStore() - const lineage = makeLineage() - runtimeEnvironmentCall.mockResolvedValue({ - id: 'rpc-lineage-list', - ok: true, - result: { lineage: { [lineage.worktreeId]: lineage } }, - _meta: { runtimeId: 'runtime-remote' } - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: null } as never, - worktreesByRepo: {} - } as Partial) - - await store.getState().fetchWorktreeLineage({ executionHostId: 'runtime:env-1' }) - - expect(runtimeEnvironmentCall).toHaveBeenCalledWith({ - selector: 'env-1', - method: 'worktree.lineageList', - params: undefined, - timeoutMs: 15_000 - }) - expect(mockApi.worktrees.listLineage).not.toHaveBeenCalled() - }) - - it('pins lineage refresh to the local host when forceLocalOwner is set', async () => { - const store = createTestStore() - const lineage = makeLineage() - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - worktreesByRepo: {} - } as Partial) - mockApi.worktrees.listLineage.mockResolvedValue({ [lineage.worktreeId]: lineage }) - - await store.getState().fetchWorktreeLineage({ forceLocalOwner: true }) - - expect(mockApi.worktrees.listLineage).toHaveBeenCalledTimes(1) - expect(runtimeEnvironmentCall).not.toHaveBeenCalled() - expect(store.getState().worktreeLineageById).toEqual({ [lineage.worktreeId]: lineage }) - }) - - it('updates lineage through the active remote runtime environment', async () => { - const store = createTestStore() - const lineage = makeLineage() - const child = makeWorktree({ - id: lineage.worktreeId, - repoId: 'repo1', - path: '/remote/child', - // Why: ingest stamps a server's rows; routing follows the stamp, not focus. - hostId: 'runtime:env-1' - }) - const updatedChild = { ...child, lineage } - runtimeEnvironmentCall.mockResolvedValue({ - id: 'rpc-set-lineage', - ok: true, - result: { worktree: updatedChild }, - _meta: { runtimeId: 'runtime-remote' } - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - worktreesByRepo: { repo1: [child] }, - sortEpoch: 3 - } as Partial) - - await store.getState().updateWorktreeLineage(lineage.worktreeId, { - parentWorktreeId: lineage.parentWorktreeId - }) - - expect(runtimeEnvironmentCall).toHaveBeenCalledWith({ - selector: 'env-1', - method: 'worktree.set', - params: { - worktree: `id:${lineage.worktreeId}`, - parentWorktree: `id:${lineage.parentWorktreeId}` - }, - timeoutMs: 15_000 - }) - expect(mockApi.worktrees.updateLineage).not.toHaveBeenCalled() - expect(store.getState().worktreeLineageById).toEqual({ [lineage.worktreeId]: lineage }) - expect(store.getState().worktreesByRepo.repo1?.[0]).toEqual({ - ...updatedChild, - hostId: 'runtime:env-1', - runtimeOwnerEnvironmentId: 'env-1' - }) - expect(store.getState().sortEpoch).toBe(4) - }) - it('stamps the owning runtime host onto worktrees returned by a remote lineage update', async () => { const store = createTestStore() const lineage = makeLineage({ @@ -507,66 +230,6 @@ describe('worktree lineage state', () => { }) }) - it('assigns a parent through the active remote runtime environment and rethrows failures', async () => { - const store = createTestStore() - const lineage = makeLineage() - const child = makeWorktree({ - id: lineage.worktreeId, - repoId: 'repo1', - path: '/remote/child', - // Why: ingest stamps a server's rows; routing follows the stamp, not focus. - hostId: 'runtime:env-1' - }) - const updatedChild = { ...child, lineage } - runtimeEnvironmentCall.mockResolvedValueOnce({ - id: 'rpc-assign-parent', - ok: true, - result: { worktree: updatedChild }, - _meta: { runtimeId: 'runtime-remote' } - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - worktreesByRepo: { repo1: [child] }, - sortEpoch: 3 - } as Partial) - - await store.getState().assignWorktreeParent(lineage.worktreeId, { - parentWorktreeId: lineage.parentWorktreeId - }) - - expect(runtimeEnvironmentCall).toHaveBeenCalledWith({ - selector: 'env-1', - method: 'worktree.set', - params: { - worktree: `id:${lineage.worktreeId}`, - parentWorktree: `id:${lineage.parentWorktreeId}` - }, - timeoutMs: 15_000 - }) - expect(mockApi.worktrees.updateLineage).not.toHaveBeenCalled() - expect(store.getState().worktreeLineageById).toEqual({ [lineage.worktreeId]: lineage }) - expect(store.getState().worktreesByRepo.repo1?.[0]).toEqual({ - ...updatedChild, - hostId: 'runtime:env-1', - runtimeOwnerEnvironmentId: 'env-1' - }) - expect(store.getState().sortEpoch).toBe(4) - - runtimeEnvironmentCall - .mockRejectedValueOnce(new Error('remote lineage failed')) - .mockResolvedValueOnce({ - id: 'rpc-lineage-refresh', - ok: true, - result: { lineage: {} }, - _meta: { runtimeId: 'runtime-remote' } - }) - await expect( - store.getState().assignWorktreeParent(lineage.worktreeId, { - parentWorktreeId: lineage.parentWorktreeId - }) - ).rejects.toThrow('remote lineage failed') - }) - it('assigns a parent through the worktree owner runtime when host-stamped', async () => { const store = createTestStore() const lineage = makeLineage() @@ -722,49 +385,6 @@ describe('worktree lineage state', () => { }) }) - // Reject unresolved lineage routes so sidebar callers can toast them (WorktreeContextMenu.handleRemoveParentLink). - it('rejects the lineage update when the owner route cannot be resolved', async () => { - const store = createTestStore() - const worktreeId = 'repo-shared::/same/path' - store.setState({ - settings: { activeRuntimeEnvironmentId: 'hub-c' } as never, - worktreesByRepo: { - 'repo-shared': [ - makeWorktree({ - id: worktreeId, - repoId: 'repo-shared', - hostId: 'ssh:ssh-a', - runtimeOwnerEnvironmentId: 'hub-a' - }), - makeWorktree({ - id: worktreeId, - repoId: 'repo-shared', - hostId: 'ssh:ssh-b', - runtimeOwnerEnvironmentId: 'hub-b' - }) - ] - } - } as Partial) - - await expect( - store.getState().updateWorktreeLineage(worktreeId, { noParent: true }) - ).rejects.toThrow() - - expect(mockApi.worktrees.updateLineage).not.toHaveBeenCalled() - }) - - it('rethrows the original update failure when the recovery refresh fails', async () => { - const lineage = makeLineage() - const store = createLocalLineageTestStore(lineage) - mockApi.worktrees.updateLineage.mockRejectedValueOnce(new Error('unnest failed')) - mockApi.worktrees.listLineage.mockRejectedValueOnce(new Error('refresh failed')) - vi.spyOn(console, 'error').mockImplementation(() => {}) - - await expect( - store.getState().updateWorktreeLineage(lineage.worktreeId, { noParent: true }) - ).rejects.toThrow('unnest failed') - }) - it('rethrows the original assign failure when the recovery refresh fails', async () => { const lineage = makeLineage() const store = createLocalLineageTestStore(lineage) diff --git a/src/renderer/src/store/slices/worktrees-linked-review-push-target.test.ts b/src/renderer/src/store/slices/worktrees-linked-review-push-target.test.ts index d752452036e..581a75e6b9d 100644 --- a/src/renderer/src/store/slices/worktrees-linked-review-push-target.test.ts +++ b/src/renderer/src/store/slices/worktrees-linked-review-push-target.test.ts @@ -71,32 +71,6 @@ describe('worktree remote runtime mutations', () => { expect(lastWrite).not.toHaveProperty('pushTarget') }) - it('clears a stale push target when unlinking the GitHub PR that supplied it', async () => { - const store = createTestStore() - const pushTarget = { remoteName: 'fork', branchName: 'owner/old-pr' } - const wt = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/path/wt1', - linkedPR: 2548, - pushTarget - }) - store.setState({ - repos: [ - { id: 'repo1', path: '/repo1', displayName: 'Repo 1', badgeColor: '#000', addedAt: 0 } - ], - worktreesByRepo: { repo1: [wt] } - } as Partial) - - await store.getState().updateWorktreeMeta(wt.id, { linkedPR: null }) - expect(mockApi.worktrees.updateMeta).toHaveBeenCalledWith({ - worktreeId: wt.id, - executionHostId: wt.hostId ?? 'local', - updates: expect.objectContaining({ linkedPR: null, pushTarget: undefined }) - }) - expect(store.getState().worktreesByRepo.repo1[0]?.pushTarget).toBeUndefined() - }) - it('switches the selected review to GitLab and clears the previous push target', async () => { const store = createTestStore() const oldPushTarget = { remoteName: 'fork', branchName: 'owner/old-pr' } @@ -275,66 +249,6 @@ describe('worktree remote runtime mutations', () => { expect(store.getState().worktreesByRepo.repo1[0]?.pushTarget).toBeUndefined() }) - it('hydrates a host-stamped linked GitHub PR push target through the worktree owner runtime', async () => { - const store = createTestStore() - const pushTarget = { remoteName: 'fork', branchName: 'feature/owner-runtime-pr' } - const wt = makeWorktree({ - id: 'repo1::/path/owner-runtime-wt', - repoId: 'repo1', - path: '/path/owner-runtime-wt', - hostId: 'runtime:owner-env', - linkedPR: 5571 - }) - runtimeEnvironmentCall.mockImplementation(({ method }: RuntimeEnvironmentCallRequest) => { - if (method === 'worktree.resolvePrBase') { - return Promise.resolve({ - id: 'rpc-owner-resolve-pr-base', - ok: true, - result: { baseBranch: 'fork-head', pushTarget }, - _meta: { runtimeId: 'owner-env' } - }) - } - if (method === 'worktree.set') { - return Promise.resolve({ - id: 'rpc-owner-set-worktree', - ok: true, - result: { worktree: { ...wt, pushTarget } }, - _meta: { runtimeId: 'owner-env' } - }) - } - throw new Error(`Unexpected runtime method ${method}`) - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'focused-env' } as never, - repos: [ - { id: 'repo1', path: '/repo1', displayName: 'Repo 1', badgeColor: '#000', addedAt: 0 } - ], - worktreesByRepo: { repo1: [wt] } - } as Partial) - - await store.getState().ensureHostedReviewPushTarget(wt.id) - - expect(runtimeEnvironmentCall).toHaveBeenCalledWith( - expect.objectContaining({ - selector: 'owner-env', - method: 'worktree.resolvePrBase', - params: expect.objectContaining({ repo: 'repo1', prNumber: 5571 }), - timeoutMs: 30_000 - }) - ) - expect(runtimeEnvironmentCall).toHaveBeenCalledWith( - expect.objectContaining({ - selector: 'owner-env', - method: 'worktree.set', - params: expect.objectContaining({ worktree: `id:${wt.id}`, pushTarget }), - timeoutMs: 15_000 - }) - ) - expect(mockApi.worktrees.resolvePrBase).not.toHaveBeenCalled() - expect(mockApi.worktrees.updateMeta).not.toHaveBeenCalled() - expect(store.getState().worktreesByRepo.repo1[0]?.pushTarget).toEqual(pushTarget) - }) - it('hydrates an SSH-owned linked GitHub PR push target through local IPC when a runtime is focused', async () => { const store = createTestStore() const pushTarget = { remoteName: 'fork', branchName: 'feature/ssh-pr' } @@ -378,37 +292,6 @@ describe('worktree remote runtime mutations', () => { expect(runtimeEnvironmentCall).not.toHaveBeenCalled() expect(store.getState().worktreesByRepo['repo-ssh'][0]?.pushTarget).toEqual(pushTarget) }) - - it('skips the push-target lookup for a genuinely ambiguous owner instead of throwing past the { ok, error } contract', async () => { - const store = createTestStore() - const worktreeId = 'repo-shared::/same/path' - store.setState({ - settings: { activeRuntimeEnvironmentId: 'hub-c' } as never, - worktreesByRepo: { - 'repo-shared': [ - makeWorktree({ - id: worktreeId, - repoId: 'repo-shared', - hostId: 'ssh:ssh-a', - runtimeOwnerEnvironmentId: 'hub-a' - }), - makeWorktree({ - id: worktreeId, - repoId: 'repo-shared', - hostId: 'ssh:ssh-b', - runtimeOwnerEnvironmentId: 'hub-b' - }) - ] - } - } as Partial) - - const result = await store.getState().updateWorktreeMeta(worktreeId, { linkedPR: 123 }) - - // The ambiguous owner must surface as a graceful { ok: false }, not an uncaught rejection. - expect(result.ok).toBe(false) - expect(mockApi.worktrees.resolvePrBase).not.toHaveBeenCalled() - expect(mockApi.worktrees.updateMeta).not.toHaveBeenCalled() - }) it('updates only the explicitly selected owner when locators collide', async () => { const store = createTestStore() const worktreeId = 'repo-shared::/same/path' diff --git a/src/renderer/src/store/slices/worktrees-metadata-persistence.test.ts b/src/renderer/src/store/slices/worktrees-metadata-persistence.test.ts index 9c732f71318..c099ace4be0 100644 --- a/src/renderer/src/store/slices/worktrees-metadata-persistence.test.ts +++ b/src/renderer/src/store/slices/worktrees-metadata-persistence.test.ts @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import type { AppState } from '../types' -import { toast } from 'sonner' +import 'sonner' import type { RuntimeEnvironmentCallRequest } from '../../runtime/runtime-compatibility-test-fixture' import { createCompatibleRuntimeStatusResponse } from '../../runtime/runtime-compatibility-test-fixture' import { WORKTREE_RENAME_ERROR_DISMISS_RUNTIME_CAPABILITY } from '../../../../shared/worktree-runtime-capabilities' @@ -99,37 +99,6 @@ describe('worktree remote runtime mutations', () => { } ) - it('persists worktree metadata through the active remote runtime environment', async () => { - const store = createTestStore() - const wt = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/path/wt1', - hostId: 'runtime:env-1' - }) - runtimeEnvironmentCall.mockResolvedValue({ - id: 'rpc-set', - ok: true, - result: { worktree: { ...wt, comment: 'remote note' } }, - _meta: { runtimeId: 'runtime-remote' } - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - worktreesByRepo: { repo1: [wt] } - } as Partial) - - await store.getState().updateWorktreeMeta(wt.id, { comment: 'remote note' }) - - expect(runtimeEnvironmentCall).toHaveBeenCalledWith({ - selector: 'env-1', - method: 'worktree.set', - params: expect.objectContaining({ worktree: `id:${wt.id}`, comment: 'remote note' }), - timeoutMs: 15_000 - }) - expect(mockApi.worktrees.updateMeta).not.toHaveBeenCalled() - expect(store.getState().worktreesByRepo.repo1[0]?.comment).toBe('remote note') - }) - it('force-deletes a preserved HUB-owned SSH branch through its HUB', async () => { const store = createTestStore() const wt = makeWorktree({ @@ -167,22 +136,6 @@ describe('worktree remote runtime mutations', () => { expect(mockApi.worktrees.forceDeletePreservedBranch).not.toHaveBeenCalled() }) - it('suppresses per-branch feedback for an aggregate delete', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - store.setState({ worktreesByRepo: { repo1: [wt] } } as Partial) - vi.mocked(toast.success).mockClear() - vi.mocked(toast.error).mockClear() - - const result = await store - .getState() - .forceDeletePreservedBranch(wt.id, 'feature/test', 'abc123', { suppressToast: true }) - - expect(result).toEqual({ ok: true, deleted: true }) - expect(toast.success).not.toHaveBeenCalled() - expect(toast.error).not.toHaveBeenCalled() - }) - it('fails preserved branch deletion closed for two HUB owners', async () => { const store = createTestStore() const worktreeId = 'repo-ssh::/srv/same-wt' diff --git a/src/renderer/src/store/slices/worktrees-multiple-attachments.test.ts b/src/renderer/src/store/slices/worktrees-multiple-attachments.test.ts index 61aa6fc2c12..f106848314b 100644 --- a/src/renderer/src/store/slices/worktrees-multiple-attachments.test.ts +++ b/src/renderer/src/store/slices/worktrees-multiple-attachments.test.ts @@ -69,30 +69,6 @@ describe('workspace attachment collections', () => { ).toEqual([base[1]]) }) - it('removes a secondary review without disturbing the active review or task', async () => { - const store = createTestStore() - const wt = makeWorktree({ - id: 'repo1::/work', - repoId: 'repo1', - linkedPR: 42, - linkedIssue: 9, - linkedItems: [ - { provider: 'github', type: 'pr', number: 42 }, - { provider: 'github', type: 'pr', number: 43 }, - { provider: 'github', type: 'issue', number: 9 } - ] - }) - store.setState({ worktreesByRepo: { repo1: [wt] } }) - await store.getState().updateWorktreeMeta(wt.id, { - linkedItems: wt.linkedItems?.filter((item) => item.number !== 43) - }) - expect(store.getState().worktreesByRepo.repo1[0]).toMatchObject({ - linkedPR: 42, - linkedIssue: 9 - }) - expect(getWorkspaceAttachments(store.getState().worktreesByRepo.repo1[0])).toHaveLength(2) - }) - it('routes folder links to the owning folder update instead of dropping them', async () => { const store = createTestStore() const folder = makeFolderWorkspace() diff --git a/src/renderer/src/store/slices/worktrees-pending-creation-state.test.ts b/src/renderer/src/store/slices/worktrees-pending-creation-state.test.ts index 963f046bc42..c10b9b594f7 100644 --- a/src/renderer/src/store/slices/worktrees-pending-creation-state.test.ts +++ b/src/renderer/src/store/slices/worktrees-pending-creation-state.test.ts @@ -59,17 +59,6 @@ describe('pending worktree creation state', () => { resetRemoteRuntimeMocks() }) - it('updatePendingWorktreeCreation skips the write when the patch changes nothing', () => { - const store = createTestStore() - store.getState().beginPendingWorktreeCreation(makePendingCreation('c1')) - const before = store.getState().pendingWorktreeCreations - - store.getState().updatePendingWorktreeCreation('c1', { phase: 'fetching' }) - - // Same map reference => no subscriber notification on a no-op progress event. - expect(store.getState().pendingWorktreeCreations).toBe(before) - }) - it('removePendingWorktreeCreation clears the active surface only when it points at the removed entry', () => { const store = createTestStore() store.getState().beginPendingWorktreeCreation(makePendingCreation('c1')) diff --git a/src/renderer/src/store/slices/worktrees-purge-terminal-state.test.ts b/src/renderer/src/store/slices/worktrees-purge-terminal-state.test.ts index d5bd9319083..4b854766c85 100644 --- a/src/renderer/src/store/slices/worktrees-purge-terminal-state.test.ts +++ b/src/renderer/src/store/slices/worktrees-purge-terminal-state.test.ts @@ -149,18 +149,6 @@ describe('purgeWorktreeTerminalState direct (design §4.4)', () => { expect(s.activeTabType).toBe('terminal') }) - it('is a no-op when the id list is empty', () => { - const store = createTestStore() - const before = { - 'repoA::/a/wt1': [{ id: 'tab-1', worktreeId: 'repoA::/a/wt1' }] - } - store.setState({ tabsByWorktree: before } as unknown as Partial) - - store.getState().purgeWorktreeTerminalState([]) - - expect(store.getState().tabsByWorktree).toBe(before) - }) - it('ignores the floating workspace sentinel while purging mixed real ids', () => { const store = createTestStore() const staleId = 'repoA::/a/wt1' @@ -250,65 +238,4 @@ describe('purgeWorktreeTerminalState direct (design §4.4)', () => { groupId: 'floating-group' }) }) - - it('is a no-op when only the floating workspace sentinel is passed', () => { - const store = createTestStore() - const tabsByWorktree = {} - const browserTabsByWorktree = { - [FLOATING_TERMINAL_WORKTREE_ID]: [{ id: 'floating-browser', url: 'https://orca.test' }] - } - const openFiles = [ - { - id: 'floating-file', - worktreeId: FLOATING_TERMINAL_WORKTREE_ID, - filePath: '/floating/note.md', - relativePath: 'note.md', - language: 'markdown', - isDirty: false, - isPreview: false, - mode: 'edit' as const - } - ] - const unifiedTabsByWorktree = { - [FLOATING_TERMINAL_WORKTREE_ID]: [ - { - id: 'floating-unified-tab', - type: 'editor', - worktreeId: FLOATING_TERMINAL_WORKTREE_ID, - fileId: 'floating-file' - } - ] - } - const groupsByWorktree = { - [FLOATING_TERMINAL_WORKTREE_ID]: [ - { - id: 'floating-group', - worktreeId: FLOATING_TERMINAL_WORKTREE_ID, - activeTabId: 'floating-unified-tab' - } - ] - } - const layoutByWorktree = { - [FLOATING_TERMINAL_WORKTREE_ID]: { type: 'leaf', groupId: 'floating-group' } - } - - store.setState({ - tabsByWorktree, - browserTabsByWorktree, - openFiles, - activeFileIdByWorktree: { [FLOATING_TERMINAL_WORKTREE_ID]: 'floating-file' }, - unifiedTabsByWorktree, - groupsByWorktree, - layoutByWorktree - } as unknown as Partial) - - store.getState().purgeWorktreeTerminalState([FLOATING_TERMINAL_WORKTREE_ID]) - - expect(store.getState().tabsByWorktree).toBe(tabsByWorktree) - expect(store.getState().browserTabsByWorktree).toBe(browserTabsByWorktree) - expect(store.getState().openFiles).toBe(openFiles) - expect(store.getState().unifiedTabsByWorktree).toBe(unifiedTabsByWorktree) - expect(store.getState().groupsByWorktree).toBe(groupsByWorktree) - expect(store.getState().layoutByWorktree).toBe(layoutByWorktree) - }) }) diff --git a/src/renderer/src/store/slices/worktrees-recent-stamp-switch-on.test.ts b/src/renderer/src/store/slices/worktrees-recent-stamp-switch-on.test.ts index 40a80251340..f93169808ba 100644 --- a/src/renderer/src/store/slices/worktrees-recent-stamp-switch-on.test.ts +++ b/src/renderer/src/store/slices/worktrees-recent-stamp-switch-on.test.ts @@ -62,25 +62,6 @@ describe('window-side Recent stamps with the sidebar-inputs switch on', () => { expect(persistedStamp()).toBe(false) }) - const persistedUnread = () => - mockApi.worktrees.updateMeta.mock.calls.some( - ([args]: [{ updates: Record }]) => 'isUnread' in args.updates - ) - - it('a bell or finish writes no stamp and leaves the unread flag to the host', () => { - const store = storeWith() - store.getState().markAgentAttentionUnread({ - workspaceId: wt.id, - subjectKey: null, - groupId: null, - reason: 'agent-completion' - }) - expect(store.getState().worktreesByRepo.repo1[0].isUnread).toBe(false) - expect(persistedUnread()).toBe(false) - expect(lastActivityAt(store)).toBe(5) - expect(persistedStamp()).toBe(false) - }) - it('a comment edit writes no stamp', async () => { const store = storeWith() await store.getState().updateWorktreeMeta(wt.id, { comment: 'note' }) diff --git a/src/renderer/src/store/slices/worktrees-remote-runtime-create.test.ts b/src/renderer/src/store/slices/worktrees-remote-runtime-create.test.ts index fdf0ddff178..abae4f43f02 100644 --- a/src/renderer/src/store/slices/worktrees-remote-runtime-create.test.ts +++ b/src/renderer/src/store/slices/worktrees-remote-runtime-create.test.ts @@ -1,5 +1,5 @@ import { setLocalRuntimeCapabilitiesForTests } from '../../runtime/local-runtime-capabilities' -import { toast } from 'sonner' +import 'sonner' import type { ExecutionHostId } from '../../../../shared/execution-host' import { beforeEach, describe, expect, it, vi } from 'vitest' import type { AppState } from '../types' @@ -36,25 +36,6 @@ vi.mock('@/components/worktree-base-fallback-notice', () => ({ beforeEach(resetWorktreeSliceModuleMemory) describe('worktree remote runtime mutations', () => { - it('shows a host warning about the push destination after creating the workspace', async () => { - const store = createRepoTestStore() - seedRepoHost(store, 'runtime:env-1') - runtimeEnvironmentCall.mockResolvedValue({ - id: 'create', - ok: true, - result: { - worktree: makeWorktree({ - id: 'repo1::/path/warning', - repoId: 'repo1', - path: '/path/warning' - }), - warning: 'Check the push destination.' - } - }) - await store.getState().createWorktree('repo1', 'warning', 'origin/main', 'skip') - expect(toast.warning).toHaveBeenCalledWith('Check the push destination.') - }) - it.each([false, true])( 'requires strict reuse support before creating on a remote host (%s)', async (supported) => { @@ -244,86 +225,6 @@ describe('worktree remote runtime mutations', () => { ]) }) - it('forwards generated-name provenance through paired-runtime create', async () => { - const store = createRepoTestStore() - const wt = makeWorktree({ id: 'repo1::/path/nautilus', repoId: 'repo1' }) - runtimeEnvironmentCall.mockResolvedValue({ - id: 'rpc-create', - ok: true, - result: { worktree: wt }, - _meta: { runtimeId: 'runtime-remote' } - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - worktreesByRepo: { repo1: [] } - } as Partial) - seedRepoHost(store, 'runtime:env-1') - const createWorktree = store.getState().createWorktree - const args: Parameters = ['repo1', 'nautilus'] - args[25] = { nameWasGenerated: true } - - await createWorktree(...args) - - expect(runtimeEnvironmentCall).toHaveBeenCalledWith( - expect.objectContaining({ - method: 'worktree.create', - params: expect.objectContaining({ nameWasGenerated: true }) - }) - ) - }) - - it('persists Jira item and source context through paired-runtime create', async () => { - const store = createRepoTestStore() - const wt = makeWorktree({ - id: 'repo1::/path/jira-link', - repoId: 'repo1', - path: '/path/jira-link' - }) - runtimeEnvironmentCall.mockResolvedValue({ - id: 'rpc-create', - ok: true, - result: { worktree: wt }, - _meta: { runtimeId: 'runtime-remote' } - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - worktreesByRepo: { repo1: [] } - } as Partial) - seedRepoHost(store, 'runtime:env-1') - const linkedWorkItem = { - provider: 'jira' as const, - type: 'issue' as const, - number: 0, - title: 'ORCA-123 Link Jira', - url: 'https://company.atlassian.net/browse/ORCA-123', - jiraIdentifier: 'ORCA-123' - } - const linkedTaskSourceContext = { - kind: 'task-source' as const, - provider: 'jira' as const, - projectId: 'project-1', - hostId: 'runtime:env-1' as const, - providerIdentity: { - provider: 'jira' as const, - siteId: 'site-1', - siteUrl: 'https://company.atlassian.net', - projectKey: 'ORCA' - } - } - const createWorktree = store.getState().createWorktree - const args: Parameters = ['repo1', 'jira-link'] - args[25] = { linkedWorkItem, linkedTaskSourceContext } - - await createWorktree(...args) - - expect(runtimeEnvironmentCall).toHaveBeenCalledWith( - expect.objectContaining({ - method: 'worktree.create', - params: expect.objectContaining({ linkedWorkItem, linkedTaskSourceContext }) - }) - ) - }) - it('blocks Jira linking when the paired runtime lacks durable metadata capability', async () => { const oldRuntimeStatus = createCompatibleRuntimeStatusResponse('runtime-old') if (oldRuntimeStatus.ok) { @@ -429,110 +330,6 @@ describe('worktree remote runtime mutations', () => { ) }) - it('passes task startup drafts only to the owning remote runtime', async () => { - const store = createRepoTestStore() - const wt = makeWorktree({ - id: 'repo1::/path/task-draft', - repoId: 'repo1', - path: '/path/task-draft' - }) - runtimeEnvironmentCall.mockResolvedValue({ - id: 'rpc-create', - ok: true, - result: { worktree: wt }, - _meta: { runtimeId: 'runtime-remote' } - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - worktreesByRepo: { repo1: [] } - } as Partial) - seedRepoHost(store, 'runtime:env-1') - const createWorktree = store.getState().createWorktree - const args: Parameters = ['repo1', 'task-draft', undefined, 'inherit'] - args[10] = 'codex' - args[25] = { startupDraft: 'https://github.com/stablyai/orca/issues/12' } - - await createWorktree(...args) - - expect(runtimeEnvironmentCall).toHaveBeenCalledWith( - expect.objectContaining({ - method: 'worktree.create', - params: expect.objectContaining({ - createdWithAgent: 'codex', - startupDraft: 'https://github.com/stablyai/orca/issues/12' - }) - }) - ) - expect(mockApi.worktrees.create).not.toHaveBeenCalled() - }) - - it('passes startup commands through local worktree creation IPC', async () => { - const store = createRepoTestStore() - const wt = makeWorktree({ - id: 'repo1::/path/local-agent-startup', - repoId: 'repo1', - path: '/path/local-agent-startup' - }) - mockApi.worktrees.create.mockResolvedValue({ - worktree: wt, - startupTerminal: { spawned: true, surface: 'visible' } - }) - store.setState({ - worktreesByRepo: { repo1: [] } - } as Partial) - - await store - .getState() - .createWorktree( - 'repo1', - 'local-agent-startup', - undefined, - 'skip', - undefined, - 'sidebar', - 'Launch local agent', - undefined, - undefined, - undefined, - 'claude', - undefined, - undefined, - undefined, - undefined, - undefined, - { - command: "claude --prefill 'summarize repo'", - env: { ORCA_AGENT_MODE: 'direct' }, - telemetry: { - agent_kind: 'claude-code', - launch_source: 'new_workspace_composer', - request_kind: 'new' - } - } - ) - - expect(mockApi.worktrees.create).toHaveBeenCalledWith( - expect.objectContaining({ - repoId: 'repo1', - name: 'local-agent-startup', - setupDecision: 'skip', - telemetrySource: 'sidebar', - displayName: 'Launch local agent', - createdWithAgent: 'claude', - startup: { - command: "claude --prefill 'summarize repo'", - env: { ORCA_AGENT_MODE: 'direct' }, - telemetry: { - agent_kind: 'claude-code', - launch_source: 'new_workspace_composer', - request_kind: 'new' - } - } - }) - ) - expect(runtimeEnvironmentCall).not.toHaveBeenCalled() - }) - it('retries a suffixed branchNameOverride when runtime create reports a branch conflict', async () => { const store = createRepoTestStore() const wt = makeWorktree({ diff --git a/src/renderer/src/store/slices/worktrees-remote-runtime-removal.test.ts b/src/renderer/src/store/slices/worktrees-remote-runtime-removal.test.ts index 0976ce88354..dc0d961770e 100644 --- a/src/renderer/src/store/slices/worktrees-remote-runtime-removal.test.ts +++ b/src/renderer/src/store/slices/worktrees-remote-runtime-removal.test.ts @@ -3,7 +3,7 @@ import { worktreeRemovalReplyTimeoutMs } from '../../../../shared/worktree/archi import type { AppState } from '../types' import type { RuntimeEnvironmentCallRequest } from '../../runtime/runtime-compatibility-test-fixture' import { makeWorktree } from './worktrees-slice-test-fixtures' -import { getDefaultSettings } from '../../../../shared/constants' +import '../../../../shared/constants' import { createTestStore, mockApi, @@ -36,140 +36,6 @@ describe('worktree remote runtime mutations', () => { resetRemoteRuntimeMocks() }) - it("removes worktrees through their owning server, the row's stamp", async () => { - const store = createTestStore() - const wt = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/path/wt1', - hostId: 'runtime:env-1', - runtimeOwnerEnvironmentId: 'env-1' - }) - runtimeEnvironmentCall.mockResolvedValue({ - id: 'rpc-rm', - ok: true, - result: { removed: true }, - _meta: { runtimeId: 'runtime-remote' } - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - worktreesByRepo: { repo1: [wt] } - } as Partial) - - const result = await store - .getState() - .removeWorktree({ id: wt.id, executionHostId: null }, false, { - snapshotPruneBatchId: 'batch-1' - }) - - expect(result).toEqual({ ok: true }) - expect(runtimeEnvironmentCall).toHaveBeenCalledWith({ - selector: 'env-1', - method: 'worktree.rm', - params: { - worktree: `id:${wt.id}`, - force: false, - allowUnverifiedPtyStop: false, - runHooks: true - }, - // Hooks run here, so the client must outlast the host's archive-hook budget (#19334). - timeoutMs: worktreeRemovalReplyTimeoutMs(true), - expectedEnvironmentPairingRevision: undefined, - expectedRuntimeId: undefined - }) - expect(mockApi.worktrees.remove).not.toHaveBeenCalled() - expect(mockApi.workspaceCleanup.recordRemovalSnapshotPrune).toHaveBeenCalledExactlyOnceWith({ - batchId: 'batch-1', - worktreeId: wt.id, - executionHostId: 'runtime:env-1' - }) - expect(store.getState().shutdownWorktreeTerminals).toHaveBeenCalledWith(wt.id, { - shutdownReason: 'remove-worktree', - backendOwnsPtyTeardown: true - }) - expect(store.getState().worktreesByRepo.repo1).toEqual([]) - }) - - it('never removes an unstamped worktree through the focused server', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - store.setState({ - settings: { ...getDefaultSettings('/home'), activeRuntimeEnvironmentId: 'env-1' }, - repos: [{ id: 'repo1', path: '/path', displayName: 'r', badgeColor: '#000', addedAt: 0 }], - worktreesByRepo: { repo1: [wt] } - }) - - await store.getState().removeWorktree({ id: wt.id, executionHostId: null }, false) - - expect(runtimeEnvironmentCall).not.toHaveBeenCalledWith( - expect.objectContaining({ method: 'worktree.rm' }) - ) - expect(mockApi.worktrees.remove).toHaveBeenCalled() - }) - - it('cleans up a preserved branch through the same host qualifier the removal used', async () => { - const store = createTestStore() - const wt = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/path/wt1', - hostId: 'runtime:env-1' - }) - runtimeEnvironmentCall - .mockResolvedValueOnce({ - id: 'rpc-rm', - ok: true, - result: { preservedBranch: { branchName: 'feature/x', head: 'saved-head' } }, - _meta: { runtimeId: 'runtime-remote' } - }) - .mockResolvedValueOnce({ - id: 'rpc-force-delete-branch', - ok: true, - result: { deleted: true }, - _meta: { runtimeId: 'runtime-remote' } - }) - store.setState({ - settings: { activeRuntimeEnvironmentId: 'env-1' } as never, - trustedOrcaHooks: { repo1: { all: { approvedAt: 1 } } }, - worktreesByRepo: { repo1: [wt] } - } as Partial) - - await store.getState().removeWorktree({ id: wt.id, executionHostId: 'runtime:env-1' }) - - const forceResult = await store - .getState() - .forceDeletePreservedBranch(wt.id, 'feature/x', 'saved-head', { - hostId: 'runtime:env-1', - runtimeEnvironmentId: 'env-1' - }) - - expect(forceResult).toEqual({ ok: true, deleted: true }) - expect(runtimeEnvironmentCall).toHaveBeenNthCalledWith(1, { - selector: 'env-1', - method: 'worktree.rm', - params: { - worktree: `id:${wt.id}`, - force: undefined, - allowUnverifiedPtyStop: false, - runHooks: true - }, - // Hooks run here, so the client must outlast the host's archive-hook budget (#19334). - timeoutMs: worktreeRemovalReplyTimeoutMs(true), - expectedEnvironmentPairingRevision: undefined, - expectedRuntimeId: undefined - }) - expect(runtimeEnvironmentCall).toHaveBeenNthCalledWith(2, { - selector: 'env-1', - method: 'worktree.forceDeleteBranch', - params: { - worktree: `id:${wt.id}`, - branchName: 'feature/x', - expectedHead: 'saved-head' - }, - timeoutMs: 15_000 - }) - }) - it('does not clean up a hidden same-id VM owned by another host', async () => { const store = createTestStore() const wt = makeWorktree({ @@ -647,37 +513,4 @@ describe('worktree remote runtime mutations', () => { expect(runtimeEnvironmentCall).not.toHaveBeenCalled() expect(store.getState().worktreesByRepo['repo-ssh']).toEqual([]) }) - - it('fails closed before deleting an exact worktree id owned by multiple hosts', async () => { - const store = createTestStore() - const worktreeId = 'repo-shared::/same/path' - store.setState({ - repos: [ - { id: 'repo-shared', path: '/local', displayName: 'Local', badgeColor: '#000', addedAt: 0 }, - { - id: 'repo-shared', - path: '/remote', - displayName: 'SSH', - badgeColor: '#111', - addedAt: 1, - connectionId: 'ssh-1' - } - ], - worktreesByRepo: { - 'repo-shared': [ - makeWorktree({ id: worktreeId, repoId: 'repo-shared', hostId: 'local' }), - makeWorktree({ id: worktreeId, repoId: 'repo-shared', hostId: 'ssh:ssh-1' }) - ] - } - } as Partial) - - const result = await store.getState().removeWorktree({ id: worktreeId, executionHostId: null }) - - expect(result).toEqual({ - ok: false, - error: 'Workspace identity is ambiguous across hosts. Refresh projects and try again.' - }) - expect(mockApi.worktrees.remove).not.toHaveBeenCalled() - expect(runtimeEnvironmentCall).not.toHaveBeenCalled() - }) }) diff --git a/src/renderer/src/store/slices/worktrees-removal-state-cleanup.test.ts b/src/renderer/src/store/slices/worktrees-removal-state-cleanup.test.ts index 6b193ac8748..f55a378c0df 100644 --- a/src/renderer/src/store/slices/worktrees-removal-state-cleanup.test.ts +++ b/src/renderer/src/store/slices/worktrees-removal-state-cleanup.test.ts @@ -6,8 +6,8 @@ import { hasDismissedHugeRepoWarning, markHugeRepoWarningDismissed } from '@/lib/source-control-huge-repo-warning-dismissals' -import { getHostedReviewLinkMutationGenerationForTests } from './worktrees' -import { makeLineage, makeTerminalTab, makeWorktree } from './worktrees-slice-test-fixtures' +import './worktrees' +import { makeWorktree } from './worktrees-slice-test-fixtures' import { createTestStore, mockApi, @@ -61,116 +61,6 @@ describe('removeWorktree state cleanup', () => { expect(hasDismissedHugeRepoWarning(replacementProbe)).toBe(false) }) - it('retains huge-repo warning state when explicit removal fails', async () => { - const store = createTestStore() - const retained = makeWorktree({ - id: 'repo1::/path/retained', - instanceId: 'retained-instance', - repoId: 'repo1', - path: '/path/retained' - }) - store.setState({ worktreesByRepo: { repo1: [retained] } } as Partial) - const retainedProbe = beginHugeRepoWarningProbe(retained) - expect(markHugeRepoWarningDismissed(retainedProbe)).toBe(true) - mockApi.worktrees.remove.mockRejectedValueOnce(new Error('delete failed')) - - const result = await store.getState().removeWorktree({ id: retained.id, executionHostId: null }) - - expect(result).toEqual({ ok: false, error: 'delete failed' }) - expect(hasDismissedHugeRepoWarning(retainedProbe)).toBe(true) - }) - - it('cleans up hosted review link mutation bookkeeping for the removed worktree', async () => { - const store = createTestStore() - const removed = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/path/wt1' - }) - const surviving = makeWorktree({ - id: 'repo1::/path/wt2', - repoId: 'repo1', - path: '/path/wt2' - }) - store.setState({ worktreesByRepo: { repo1: [removed, surviving] } } as Partial) - await store.getState().updateWorktreeMeta(removed.id, { linkedBitbucketPR: 101 }) - await store.getState().updateWorktreeMeta(surviving.id, { linkedAzureDevOpsPR: 202 }) - - expect(getHostedReviewLinkMutationGenerationForTests(removed.id)).toBeGreaterThan(0) - expect(getHostedReviewLinkMutationGenerationForTests(surviving.id)).toBeGreaterThan(0) - - await store.getState().removeWorktree({ id: removed.id, executionHostId: null }) - - expect(getHostedReviewLinkMutationGenerationForTests(removed.id)).toBe(0) - expect(getHostedReviewLinkMutationGenerationForTests(surviving.id)).toBeGreaterThan(0) - }) - - it('cleans up expandedPaneByTabId/canExpandPaneByTabId for removed worktree tabs', async () => { - const store = createTestStore() - const removed = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - const surviving = makeWorktree({ id: 'repo1::/path/wt2', repoId: 'repo1', path: '/path/wt2' }) - - store.setState({ - worktreesByRepo: { repo1: [removed, surviving] }, - tabsByWorktree: { - [removed.id]: [makeTerminalTab({ id: 'removed-tab', worktreeId: removed.id })], - [surviving.id]: [makeTerminalTab({ id: 'surviving-tab', worktreeId: surviving.id })] - }, - // Split panes write these even when false; removeWorktree used to strand them (only closeTab deleted them). - expandedPaneByTabId: { 'removed-tab': true, 'surviving-tab': false }, - canExpandPaneByTabId: { 'removed-tab': false, 'surviving-tab': true } - } as unknown as Partial) - - await store.getState().removeWorktree({ id: removed.id, executionHostId: null }) - - expect(store.getState().expandedPaneByTabId).toEqual({ 'surviving-tab': false }) - expect(store.getState().canExpandPaneByTabId).toEqual({ 'surviving-tab': true }) - }) - - it('cleans up automatic agent resume claims for removed worktree tabs', async () => { - const store = createTestStore() - const removed = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/path/wt1' - }) - const surviving = makeWorktree({ - id: 'repo1::/path/wt2', - repoId: 'repo1', - path: '/path/wt2' - }) - - store.setState({ - worktreesByRepo: { repo1: [removed, surviving] }, - tabsByWorktree: { - [removed.id]: [makeTerminalTab({ id: 'removed-tab', worktreeId: removed.id })], - [surviving.id]: [makeTerminalTab({ id: 'surviving-tab', worktreeId: surviving.id })] - }, - automaticAgentResumeClaimsByTabId: { - 'removed-tab': { - worktreeId: removed.id, - launchAgent: 'codex', - providerSession: { key: 'session_id', id: 'removed-session' } - }, - 'surviving-tab': { - worktreeId: surviving.id, - launchAgent: 'codex', - providerSession: { key: 'session_id', id: 'surviving-session' } - } - } - } as Partial) - - await store.getState().removeWorktree({ id: removed.id, executionHostId: null }) - - expect(store.getState().automaticAgentResumeClaimsByTabId).toEqual({ - 'surviving-tab': { - worktreeId: surviving.id, - launchAgent: 'codex', - providerSession: { key: 'session_id', id: 'surviving-session' } - } - }) - }) - it('purges the orphaned project that pointed at a destroyed runtime-owned SSH target', async () => { const store = createTestStore() const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) @@ -223,151 +113,6 @@ describe('removeWorktree state cleanup', () => { }) }) - it('cleans up editorDrafts for files in the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - openFiles: [ - { - id: 'file-1', - worktreeId: 'repo1::/path/wt1', - filePath: '/path/wt1/file.ts', - relativePath: 'file.ts', - language: 'typescript', - isDirty: true, - isPreview: false, - mode: 'edit' as const - } - ], - editorDrafts: { - 'file-1': 'draft content for wt1', - 'file-2': 'draft content for another worktree' - } - } as unknown as Partial) - - const result = await store - .getState() - .removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(result).toEqual({ ok: true }) - expect(store.getState().editorDrafts).toEqual({ - 'file-2': 'draft content for another worktree' - }) - }) - - it('cleans up the removed worktree lineage entry', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - const childLineage = makeLineage({ worktreeId: wt.id }) - const siblingLineage = makeLineage({ - worktreeId: 'repo1::/path/wt2', - worktreeInstanceId: 'sibling-instance' - }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - worktreeLineageById: { - [wt.id]: childLineage, - 'repo1::/path/wt2': siblingLineage - } - } as Partial) - - await store.getState().removeWorktree({ id: wt.id, executionHostId: null }) - - expect(store.getState().worktreeLineageById).toEqual({ - 'repo1::/path/wt2': siblingLineage - }) - }) - - it('cleans up markdownViewMode for files in the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - openFiles: [ - { - id: 'file-1', - worktreeId: 'repo1::/path/wt1', - filePath: '/path/wt1/readme.md', - relativePath: 'readme.md', - language: 'markdown', - isDirty: false, - isPreview: false, - mode: 'edit' as const - } - ], - markdownViewMode: { - 'file-1': 'rich' as const, - 'file-2': 'source' as const - } - } as unknown as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().markdownViewMode).toEqual({ 'file-2': 'source' }) - }) - - it('cleans up editorViewMode for files in the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - openFiles: [ - { - id: 'file-1', - worktreeId: 'repo1::/path/wt1', - filePath: '/path/wt1/app.ts', - relativePath: 'app.ts', - language: 'typescript', - isDirty: false, - isPreview: false, - mode: 'edit' as const - } - ], - editorViewMode: { - 'file-1': 'changes' as const, - 'file-2': 'changes' as const - } - } as unknown as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().editorViewMode).toEqual({ 'file-2': 'changes' }) - }) - - it('cleans up markdownFrontmatterVisible for files in the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - openFiles: [ - { - id: 'file-1', - worktreeId: 'repo1::/path/wt1', - filePath: '/path/wt1/readme.md', - relativePath: 'readme.md', - language: 'markdown', - isDirty: false, - isPreview: false, - mode: 'edit' as const - } - ], - markdownFrontmatterVisible: { - 'file-1': true, - 'file-2': true - } - } as unknown as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().markdownFrontmatterVisible).toEqual({ 'file-2': true }) - }) - it('cleans up markdownFrontmatterVisible for preview-only source files in the removed worktree', async () => { const store = createTestStore() const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) @@ -424,249 +169,4 @@ describe('removeWorktree state cleanup', () => { expect(worktreePresentWhenRecorded).toBe(true) expect(store.getState().worktreesByRepo.repo1).toEqual([]) }) - - it('cleans up expandedDirs for the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - expandedDirs: { - 'repo1::/path/wt1': new Set(['src', 'src/lib']), - 'repo1::/path/wt2': new Set(['test']) - } - } as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().expandedDirs).toEqual({ - 'repo1::/path/wt2': new Set(['test']) - }) - }) - - it('cleans up dotfile visibility for the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - showDotfilesByWorktree: { - 'repo1::/path/wt1': false, - 'repo1::/path/wt2': false - } - } as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().showDotfilesByWorktree).toEqual({ - 'repo1::/path/wt2': false - }) - }) - - it('cleans up activeTabIdByWorktree for the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeTabIdByWorktree: { - 'repo1::/path/wt1': 'tab-1', - 'repo1::/path/wt2': 'tab-2' - } - } as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().activeTabIdByWorktree).toEqual({ - 'repo1::/path/wt2': 'tab-2' - }) - }) - - it('cleans up tabBarOrderByWorktree for the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - tabBarOrderByWorktree: { - 'repo1::/path/wt1': ['tab-1', 'file-1', 'browser-1'], - 'repo1::/path/wt2': ['tab-2'] - } - } as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().tabBarOrderByWorktree).toEqual({ - 'repo1::/path/wt2': ['tab-2'] - }) - }) - - it('cleans up split-tab model state for the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - pendingReconnectTabByWorktree: { - 'repo1::/path/wt1': ['tab-1'], - 'repo1::/path/wt2': ['tab-2'] - }, - unifiedTabsByWorktree: { - 'repo1::/path/wt1': [{ id: 'tab-1', worktreeId: 'repo1::/path/wt1' }], - 'repo1::/path/wt2': [{ id: 'tab-2', worktreeId: 'repo1::/path/wt2' }] - }, - groupsByWorktree: { - 'repo1::/path/wt1': [ - { id: 'group-1', worktreeId: 'repo1::/path/wt1', activeTabId: 'tab-1' } - ], - 'repo1::/path/wt2': [ - { id: 'group-2', worktreeId: 'repo1::/path/wt2', activeTabId: 'tab-2' } - ] - }, - activeGroupIdByWorktree: { - 'repo1::/path/wt1': 'group-1', - 'repo1::/path/wt2': 'group-2' - }, - layoutByWorktree: { - 'repo1::/path/wt1': { type: 'leaf', groupId: 'group-1' }, - 'repo1::/path/wt2': { type: 'leaf', groupId: 'group-2' } - } - } as unknown as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().pendingReconnectTabByWorktree).toEqual({ - 'repo1::/path/wt2': ['tab-2'] - }) - expect(store.getState().unifiedTabsByWorktree).toEqual({ - 'repo1::/path/wt2': [{ id: 'tab-2', worktreeId: 'repo1::/path/wt2' }] - }) - expect(store.getState().groupsByWorktree).toEqual({ - 'repo1::/path/wt2': [{ id: 'group-2', worktreeId: 'repo1::/path/wt2', activeTabId: 'tab-2' }] - }) - expect(store.getState().activeGroupIdByWorktree).toEqual({ - 'repo1::/path/wt2': 'group-2' - }) - expect(store.getState().layoutByWorktree).toEqual({ - 'repo1::/path/wt2': { type: 'leaf', groupId: 'group-2' } - }) - }) - - it('cleans up git caches for the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - gitStatusByWorktree: { - 'repo1::/path/wt1': [{ path: 'a.ts' }], - 'repo1::/path/wt2': [{ path: 'b.ts' }] - }, - gitStatusHeadByWorktree: { - 'repo1::/path/wt1': 'head-1', - 'repo1::/path/wt2': 'head-2' - }, - gitBranchLineTotalByWorktree: { - 'repo1::/path/wt1': { added: 24, removed: 3, mergeBase: 'base-1' }, - 'repo1::/path/wt2': { added: 1, removed: 0, mergeBase: 'base-2' } - }, - gitIgnoredPathsByWorktree: { - 'repo1::/path/wt1': ['dist/'], - 'repo1::/path/wt2': ['coverage/'] - }, - gitConflictOperationByWorktree: { - 'repo1::/path/wt1': 'merge', - 'repo1::/path/wt2': 'unknown' - }, - trackedConflictPathsByWorktree: { - 'repo1::/path/wt1': { 'a.ts': 'both_modified' }, - 'repo1::/path/wt2': { 'b.ts': 'both_modified' } - }, - gitBranchChangesByWorktree: { - 'repo1::/path/wt1': [{ path: 'a.ts' }], - 'repo1::/path/wt2': [{ path: 'b.ts' }] - }, - gitBranchCompareSummaryByWorktree: { - 'repo1::/path/wt1': { status: 'ready' }, - 'repo1::/path/wt2': { status: 'loading' } - }, - gitBranchCompareRequestKeyByWorktree: { - 'repo1::/path/wt1': 'req-1', - 'repo1::/path/wt2': 'req-2' - }, - gitBranchCompareRequestStatusHeadByWorktree: { - 'repo1::/path/wt1': 'head-1', - 'repo1::/path/wt2': 'head-2' - } - } as unknown as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().gitStatusByWorktree).toEqual({ - 'repo1::/path/wt2': [{ path: 'b.ts' }] - }) - expect(store.getState().gitStatusHeadByWorktree).toEqual({ - 'repo1::/path/wt2': 'head-2' - }) - expect(store.getState().gitBranchLineTotalByWorktree).toEqual({ - 'repo1::/path/wt2': { added: 1, removed: 0, mergeBase: 'base-2' } - }) - expect(store.getState().gitIgnoredPathsByWorktree).toEqual({ - 'repo1::/path/wt2': ['coverage/'] - }) - expect(store.getState().gitConflictOperationByWorktree).toEqual({ - 'repo1::/path/wt2': 'unknown' - }) - expect(store.getState().trackedConflictPathsByWorktree).toEqual({ - 'repo1::/path/wt2': { 'b.ts': 'both_modified' } - }) - expect(store.getState().gitBranchChangesByWorktree).toEqual({ - 'repo1::/path/wt2': [{ path: 'b.ts' }] - }) - expect(store.getState().gitBranchCompareSummaryByWorktree).toEqual({ - 'repo1::/path/wt2': { status: 'loading' } - }) - expect(store.getState().gitBranchCompareRequestKeyByWorktree).toEqual({ - 'repo1::/path/wt2': 'req-2' - }) - expect(store.getState().gitBranchCompareRequestStatusHeadByWorktree).toEqual({ - 'repo1::/path/wt2': 'head-2' - }) - }) - - it('clears recentlyClosedBrowserTabsByWorktree for the removed worktree', async () => { - // Why: undo snapshots for a deleted worktree can never be restored, so removeWorktree clears the key (design §1.1). - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - store.setState({ - worktreesByRepo: { repo1: [wt] }, - recentlyClosedBrowserTabsByWorktree: { - 'repo1::/path/wt1': [{ workspace: { id: 'workspace-1' }, pages: [] }], - 'repo1::/path/wt2': [{ workspace: { id: 'workspace-2' }, pages: [] }] - } - } as unknown as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().recentlyClosedBrowserTabsByWorktree).toEqual({ - 'repo1::/path/wt2': [{ workspace: { id: 'workspace-2' }, pages: [] }] - }) - }) - - it('skips editorDrafts shallow copy when no files belong to the removed worktree', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - - const drafts = { 'file-2': 'some content' } - store.setState({ - worktreesByRepo: { repo1: [wt] }, - openFiles: [], - editorDrafts: drafts - } as Partial) - - await store.getState().removeWorktree({ id: 'repo1::/path/wt1', executionHostId: null }) - - expect(store.getState().editorDrafts).toBe(drafts) - }) }) diff --git a/src/renderer/src/store/slices/worktrees-terminal-pr-exact-observation.test.ts b/src/renderer/src/store/slices/worktrees-terminal-pr-exact-observation.test.ts index 559b35dfeae..c5c30a0a600 100644 --- a/src/renderer/src/store/slices/worktrees-terminal-pr-exact-observation.test.ts +++ b/src/renderer/src/store/slices/worktrees-terminal-pr-exact-observation.test.ts @@ -104,15 +104,6 @@ it.each([ } ) -it('does not attach a source rejected by the configured-remote exact lookup', async () => { - const { store, workspace, branchLookup } = setup() - exactLookup.mockResolvedValue(null) - store.getState().observeTerminalGitHubPullRequestLink(workspace.id, link) - await flush() - expect(getWorkspaceAttachments(store.getState().worktreesByRepo.repo[0])).toEqual([]) - expect(branchLookup).toHaveBeenCalledTimes(1) -}) - it.each([false, true])( 'checks a saved push branch and its late replacement=%s', async (replace) => { diff --git a/src/renderer/src/store/slices/worktrees-terminal-pr-url-linking.test.ts b/src/renderer/src/store/slices/worktrees-terminal-pr-url-linking.test.ts index c81255c596c..b968965d97c 100644 --- a/src/renderer/src/store/slices/worktrees-terminal-pr-url-linking.test.ts +++ b/src/renderer/src/store/slices/worktrees-terminal-pr-url-linking.test.ts @@ -53,136 +53,6 @@ describe('worktree remote runtime mutations', () => { resetRemoteRuntimeMocks() }) - it('waits for branch confirmation before linking a terminal PR URL for a known push target', async () => { - const store = createTestStore() - const readHostedReview = installReviewRead().mockResolvedValue(confirmedReview(42)) - const wt = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/worktrees/orca', - branch: 'refs/heads/feature/pr-link', - pushTarget: { - remoteName: 'origin', - branchName: 'feature/pr-link', - remoteUrl: 'https://github.com/acme/orca.git' - } - }) - store.setState({ - repos: [ - { id: 'repo1', path: '/repos/orca', displayName: 'orca', badgeColor: '#000', addedAt: 0 } - ], - worktreesByRepo: { repo1: [wt] } - }) - - store.getState().observeTerminalGitHubPullRequestLink(wt.id, { - url: 'https://github.com/acme/orca/pull/42', - slug: { owner: 'acme', repo: 'orca' }, - number: 42 - }) - - expect(store.getState().worktreesByRepo.repo1[0]?.linkedPR).toBeNull() - expect(mockApi.worktrees.resolvePrBase).not.toHaveBeenCalled() - expect(mockApi.worktrees.updateMeta).not.toHaveBeenCalled() - await vi.waitFor(() => expect(readHostedReview).toHaveBeenCalled()) - expect(readHostedReview).toHaveBeenCalledWith({ - repoPath: '/repos/orca', - branch: 'feature/pr-link', - force: true, - repoId: 'repo1', - active: true, - repoOwnerExecutionHostId: 'local', - currentHeadOid: wt.head, - linkedGitHubPR: null, - linkedGitLabMR: null, - linkedBitbucketPR: null, - linkedAzureDevOpsPR: null, - linkedGiteaPR: null - }) - for (let i = 0; i < 20; i++) { - await Promise.resolve() - } - - expect(mockApi.worktrees.updateMeta).toHaveBeenCalledWith({ - worktreeId: wt.id, - executionHostId: 'local', - updates: expect.objectContaining({ - linkedItems: [{ provider: 'github', type: 'pr', number: 42 }], - linkedPR: 42, - suppressedGitHubPR: null - }) - }) - }) - - it('ignores a terminal URL matching current GitHub PR suppression', () => { - const store = createTestStore() - const readHostedReview = installReviewRead().mockResolvedValue(confirmedReview(42)) - const wt = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/worktrees/orca', - branch: 'refs/heads/feature/pr-link', - linkedPR: null, - suppressedGitHubPR: 42 - }) - store.setState({ - repos: [ - { id: 'repo1', path: '/repos/orca', displayName: 'orca', badgeColor: '#000', addedAt: 0 } - ], - worktreesByRepo: { repo1: [wt] } - }) - - store.getState().observeTerminalGitHubPullRequestLink(wt.id, { - url: 'https://github.com/acme/orca/pull/42', - slug: { owner: 'acme', repo: 'orca' }, - number: 42 - }) - - expect(readHostedReview).not.toHaveBeenCalled() - expect(mockApi.worktrees.updateMeta).not.toHaveBeenCalled() - }) - - it('allows terminal observation of a different PR than the suppressed one', async () => { - const store = createTestStore() - installReviewRead().mockResolvedValue(confirmedReview(43)) - const wt = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/worktrees/orca', - branch: 'refs/heads/feature/pr-link', - linkedPR: null, - suppressedGitHubPR: 42, - pushTarget: { - remoteName: 'origin', - branchName: 'feature/pr-link' - } - }) - store.setState({ - repos: [ - { id: 'repo1', path: '/repos/orca', displayName: 'orca', badgeColor: '#000', addedAt: 0 } - ], - worktreesByRepo: { repo1: [wt] } - }) - - store.getState().observeTerminalGitHubPullRequestLink(wt.id, { - url: 'https://github.com/acme/orca/pull/43', - slug: { owner: 'acme', repo: 'orca' }, - number: 43 - }) - for (let i = 0; i < 20; i++) { - await Promise.resolve() - } - - expect(mockApi.worktrees.updateMeta).toHaveBeenCalledWith({ - worktreeId: wt.id, - executionHostId: 'local', - updates: expect.objectContaining({ - linkedItems: [{ provider: 'github', type: 'pr', number: 43 }], - linkedPR: 43, - suppressedGitHubPR: null - }) - }) - }) - it('rechecks GitHub PR suppression after branch confirmation resolves', async () => { const store = createTestStore() let resolveLookup: (value: HostedReviewInfo | null) => void = () => {} @@ -232,63 +102,6 @@ describe('worktree remote runtime mutations', () => { expect(mockApi.worktrees.updateMeta).not.toHaveBeenCalled() }) - it('waits for branch confirmation before linking a same-repo terminal PR URL', async () => { - const store = createTestStore() - const readHostedReview = installReviewRead().mockResolvedValue(confirmedReview(42)) - const wt = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/worktrees/orca', - branch: 'refs/heads/feature/pr-link', - pushTarget: { - remoteName: 'origin', - branchName: 'feature/pr-link' - } - }) - store.setState({ - repos: [ - { id: 'repo1', path: '/repos/orca', displayName: 'orca', badgeColor: '#000', addedAt: 0 } - ], - worktreesByRepo: { repo1: [wt] } - }) - - store.getState().observeTerminalGitHubPullRequestLink(wt.id, { - url: 'https://github.com/acme/orca/pull/42', - slug: { owner: 'acme', repo: 'orca' }, - number: 42 - }) - - expect(store.getState().worktreesByRepo.repo1[0]?.linkedPR).toBeNull() - await vi.waitFor(() => expect(readHostedReview).toHaveBeenCalled()) - expect(readHostedReview).toHaveBeenCalledWith({ - repoPath: '/repos/orca', - branch: 'feature/pr-link', - force: true, - repoId: 'repo1', - active: true, - repoOwnerExecutionHostId: 'local', - currentHeadOid: wt.head, - linkedGitHubPR: null, - linkedGitLabMR: null, - linkedBitbucketPR: null, - linkedAzureDevOpsPR: null, - linkedGiteaPR: null - }) - for (let i = 0; i < 20; i++) { - await Promise.resolve() - } - - expect(mockApi.worktrees.updateMeta).toHaveBeenCalledWith({ - worktreeId: wt.id, - executionHostId: 'local', - updates: expect.objectContaining({ - linkedItems: [{ provider: 'github', type: 'pr', number: 42 }], - linkedPR: 42, - suppressedGitHubPR: null - }) - }) - }) - it('preserves a manual primary while appending a PR confirmed after the selection changes', async () => { const store = createTestStore() let resolveLookup: (value: HostedReviewInfo | null) => void = () => {} diff --git a/src/renderer/src/store/slices/worktrees-terminal-reference-origins.test.ts b/src/renderer/src/store/slices/worktrees-terminal-reference-origins.test.ts index 9317695c46a..47d3cf514c6 100644 --- a/src/renderer/src/store/slices/worktrees-terminal-reference-origins.test.ts +++ b/src/renderer/src/store/slices/worktrees-terminal-reference-origins.test.ts @@ -203,43 +203,6 @@ describe('terminal reference evidence', () => { expect.objectContaining({ hostId: 'local', tabId: 'tab-1' }) ]) }) - it('confirms a number-only secondary attachment without requiring it to be the primary review', async () => { - const { store } = setup() - const workspace = store.getState().worktreesByRepo.repo1[0] - const readHostedReview = installReviewRead().mockResolvedValue({ - provider: 'github', - number: 42, - title: 'Secondary', - state: 'open', - url, - status: 'success', - mergeable: 'MERGEABLE', - updatedAt: '2026-01-01' - }) - store.setState({ - worktreesByRepo: { - repo1: [ - { - ...workspace, - linkedItems: [ - ...getWorkspaceAttachments(workspace), - { - provider: 'github', - type: 'pr', - number: 42 - } - ] - } - ] - } - }) - store.getState().observeTerminalGitHubPullRequestLink(worktreeId, link, context('tab-1')) - await flush() - expect(readHostedReview).toHaveBeenCalledWith(expect.objectContaining({ linkedGitHubPR: 42 })) - const current = store.getState().worktreesByRepo.repo1[0] - expect(current.linkedPR).toBe(7) - expect(getWorkspaceAttachments(current)[1].origins?.[0].tabId).toBe('tab-1') - }) it('rejects a different provider returned by owner-scoped branch confirmation', async () => { const { store } = setup() installReviewRead().mockResolvedValue({ @@ -256,17 +219,6 @@ describe('terminal reference evidence', () => { await flush() expect(getWorkspaceAttachments(store.getState().worktreesByRepo.repo1[0])).toHaveLength(1) }) - it('adds a second confirmed PR without changing which review is used for checks', async () => { - const { store } = setup() - store.getState().observeTerminalGitHubPullRequestLink(worktreeId, link, context('tab-1')) - await flush() - const workspace = store.getState().worktreesByRepo.repo1[0] - expect(workspace.linkedPR).toBe(7) - expect(getWorkspaceAttachments(workspace).map((item) => item.number)).toEqual([7, 42]) - expect(getWorkspaceAttachments(workspace)[1].origins).toEqual([ - expect.objectContaining({ kind: 'observed', tabId: 'tab-1', hostId: 'local' }) - ]) - }) it('records two terminals for one PR and keeps repeated evidence deduplicated', async () => { const { store, readHostedReview } = setup() for (const tabId of ['tab-1', 'tab-2', 'tab-2']) { @@ -280,28 +232,6 @@ describe('terminal reference evidence', () => { ).toEqual(['tab-1', 'tab-2']) expect(readHostedReview.mock.calls.filter(([args]) => args.active === true)).toHaveLength(1) }) - it('does not associate a same-number PR from a different repository', async () => { - const { store } = setup() - store - .getState() - .observeTerminalGitHubPullRequestLink( - worktreeId, - { ...link, url: 'https://github.com/other/repo/pull/42' }, - context('tab-1') - ) - await flush() - expect(getWorkspaceAttachments(store.getState().worktreesByRepo.repo1[0])).toHaveLength(1) - }) - it('does not write after a failed confirmation', async () => { - const { store, readHostedReview } = setup() - readHostedReview.mockRejectedValue(new Error('Offline')) - const warning = vi.spyOn(console, 'warn').mockImplementation(() => {}) - store.getState().observeTerminalGitHubPullRequestLink(worktreeId, link, context('tab-1')) - await flush() - expect(getWorkspaceAttachments(store.getState().worktreesByRepo.repo1[0])).toHaveLength(1) - expect(warning).toHaveBeenCalled() - warning.mockRestore() - }) it('ignores a stale PTY even when its caller supplies an execution host', async () => { const { store, readHostedReview } = setup() store.getState().observeTerminalGitHubPullRequestLink(worktreeId, link, { diff --git a/src/renderer/src/store/slices/worktrees-unread-state.test.ts b/src/renderer/src/store/slices/worktrees-unread-state.test.ts index a2b46e7059c..a2017a06b62 100644 --- a/src/renderer/src/store/slices/worktrees-unread-state.test.ts +++ b/src/renderer/src/store/slices/worktrees-unread-state.test.ts @@ -36,72 +36,6 @@ describe('worktree unread (show-until-interact)', () => { resetRemoteRuntimeMocks() }) - it('marking sets isUnread even when the worktree is active', async () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeWorktreeId: wt.id - } as Partial) - - store.getState().markAgentAttentionUnread({ - workspaceId: wt.id, - subjectKey: null, - groupId: null, - reason: 'agent-completion' - }) - - const after = store.getState().worktreesByRepo.repo1[0] - expect(after.isUnread).toBe(true) - expect(mockApi.worktrees.updateMeta).toHaveBeenCalledWith( - expect.objectContaining({ - worktreeId: wt.id, - updates: expect.objectContaining({ isUnread: true }) - }) - ) - }) - - it('routes multi-host project unread persistence by the worktree host (#10634)', () => { - const store = createTestStore() - const wt = makeWorktree({ - id: 'repo-shared::/home/user/wt', - repoId: 'repo-shared', - path: '/home/user/wt', - hostId: 'ssh:ssh-1' - }) - store.setState({ - repos: [ - { id: 'repo-shared', path: '/local', displayName: 'Local', badgeColor: '#000', addedAt: 0 }, - { - id: 'repo-shared', - path: '/home/user/repo', - displayName: 'SSH', - badgeColor: '#111', - addedAt: 1, - connectionId: 'ssh-1' - } - ], - worktreesByRepo: { 'repo-shared': [wt] } - } as Partial) - - expect(() => - store.getState().markAgentAttentionUnread({ - workspaceId: wt.id, - subjectKey: null, - groupId: null, - reason: 'agent-completion' - }) - ).not.toThrow() - - expect(store.getState().worktreesByRepo['repo-shared'][0].isUnread).toBe(true) - expect(mockApi.worktrees.updateMeta).toHaveBeenCalledWith( - expect.objectContaining({ - worktreeId: wt.id, - updates: expect.objectContaining({ isUnread: true }) - }) - ) - }) - it('keeps unread state local instead of throwing for genuinely ambiguous owners (#10634)', () => { const store = createTestStore() const worktreeId = 'repo-shared::/same/path' @@ -188,74 +122,6 @@ describe('worktree unread (show-until-interact)', () => { } }) - it('warns once per workspace rather than on every activity event (#10634)', () => { - // Why: activity bumps fire on every PTY event; an unbounded warn would flood the console. - const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}) - try { - const worktreeId = 'repo-spam::/same/path' - const store = createTestStore() - store.setState({ - settings: { activeRuntimeEnvironmentId: 'hub-c' } as never, - worktreesByRepo: { - 'repo-spam': [ - makeWorktree({ id: worktreeId, repoId: 'repo-spam', hostId: 'ssh:ssh-a' }), - makeWorktree({ id: worktreeId, repoId: 'repo-spam', hostId: 'ssh:ssh-b' }) - ] - } - } as Partial) - - const before = warn.mock.calls.length - for (let i = 0; i < 5; i++) { - store.getState().bumpWorktreeActivity(worktreeId) - } - - expect(warn.mock.calls.length - before).toBe(1) - } finally { - warn.mockRestore() - } - }) - - it('reading clears isUnread and persists the change', async () => { - const store = createTestStore() - const wt = makeWorktree({ - id: 'repo1::/path/wt1', - repoId: 'repo1', - path: '/path/wt1', - isUnread: true - }) - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeWorktreeId: wt.id - } as Partial) - - store - .getState() - .readOnScreenAttention({ workspaceIds: [wt.id], targets: [] }, { screenArrived: true }) - - const after = store.getState().worktreesByRepo.repo1[0] - expect(after.isUnread).toBe(false) - expect(mockApi.worktrees.updateMeta).toHaveBeenCalledWith( - expect.objectContaining({ - worktreeId: wt.id, - updates: { isUnread: false } - }) - ) - }) - - it('reading is a no-op when already cleared', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/path/wt1', repoId: 'repo1', path: '/path/wt1' }) - const initial = { repo1: [wt] } - store.setState({ worktreesByRepo: initial } as Partial) - - store - .getState() - .readOnScreenAttention({ workspaceIds: [wt.id], targets: [] }, { screenArrived: true }) - - expect(store.getState().worktreesByRepo).toBe(initial) - expect(mockApi.worktrees.updateMeta).not.toHaveBeenCalled() - }) - it('updates unread state for hidden detected worktrees', () => { const store = createTestStore() const hidden = makeWorktree({ diff --git a/src/renderer/src/store/slices/worktrees-workspace-selection-state.test.ts b/src/renderer/src/store/slices/worktrees-workspace-selection-state.test.ts index 2d0e0131bd3..6118f5b0983 100644 --- a/src/renderer/src/store/slices/worktrees-workspace-selection-state.test.ts +++ b/src/renderer/src/store/slices/worktrees-workspace-selection-state.test.ts @@ -4,14 +4,9 @@ import { registerPersistentWebview, unregisterPersistentWebview } from '../../components/browser-pane/host-guest/webview-registry' -import { folderWorkspaceKey, worktreeWorkspaceKey } from '../../../../shared/workspace-scope' -import { makeDetectedResult } from './worktrees-detected-listing-fixtures' -import { - createWebview, - makeFolderWorkspace, - makeLineage, - makeWorktree -} from './worktrees-slice-test-fixtures' +import '../../../../shared/workspace-scope' +import './worktrees-detected-listing-fixtures' +import { createWebview, makeWorktree } from './worktrees-slice-test-fixtures' import { createTestStore, mockApi, @@ -37,24 +32,6 @@ vi.mock('@/components/worktree-base-fallback-notice', () => ({ beforeEach(resetWorktreeSliceModuleMemory) -describe('folder workspace lookups', () => { - it('returns a stable synthetic worktree for repeated folder workspace lookups', () => { - const store = createTestStore() - const folderWorkspace = makeFolderWorkspace() - store.setState({ folderWorkspaces: [folderWorkspace] } as Partial) - - const first = store.getState().getKnownWorktreeById(folderWorkspaceKey(folderWorkspace.id)) - const second = store.getState().getKnownWorktreeById(folderWorkspaceKey(folderWorkspace.id)) - - expect(second).toBe(first) - expect(first).toMatchObject({ - id: folderWorkspaceKey(folderWorkspace.id), - displayName: folderWorkspace.name, - path: folderWorkspace.folderPath - }) - }) -}) - describe('setActiveWorktree focus handling', () => { beforeEach(() => { vi.clearAllMocks() @@ -112,661 +89,4 @@ describe('setActiveWorktree focus handling', () => { } } }) - - it('repairs a stale workspace key when reactivating the current worktree', () => { - const store = createTestStore() - const worktree = makeWorktree({ id: 'repo1::/path/current', repoId: 'repo1' }) - store.setState({ - worktreesByRepo: { repo1: [worktree] }, - activeWorktreeId: worktree.id, - activeWorkspaceKey: worktreeWorkspaceKey('repo1::/path/stale'), - activeWorkspaceExecutionHostId: null, - activeTabTypeByWorktree: { [worktree.id]: 'terminal' }, - rightSidebarExplorerView: 'files', - everActivatedWorktreeIds: new Set([worktree.id]) - }) - - store.getState().setActiveWorktree(worktree.id) - - expect(store.getState().activeWorkspaceKey).toBe(worktreeWorkspaceKey(worktree.id)) - }) -}) - -describe('markWorktreeVisited', () => { - it('stamps a host-qualified key when the worktree owner is known', () => { - const store = createTestStore() - const worktree = makeWorktree({ id: 'repo1::/hosted', repoId: 'repo1', hostId: 'ssh:builder' }) - store.setState({ worktreesByRepo: { repo1: [worktree] } } as Partial) - - store.getState().markWorktreeVisited(worktree.id, 1000) - - expect(store.getState().lastVisitedAtByWorktreeId).toEqual({ - [`ssh:builder|${worktree.id}`]: 1000 - }) - }) - - it('is monotonic: an older timestamp does not regress the stored value', () => { - const store = createTestStore() - store.getState().markWorktreeVisited('wt-1', 1000) - expect(store.getState().lastVisitedAtByWorktreeId['wt-1']).toBe(1000) - - store.getState().markWorktreeVisited('wt-1', 500) - expect(store.getState().lastVisitedAtByWorktreeId['wt-1']).toBe(1000) - - store.getState().markWorktreeVisited('wt-1', 1000) - expect(store.getState().lastVisitedAtByWorktreeId['wt-1']).toBe(1000) - - store.getState().markWorktreeVisited('wt-1', 2000) - expect(store.getState().lastVisitedAtByWorktreeId['wt-1']).toBe(2000) - }) - - it('seedActiveWorktreeLastVisitedIfMissing seeds only when missing', () => { - const store = createTestStore() - store.setState({ - activeWorktreeId: 'wt-1', - lastVisitedAtByWorktreeId: {} - } as Partial) - store.getState().seedActiveWorktreeLastVisitedIfMissing() - expect(store.getState().lastVisitedAtByWorktreeId['wt-1']).toBeTypeOf('number') - - const existing = store.getState().lastVisitedAtByWorktreeId['wt-1'] - store.getState().seedActiveWorktreeLastVisitedIfMissing() - expect(store.getState().lastVisitedAtByWorktreeId['wt-1']).toBe(existing) - }) - - it('pruneLastVisitedTimestamps drops entries for unknown worktree IDs within hydrated repos', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a' }) - store.setState({ - worktreesByRepo: { repo1: [wt] }, - lastVisitedAtByWorktreeId: { 'repo1::/a': 100, 'repo1::/gone': 200 } - } as Partial) - store.getState().pruneLastVisitedTimestamps() - expect(store.getState().lastVisitedAtByWorktreeId).toEqual({ 'repo1::/a': 100 }) - }) - - it('prunes host-qualified recency by host while retaining a same-id twin', () => { - const store = createTestStore() - const id = 'repo1::/shared' - const local = makeWorktree({ id, repoId: 'repo1', path: '/shared', hostId: 'local' }) - const ssh = makeWorktree({ id, repoId: 'repo1', path: '/shared', hostId: 'ssh:builder' }) - store.setState({ - worktreesByRepo: { repo1: [local, ssh] }, - lastVisitedAtByWorktreeId: { - [`local|${id}`]: 100, - [`ssh:builder|${id}`]: 200, - 'local|repo1::/gone': 300 - } - } as Partial) - - store.getState().pruneLastVisitedTimestamps() - - expect(store.getState().lastVisitedAtByWorktreeId).toEqual({ - [`local|${id}`]: 100, - [`ssh:builder|${id}`]: 200 - }) - }) - - it('pruneLastVisitedTimestamps preserves entries for not-yet-hydrated repos (e.g. SSH pre-connect)', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a' }) - store.setState({ - worktreesByRepo: { repo1: [wt] }, - lastVisitedAtByWorktreeId: { 'repo1::/a': 100, 'ssh-repo::/b': 200 } - } as Partial) - store.getState().pruneLastVisitedTimestamps() - expect(store.getState().lastVisitedAtByWorktreeId).toEqual({ - 'repo1::/a': 100, - 'ssh-repo::/b': 200 - }) - }) - - it('pruneLastVisitedTimestamps clears a stale activeWorktreeId gone from a hydrated repo', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a' }) - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeWorktreeId: 'repo1::/gone', - lastVisitedAtByWorktreeId: {} - } as Partial) - store.getState().pruneLastVisitedTimestamps() - expect(store.getState().activeWorktreeId).toBeNull() - }) - - it('pruneLastVisitedTimestamps keeps a live activeWorktreeId and defers unhydrated repos', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a' }) - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeWorktreeId: 'repo1::/a' - } as Partial) - store.getState().pruneLastVisitedTimestamps() - expect(store.getState().activeWorktreeId).toBe('repo1::/a') - - // A pointer into a not-yet-hydrated (e.g. SSH pre-connect) repo is deferred. - store.setState({ activeWorktreeId: 'ssh-repo::/b' } as Partial) - store.getState().pruneLastVisitedTimestamps() - expect(store.getState().activeWorktreeId).toBe('ssh-repo::/b') - }) - - it('pruneLastVisitedTimestamps defers when the detected list is non-authoritative', () => { - const store = createTestStore() - store.setState({ - worktreesByRepo: { repo1: [] }, - detectedWorktreesByRepo: { - repo1: makeDetectedResult('repo1', [], { - authoritative: false, - source: 'metadata-fallback' - }) - }, - lastVisitedAtByWorktreeId: { 'repo1::/hidden': 100 } - } as Partial) - - store.getState().pruneLastVisitedTimestamps() - - expect(store.getState().lastVisitedAtByWorktreeId).toEqual({ 'repo1::/hidden': 100 }) - }) - - it('pruneLastVisitedTimestamps defers an empty list with no detected record (unhydrated shape)', () => { - const store = createTestStore() - store.setState({ - worktreesByRepo: { repo1: [] }, - lastVisitedAtByWorktreeId: { 'repo1::/hidden': 100 } - } as Partial) - - store.getState().pruneLastVisitedTimestamps() - - // An empty list is the not-yet-hydrated shape, not an authoritative "no worktrees", - // so focus-recency is kept until an authoritative scan lands. - expect(store.getState().lastVisitedAtByWorktreeId).toEqual({ 'repo1::/hidden': 100 }) - }) - - it('pruneLastVisitedTimestamps clears the derived worktree-scoped active workspace key with a stale active worktree', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a' }) - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeWorktreeId: 'repo1::/gone', - activeWorkspaceKey: worktreeWorkspaceKey('repo1::/gone'), - activeWorkspaceExecutionHostId: 'local', - lastVisitedAtByWorktreeId: {} - } as Partial) - - store.getState().pruneLastVisitedTimestamps() - - expect(store.getState().activeWorktreeId).toBeNull() - // The derived workspace key would keep the phantom workspace selected, so it goes too. - expect(store.getState().activeWorkspaceKey).toBeNull() - expect(store.getState().activeWorkspaceExecutionHostId).toBeNull() - }) - - it('pruneLastVisitedTimestamps preserves a folder-scoped active workspace key when the active worktree is stale', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a' }) - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeWorktreeId: 'repo1::/gone', - activeWorkspaceKey: folderWorkspaceKey('folder-1'), - activeWorkspaceExecutionHostId: 'local', - lastVisitedAtByWorktreeId: {} - } as Partial) - - store.getState().pruneLastVisitedTimestamps() - - expect(store.getState().activeWorktreeId).toBeNull() - // Folder-scoped keys are never dropped here (matches the removal paths). - expect(store.getState().activeWorkspaceKey).toBe(folderWorkspaceKey('folder-1')) - expect(store.getState().activeWorkspaceExecutionHostId).toBeNull() - }) - - it('pruneLastVisitedTimestamps preserves an active workspace key pointing at a different live worktree', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a' }) - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeWorktreeId: 'repo1::/gone', - activeWorkspaceKey: worktreeWorkspaceKey('repo1::/a'), - lastVisitedAtByWorktreeId: {} - } as Partial) - - store.getState().pruneLastVisitedTimestamps() - - expect(store.getState().activeWorktreeId).toBeNull() - // Only the stale worktree's own derived key is dropped. - expect(store.getState().activeWorkspaceKey).toBe(worktreeWorkspaceKey('repo1::/a')) - }) - - it('pruneLastVisitedTimestamps clears a legacy unprefixed active workspace key for the stale worktree', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a' }) - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeWorktreeId: 'repo1::/gone', - // Sessions predating the `worktree:` prefix stored the bare id (see the purge path). - activeWorkspaceKey: 'repo1::/gone', - lastVisitedAtByWorktreeId: {} - } as unknown as Partial) - - store.getState().pruneLastVisitedTimestamps() - - expect(store.getState().activeWorktreeId).toBeNull() - expect(store.getState().activeWorkspaceKey).toBeNull() - }) -}) - -describe('setRenamingWorktreeId', () => { - it('sets and clears the workspace rename signal', () => { - const store = createTestStore() - - expect(store.getState().renamingWorktreeId).toBeNull() - - store.getState().setRenamingWorktreeId('repo1::/feature') - expect(store.getState().renamingWorktreeId).toEqual({ worktreeId: 'repo1::/feature' }) - - store.getState().setRenamingWorktreeId(null) - expect(store.getState().renamingWorktreeId).toBeNull() - }) -}) - -describe('setWorktreesPinnedAndReveal', () => { - beforeEach(() => { - vi.clearAllMocks() - resetRemoteRuntimeMocks() - }) - - it('pins the focused worktree and reveals it so the viewport follows it into the Pinned section', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a', isPinned: false }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeWorktreeId: wt.id, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([wt], true) - - expect(store.getState().worktreesByRepo.repo1[0].isPinned).toBe(true) - expect(reveal).toHaveBeenCalledWith(wt.id, { behavior: 'smooth', highlight: true }) - }) - - it('reveals on unpin of the focused worktree so the viewport follows it back to its status group', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a', isPinned: true }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [wt] }, - activeWorktreeId: wt.id, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([wt], false) - - expect(store.getState().worktreesByRepo.repo1[0].isPinned).toBe(false) - expect(reveal).toHaveBeenCalledWith(wt.id, { behavior: 'smooth', highlight: true }) - }) - - it('does not scroll when unpinning an unfocused worktree, but still unpins it', () => { - const store = createTestStore() - const focused = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a', isPinned: false }) - const pinned = makeWorktree({ id: 'repo1::/b', repoId: 'repo1', path: '/b', isPinned: true }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [focused, pinned] }, - activeWorktreeId: focused.id, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([pinned], false) - - // The row unpins, but the viewport stays put because it isn't focused. - expect(store.getState().worktreesByRepo.repo1[1].isPinned).toBe(false) - expect(reveal).not.toHaveBeenCalled() - }) - - it('does not scroll when pinning an unfocused worktree, but still pins it', () => { - const store = createTestStore() - const focused = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a', isPinned: false }) - const other = makeWorktree({ id: 'repo1::/b', repoId: 'repo1', path: '/b', isPinned: false }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [focused, other] }, - activeWorktreeId: focused.id, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([other], true) - - expect(store.getState().worktreesByRepo.repo1[1].isPinned).toBe(true) - expect(reveal).not.toHaveBeenCalled() - }) - - it("never scrolls to the focused card for its same-id twin's pin, and reveals the focused copy by host", () => { - const store = createTestStore() - const local = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a', hostId: 'local' }) - const ssh = makeWorktree({ ...local, hostId: 'ssh:box' }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [local, ssh] }, - activeWorktreeId: local.id, - activeWorkspaceExecutionHostId: 'local', - revealWorktreeInSidebar: reveal - }) - - store.getState().setWorktreesPinnedAndReveal([ssh], true) - expect(reveal).not.toHaveBeenCalled() - - store.getState().setWorktreesPinnedAndReveal([local], true) - expect(reveal).toHaveBeenCalledWith(local.id, { - behavior: 'smooth', - highlight: true, - executionHostId: 'local' - }) - }) - - it.each([ - { previousPinned: false, nextPinned: true }, - { previousPinned: true, nextPinned: false } - ])( - 'reveals the focused descendant when changing its unfocused ancestor from $previousPinned to $nextPinned', - ({ previousPinned, nextPinned }) => { - const store = createTestStore() - const parent = makeWorktree({ - id: 'repo1::/parent', - instanceId: 'parent-instance', - repoId: 'repo1', - isPinned: previousPinned - }) - const child = makeWorktree({ - id: 'repo1::/child', - instanceId: 'child-instance', - repoId: 'repo1' - }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [parent, child] }, - worktreeLineageById: { - [child.id]: makeLineage({ worktreeId: child.id, parentWorktreeId: parent.id }) - }, - activeWorktreeId: child.id, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([parent], nextPinned) - - expect(reveal).toHaveBeenCalledWith(child.id, { behavior: 'smooth', highlight: true }) - } - ) - - it("follows a server-proxied focused row selected by its server's runtime alias", () => { - const store = createTestStore() - const proxied = makeWorktree({ - id: 'repo1::/a', - repoId: 'repo1', - path: '/a', - hostId: 'ssh:box', - runtimeOwnerEnvironmentId: 'hub' - }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [proxied] }, - activeWorktreeId: proxied.id, - activeWorkspaceExecutionHostId: 'runtime:hub', - revealWorktreeInSidebar: reveal - }) - - store.getState().setWorktreesPinnedAndReveal([proxied], true) - - expect(reveal).toHaveBeenCalledWith(proxied.id, { - behavior: 'smooth', - highlight: true, - executionHostId: 'ssh:box' - }) - }) - - it("does not reveal the focused descendant for its ancestor's twin on another host", () => { - const store = createTestStore() - const parent = makeWorktree({ - id: 'repo1::/parent', - instanceId: 'parent-instance', - repoId: 'repo1', - hostId: 'local' - }) - const parentTwin = makeWorktree({ ...parent, hostId: 'ssh:box' }) - const child = makeWorktree({ - id: 'repo1::/child', - instanceId: 'child-instance', - repoId: 'repo1', - hostId: 'local' - }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [parent, parentTwin, child] }, - worktreeLineageById: { - [child.id]: makeLineage({ worktreeId: child.id, parentWorktreeId: parent.id }) - }, - activeWorktreeId: child.id, - activeWorkspaceExecutionHostId: 'local', - revealWorktreeInSidebar: reveal - }) - - store.getState().setWorktreesPinnedAndReveal([parentTwin], true) - - expect(reveal).not.toHaveBeenCalled() - }) - - it('reveals the focused descendant from embedded legacy lineage', () => { - const store = createTestStore() - const parent = makeWorktree({ - id: 'repo1::/parent', - instanceId: 'parent-instance', - repoId: 'repo1' - }) - const child = { - ...makeWorktree({ - id: 'repo1::/child', - instanceId: 'child-instance', - repoId: 'repo1' - }), - lineage: makeLineage({ worktreeId: 'repo1::/child', parentWorktreeId: parent.id }) - } - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [parent, child] }, - activeWorktreeId: child.id, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([parent], true) - - expect(reveal).toHaveBeenCalledWith(child.id, { behavior: 'smooth', highlight: true }) - }) - - it('does not reveal through cyclic lineage rejected by rendering', () => { - const store = createTestStore() - const first = makeWorktree({ - id: 'repo1::/first', - instanceId: 'first-instance', - repoId: 'repo1' - }) - const second = makeWorktree({ - id: 'repo1::/second', - instanceId: 'second-instance', - repoId: 'repo1' - }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [first, second] }, - worktreeLineageById: { - [first.id]: makeLineage({ - worktreeId: first.id, - worktreeInstanceId: first.instanceId, - parentWorktreeId: second.id, - parentWorktreeInstanceId: second.instanceId - }), - [second.id]: makeLineage({ - worktreeId: second.id, - worktreeInstanceId: second.instanceId, - parentWorktreeId: first.id, - parentWorktreeInstanceId: first.instanceId - }) - }, - activeWorktreeId: second.id, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([first], true) - - expect(reveal).not.toHaveBeenCalled() - }) - - it('does not reveal a focused descendant for duplicate pinned rows', () => { - const store = createTestStore() - const parent = makeWorktree({ - id: 'repo1::/parent', - instanceId: 'parent-instance', - repoId: 'repo1' - }) - const child = makeWorktree({ - id: 'repo1::/child', - instanceId: 'child-instance', - repoId: 'repo1' - }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [parent, child] }, - worktreeLineageById: { - [child.id]: makeLineage({ worktreeId: child.id, parentWorktreeId: parent.id }) - }, - activeWorktreeId: child.id, - settings: { ...store.getState().settings, showPinnedWorktreesInGroups: true }, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([parent], true) - - expect(reveal).not.toHaveBeenCalled() - }) - - it('does not reveal through stale lineage', () => { - const store = createTestStore() - const parent = makeWorktree({ - id: 'repo1::/parent', - instanceId: 'replacement-parent-instance', - repoId: 'repo1' - }) - const child = makeWorktree({ - id: 'repo1::/child', - instanceId: 'child-instance', - repoId: 'repo1' - }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [parent, child] }, - worktreeLineageById: { - [child.id]: makeLineage({ worktreeId: child.id, parentWorktreeId: parent.id }) - }, - activeWorktreeId: child.id, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([parent], true) - - expect(reveal).not.toHaveBeenCalled() - }) - - it('skips a no-op toggle without requesting a reveal', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a', isPinned: true }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [wt] }, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([wt], true) - - expect(reveal).not.toHaveBeenCalled() - expect(store.getState().worktreesByRepo.repo1[0].isPinned).toBe(true) - }) - - it('does nothing for an unknown worktree id', () => { - const store = createTestStore() - const wt = makeWorktree({ id: 'repo1::/a', repoId: 'repo1', path: '/a', isPinned: false }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [wt] }, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([{ id: 'repo1::/missing' }], true) - - expect(reveal).not.toHaveBeenCalled() - expect(store.getState().worktreesByRepo.repo1[0].isPinned).toBe(false) - }) - - it('does nothing for an empty id list', () => { - const store = createTestStore() - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [] }, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([], true) - - expect(reveal).not.toHaveBeenCalled() - }) - - it('pins several at once and reveals the focused row even when it is not first', () => { - const store = createTestStore() - const alreadyPinned = makeWorktree({ - id: 'repo1::/a', - repoId: 'repo1', - path: '/a', - isPinned: true - }) - const first = makeWorktree({ id: 'repo1::/b', repoId: 'repo1', path: '/b', isPinned: false }) - const focused = makeWorktree({ id: 'repo1::/c', repoId: 'repo1', path: '/c', isPinned: false }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [alreadyPinned, first, focused] }, - activeWorktreeId: focused.id, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([alreadyPinned, first, focused], true) - - // Only the focused row is revealed, not the first-changed one. - expect(reveal).toHaveBeenCalledTimes(1) - expect(reveal).toHaveBeenCalledWith(focused.id, { behavior: 'smooth', highlight: true }) - // Every targeted row is pinned, not just the revealed one; the already-pinned row is untouched. - expect(store.getState().worktreesByRepo.repo1[0].isPinned).toBe(true) - expect(store.getState().worktreesByRepo.repo1[1].isPinned).toBe(true) - expect(store.getState().worktreesByRepo.repo1[2].isPinned).toBe(true) - }) - - it('pins several at once without scrolling when none of them are focused', () => { - const store = createTestStore() - const first = makeWorktree({ id: 'repo1::/b', repoId: 'repo1', path: '/b', isPinned: false }) - const second = makeWorktree({ id: 'repo1::/c', repoId: 'repo1', path: '/c', isPinned: false }) - const elsewhere = makeWorktree({ - id: 'repo1::/z', - repoId: 'repo1', - path: '/z', - isPinned: false - }) - const reveal = vi.fn() - store.setState({ - worktreesByRepo: { repo1: [first, second, elsewhere] }, - activeWorktreeId: elsewhere.id, - revealWorktreeInSidebar: reveal - } as Partial) - - store.getState().setWorktreesPinnedAndReveal([first, second], true) - - expect(reveal).not.toHaveBeenCalled() - expect(store.getState().worktreesByRepo.repo1[0].isPinned).toBe(true) - expect(store.getState().worktreesByRepo.repo1[1].isPinned).toBe(true) - }) }) diff --git a/src/renderer/src/store/slices/worktrees/host-scoped-row-merges.test.ts b/src/renderer/src/store/slices/worktrees/host-scoped-row-merges.test.ts index 406f2b3913e..e091c83898e 100644 --- a/src/renderer/src/store/slices/worktrees/host-scoped-row-merges.test.ts +++ b/src/renderer/src/store/slices/worktrees/host-scoped-row-merges.test.ts @@ -104,21 +104,4 @@ describe('row writers touch only the copy on their own host', () => { expect(onLocal(WORKTREE_ID)).toMatchObject({ parentWorktreeId: null }) expect(onLocal(PARENT_ID)).toMatchObject({ childWorktreeIds: [] }) }) - - it("never appends a server's copy when only the local twin is listed", () => { - const store = createTestStore() - const { local } = seedTwins(store) - store.setState({ worktreesByRepo: { [REPO_ID]: [local] } }) - applyWorktreeLineageUpdate(store.setState, WORKTREE_ID, { - target: { kind: 'environment', environmentId: 'hub' }, - hostId: 'runtime:hub', - lineage: null, - updatedRemoteWorktree: makeWorktree({ - id: WORKTREE_ID, - repoId: REPO_ID, - displayName: 'server after lineage' - }) - }) - expect(store.getState().worktreesByRepo[REPO_ID]).toEqual([local]) - }) }) diff --git a/src/renderer/src/store/slices/worktrees/listing/detected-worktree-meta.test.ts b/src/renderer/src/store/slices/worktrees/listing/detected-worktree-meta.test.ts index dfeba420bda..38dbb7ffa94 100644 --- a/src/renderer/src/store/slices/worktrees/listing/detected-worktree-meta.test.ts +++ b/src/renderer/src/store/slices/worktrees/listing/detected-worktree-meta.test.ts @@ -1,12 +1,7 @@ import { describe, expect, it } from 'vitest' import { hostWorktreeTarget } from '../../../../../../shared/worktree/host-qualified-identity' -import type { FolderWorkspace } from '../../../../../../shared/folder-workspace-types' -import type { DetectedWorktreeListResult } from '../../../../../../shared/worktree/types' -import { - applyDetectedWorktreeUpdates, - folderWorkspaceMatchesHost, - findKnownWorktreeById -} from './detected-worktree-meta' + +import { findKnownWorktreeById } from './detected-worktree-meta' import { makeFolderWorkspace, makeProjectGroup @@ -115,85 +110,3 @@ describe('inherited folder consumer identity', () => { } ) }) - -describe('folderWorkspaceMatchesHost', () => { - it('prefers the host stamp, then the connection id, then local', () => { - type Row = Pick - const ssh: Row = { executionHostId: 'ssh:target-1', connectionId: null } - expect(folderWorkspaceMatchesHost(ssh, 'ssh:target-1')).toBe(true) - expect(folderWorkspaceMatchesHost(ssh, 'local')).toBe(false) - const stamped: Row = { executionHostId: 'runtime:env-1', connectionId: 'target-1' } - expect(folderWorkspaceMatchesHost(stamped, 'runtime:env-1')).toBe(true) - expect(folderWorkspaceMatchesHost(stamped, 'ssh:target-1')).toBe(false) - const legacy: Row = { executionHostId: undefined, connectionId: 'target-1' } - expect(folderWorkspaceMatchesHost(legacy, 'ssh:target-1')).toBe(true) - expect(folderWorkspaceMatchesHost({ connectionId: ' ' }, 'local')).toBe(true) - expect(folderWorkspaceMatchesHost({ connectionId: null }, 'local')).toBe(true) - }) -}) - -describe('applyDetectedWorktreeUpdates display-name provenance', () => { - it('projects pinning changes into detected rows', () => { - const detected = { - id: 'repo-1::/workspace/feature', - displayName: 'feature', - displayNameMode: 'automatic', - repoId: 'repo-1', - branch: 'refs/heads/feature' - } - const state = { - 'repo-1': { - repoId: 'repo-1', - authoritative: true, - source: 'git', - worktrees: [detected] - } - } as unknown as Record - - const fixed = applyDetectedWorktreeUpdates(state, detected.id, { - displayName: 'Agent workspace', - displayNameIsPinned: true - }) - expect(fixed['repo-1']?.worktrees[0]).toMatchObject({ - displayName: 'Agent workspace', - displayNameMode: 'fixed' - }) - - const automatic = applyDetectedWorktreeUpdates(state, detected.id, { - displayName: '', - displayNameIsPinned: false - }) - expect(automatic['repo-1']?.worktrees[0]).toMatchObject({ - displayName: 'feature', - displayNameMode: 'automatic' - }) - }) - - it('keeps text until the host resolves a detached fallback', () => { - const detached = { - id: 'repo-1::/workspace/feature', - displayName: 'Agent workspace', - displayNameMode: 'fixed' as const, - repoId: 'repo-1', - branch: '' - } - const detachedState = { - 'repo-1': { - repoId: 'repo-1', - authoritative: true, - source: 'git', - worktrees: [detached] - } - } as unknown as Record - - const automatic = applyDetectedWorktreeUpdates(detachedState, detached.id, { - displayName: '', - displayNameIsPinned: false - }) - - expect(automatic['repo-1']?.worktrees[0]).toMatchObject({ - displayName: 'Agent workspace', - displayNameMode: 'automatic' - }) - }) -}) diff --git a/src/renderer/src/store/slices/worktrees/listing/stale-listing-purges-created-worktree.test.ts b/src/renderer/src/store/slices/worktrees/listing/stale-listing-purges-created-worktree.test.ts index ea04a6c2b77..4a6d3fa7663 100644 --- a/src/renderer/src/store/slices/worktrees/listing/stale-listing-purges-created-worktree.test.ts +++ b/src/renderer/src/store/slices/worktrees/listing/stale-listing-purges-created-worktree.test.ts @@ -196,7 +196,6 @@ describe('a listing versioned before an applied create', () => { const HOST = 'host-epoch-1' const before = { epoch: HOST, sequence: 6 } const createReply = { epoch: HOST, sequence: 7 } - const after = { epoch: HOST, sequence: 8 } beforeEach(() => { resetStructuredAgentLaunchPersistenceForTests() @@ -231,31 +230,6 @@ describe('a listing versioned before an applied create', () => { expect(state.detectedWorktreesByRepo[REPO_ID]!.worktrees.map((w) => w.id)).toContain(CREATED_ID) }) - it('reports a listing whose repo owner went away as not-current, even when also older', () => { - const store = createTestStore() - seedWithAppliedCreate(store) - store.setState({ repos: [] }) - const existingRow = store.getState().worktreesByRepo[REPO_ID]![0]! - - expect(applyListing(store, [existingRow], before)).toBe('not-current') - - expect(store.getState().unifiedTabsByWorktree[CREATED_ID]).toHaveLength(2) - }) - - it('a later listing that includes the worktree applies and advances the version', () => { - const store = createTestStore() - seedWithAppliedCreate(store) - const rows = store.getState().worktreesByRepo[REPO_ID]! - - expect(applyListing(store, [...rows], after)).toBe('applied') - - const state = store.getState() - expect(state.activeWorktreeId).toBe(CREATED_ID) - expect( - state.worktreeCatalogVersionByRepoHost[worktreeCatalogVersionKey(REPO_ID, 'local')] - ).toEqual(after) - }) - it('a listing from a restarted host is a new catalog, not an older one', () => { const store = createTestStore() seedWithAppliedCreate(store) diff --git a/src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership-repo-host.test.ts b/src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership-repo-host.test.ts deleted file mode 100644 index efe31c7f664..00000000000 --- a/src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership-repo-host.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { getDefaultSettings } from '../../../../../../shared/constants' -import { repoHostId } from './worktree-host-ownership' - -const focused = { ...getDefaultSettings('/home/me'), activeRuntimeEnvironmentId: 'env-1' } - -describe('repoHostId', () => { - it('stamps a listing for a repo with no row as this app, never the focused server', () => { - expect(repoHostId({ repos: [], settings: focused, runtimeEnvironments: [] }, 'repo-1')).toBe( - 'local' - ) - }) - - it('keeps the host the caller names for a repo with no row', () => { - expect( - repoHostId({ repos: [], settings: focused, runtimeEnvironments: [] }, 'repo-1', 'ssh:box') - ).toBe('ssh:box') - }) -}) diff --git a/src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership-unstamped.test.ts b/src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership-unstamped.test.ts deleted file mode 100644 index 777c6788aed..00000000000 --- a/src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership-unstamped.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { worktreeMatchesHost } from './worktree-host-ownership' - -describe('worktreeMatchesHost unstamped non-local rows', () => { - it.each([ - ['stamped SSH row', { hostId: 'ssh:t' as const }, 'ssh:t' as const, true, true], - ['stamped server row', { runtimeOwnerEnvironmentId: 'e' }, 'runtime:e' as const, true, true], - ['unstamped row claimed by local', {}, 'local' as const, true, true], - ['unstamped row claimed by SSH', {}, 'ssh:t' as const, true, true], - ['unstamped row claimed by a server', {}, 'runtime:e' as const, true, true], - ['unstamped row refused by SSH', {}, 'ssh:t' as const, false, false], - ['unstamped row, no hint, SSH', {}, 'ssh:t' as const, undefined, false], - ['unstamped row, no hint, local', {}, 'local' as const, undefined, true] - ])('%s', (_name, row, hostId, unhostedWorktreesMatchHost, matches) => { - expect(worktreeMatchesHost(row, hostId, { unhostedWorktreesMatchHost })).toBe(matches) - }) -}) diff --git a/src/renderer/src/store/slices/worktrees/listing/worktree-sort-order-patch.test.ts b/src/renderer/src/store/slices/worktrees/listing/worktree-sort-order-patch.test.ts deleted file mode 100644 index 621f638ac79..00000000000 --- a/src/renderer/src/store/slices/worktrees/listing/worktree-sort-order-patch.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { readPublishedSortOrders } from './worktree-sort-order-patch' - -describe('readPublishedSortOrders', () => { - it('reads valid entries and treats an absent field as an older host', () => { - expect(readPublishedSortOrders([{ worktreeId: 'repo::/a', sortOrder: 5 }])).toEqual([ - { worktreeId: 'repo::/a', sortOrder: 5 } - ]) - expect(readPublishedSortOrders(undefined)).toBeNull() - }) - - it('falls back to a refetch when any entry is malformed', () => { - expect( - readPublishedSortOrders([ - { worktreeId: 'repo::/a', sortOrder: 5 }, - { worktreeId: 'repo::/b', sortOrder: Number.NaN } - ]) - ).toBeNull() - expect(readPublishedSortOrders([{ worktreeId: 7, sortOrder: 5 }])).toBeNull() - }) -}) diff --git a/src/renderer/src/store/slices/worktrees/metadata/worktree-meta-persist.test.ts b/src/renderer/src/store/slices/worktrees/metadata/worktree-meta-persist.test.ts index 6b21f60afd4..98f04426c5b 100644 --- a/src/renderer/src/store/slices/worktrees/metadata/worktree-meta-persist.test.ts +++ b/src/renderer/src/store/slices/worktrees/metadata/worktree-meta-persist.test.ts @@ -37,25 +37,6 @@ describe('persistWorktreeMeta GitHub PR suppression compatibility', () => { vi.unstubAllGlobals() }) - it.each([ - { linkedPR: 42 }, - { linkedPR: null }, - { linkedGitLabMR: 7 }, - { linkedGitLabMR: null }, - { linkedIssue: 9 }, - { linkedIssue: null } - ])('does not require a collection capability for scalar writes: %j', async (updates) => { - mocks.assertCapability.mockRejectedValue(new Error('collection unsupported')) - await persistWorktreeMeta(mocks.target, 'repo::/feature', updates) - expect(mocks.assertCapability).not.toHaveBeenCalled() - expect(mocks.callRuntimeRpc).toHaveBeenCalledWith( - mocks.target, - 'worktree.set', - { worktree: 'id:repo::/feature', ...updates }, - { timeoutMs: 15_000 } - ) - }) - it.each([true, false])( 'keeps review selection exclusive when collection support is %s', async (supportsCollections) => { @@ -109,33 +90,6 @@ describe('persistWorktreeMeta GitHub PR suppression compatibility', () => { expect(mocks.callRuntimeRpc).not.toHaveBeenCalled() }) - it('sends the complete collection to a capable host', async () => { - const linkedItems = [ - { provider: 'github', type: 'pr', number: 42 }, - { provider: 'gitlab', type: 'mr', number: 7 } - ] as const - await persistWorktreeMeta(mocks.target, 'repo::/feature', { - linkedItems: [...linkedItems] - }) - expect(mocks.callRuntimeRpc).toHaveBeenCalledWith( - mocks.target, - 'worktree.set', - { worktree: 'id:repo::/feature', linkedItems }, - { timeoutMs: 15_000 } - ) - }) - - it('sends positive suppression writes to capable hosts', async () => { - await persistWorktreeMeta(mocks.target, 'repo::/feature', { suppressedGitHubPR: 42 }) - - expect(mocks.callRuntimeRpc).toHaveBeenCalledWith( - mocks.target, - 'worktree.set', - { worktree: 'id:repo::/feature', suppressedGitHubPR: 42 }, - { timeoutMs: 15_000 } - ) - }) - it('strips null clears for older hosts while preserving compatible updates', async () => { mocks.supportsCapability.mockResolvedValue(false) @@ -158,40 +112,6 @@ describe('persistWorktreeMeta GitHub PR suppression compatibility', () => { { timeoutMs: 15_000 } ) }) - - it('keeps null clears for capable hosts', async () => { - await persistWorktreeMeta(mocks.target, 'repo::/feature', { - linkedPR: 42, - suppressedGitHubPR: null - }) - - expect(mocks.callRuntimeRpc).toHaveBeenCalledWith( - mocks.target, - 'worktree.set', - { worktree: 'id:repo::/feature', linkedPR: 42, suppressedGitHubPR: null }, - { timeoutMs: 15_000 } - ) - }) - - it('preserves host-owned suppression writes without a paired-runtime capability check', async () => { - const updateMeta = vi.fn().mockResolvedValue(undefined) - mocks.target = { kind: 'local' } - vi.stubGlobal('window', { api: { worktrees: { updateMeta } } }) - - await persistWorktreeMeta( - mocks.target, - 'repo::/feature', - { suppressedGitHubPR: 42 }, - 'ssh:build-box' - ) - - expect(updateMeta).toHaveBeenCalledWith({ - worktreeId: 'repo::/feature', - executionHostId: 'ssh:build-box', - updates: { suppressedGitHubPR: 42 } - }) - expect(mocks.assertCapability).not.toHaveBeenCalled() - }) it('gates and forwards the atomic collection snapshot', async () => { await persistWorktreeMeta(mocks.target, 'repo::/feature', { linkedItems: [], diff --git a/src/renderer/src/store/slices/worktrees/session/worktree-identity-rename-main-agreement.test.ts b/src/renderer/src/store/slices/worktrees/session/worktree-identity-rename-main-agreement.test.ts deleted file mode 100644 index 335b9ff15dc..00000000000 --- a/src/renderer/src/store/slices/worktrees/session/worktree-identity-rename-main-agreement.test.ts +++ /dev/null @@ -1,160 +0,0 @@ -// Main migrates sessions before window handles rename; its next save must agree with identityRenamed, never carry the rekey alone. Only compiled-off local first-work-folder-rename emits this event; paired events omit rename. -import { describe, expect, it, vi } from 'vitest' -import type * as AgentStatusModule from '@/lib/agent-status' -import { getDefaultPersistedState } from '../../../../../../shared/constants' -import type { WorkspaceSessionState } from '../../../../../../shared/workspace-session-state-types' -import { - addWorkspace, - emptySession, - leaf -} from '../../../../../../shared/workspace-layout/workspace-layout-session.test-fixture' -import { applyLayoutTransition } from '../../../../../../shared/workspace-layout/workspace-layout-transitions' -import { migrateWorktreeIdentity } from '../../../../../../main/persistence/tracking-repos/worktree-identity-migration' -import { loadWorkspaceLayoutWithoutReport } from '../../../../../../shared/workspace-layout/workspace-layout-load' -import { nameBasedLoadContext } from '../../../../../../shared/workspace-layout/workspace-layout-minted-ids' - -vi.mock('sonner', () => ({ toast: { info: vi.fn(), success: vi.fn(), error: vi.fn() } })) -vi.mock('@/lib/agent-status', async (importOriginal) => { - const actual = await importOriginal() - return { ...actual, detectAgentStatusFromTitle: vi.fn().mockReturnValue(null) } -}) - -// @ts-expect-error -- mocked browser preload API -globalThis.window = { api: {} } - -import { buildWorkspaceSessionPayload } from '@/lib/workspace-session' -import { createTestStore, makeWorktree } from '../../store-test-helpers' - -const REPO = 'repo1' -const OLD = `${REPO}::/path/cunner` -const NEW = `${REPO}::/path/spinner` -const OTHER = `${REPO}::/path/other` -const EDITOR_FILE = '/path/cunner/src/App.tsx' - -function sessionBeforeRename(): WorkspaceSessionState { - const session = addWorkspace(emptySession(), OLD, [ - { - id: 'group-left', - tabs: [ - { id: 'tab-split', leaves: [[leaf(1), 'pty-1'], [leaf(2)]] }, - { id: 'tab-two', leaves: [[leaf(3), 'pty-3']] }, - { id: EDITOR_FILE, kind: 'editor' } - ] - }, - { - id: 'group-right', - tabs: [ - { id: 'tab-right', leaves: [[leaf(4)]] }, - { id: 'browser-1', kind: 'browser' } - ] - } - ]) - session.openFilesByWorktree = { - [OLD]: [ - { - filePath: EDITOR_FILE, - relativePath: 'src/App.tsx', - worktreeId: OLD, - language: 'typescript' - } - ] - } - session.activeFileIdByWorktree = { [OLD]: EDITOR_FILE } - session.browserTabsByWorktree = { - [OLD]: [ - { - id: 'browser-1', - worktreeId: OLD, - url: 'https://example.com', - title: 'Example', - loading: false, - faviconUrl: null, - canGoBack: false, - canGoForward: false, - loadError: null, - createdAt: 3 - } - ] - } - addWorkspace(session, OTHER, [ - { id: 'group-other', tabs: [{ id: 'tab-other', leaves: [[leaf(5)]] }] } - ]) - session.activeRepoId = REPO - session.activeWorktreeId = OLD - return session -} - -/** Main's layout model of a stored partition, loaded as main loads it. */ -function layoutModelOf(session: WorkspaceSessionState) { - return loadWorkspaceLayoutWithoutReport('local', session, nameBasedLoadContext()).layout -} - -function hydratedWindow(session: WorkspaceSessionState) { - const store = createTestStore() - store.setState({ - repos: [{ id: REPO, path: '/path', displayName: 'Repo 1', badgeColor: '#000', addedAt: 0 }], - worktreesByRepo: { - [REPO]: [OLD, OTHER].map((id) => - makeWorktree({ id, repoId: REPO, path: id.slice(`${REPO}::`.length) }) - ) - } - }) - store.getState().hydrateWorkspaceSession(session) - store.getState().hydrateTabsSession(session) - store.getState().hydrateEditorSession(session) - store.getState().hydrateBrowserSession(session) - store.setState({ workspaceSessionReady: true }) - store.getState().setHydrationSucceeded(true) - return store -} - -describe('worktree identity rename: window and main agree on the layout', () => { - it("leaves main's migrated layout model as it is when the window saves its rekey", () => { - const store = hydratedWindow(sessionBeforeRename()) - // What main holds: the window's last save before the rename. - const held = buildWorkspaceSessionPayload(store.getState()) - const before = layoutModelOf(held) - expect(Object.keys(before.workspaces).sort()).toEqual([OLD, OTHER].sort()) - - // Main: Store.migrateWorktreeIdentity, before it sends the rename event. - const persisted = { - ...getDefaultPersistedState('/home'), - workspaceSession: structuredClone(held) - } - expect(migrateWorktreeIdentity(persisted, OLD, NEW)).toBe(true) - const mainModel = layoutModelOf(persisted.workspaceSession) - - // Window: the rename event re-keys its slices; the worktree list then catches up. - store.getState().migrateWorktreeIdentity(OLD, NEW) - store.setState({ - worktreesByRepo: { - [REPO]: [NEW, OTHER].map((id) => - makeWorktree({ id, repoId: REPO, path: id.slice(`${REPO}::`.length) }) - ) - } - }) - const windowModel = layoutModelOf(buildWorkspaceSessionPayload(store.getState())) - - expect(Object.keys(mainModel.workspaces).sort()).toEqual([NEW, OTHER].sort()) - const renamed = windowModel.workspaces[NEW]! - expect(renamed.tabs.length).toBe(5) - expect(renamed.groups?.length).toBe(2) - expect(renamed.editorFiles?.length).toBe(1) - expect(renamed.browserTabs?.length).toBe(1) - expect({ workspaces: windowModel.workspaces, records: windowModel.records }).toEqual({ - workspaces: mainModel.workspaces, - records: mainModel.records - }) - - const transitioned = applyLayoutTransition(before, { - type: 'identityRenamed', - from: OLD, - to: NEW - }) - expect(transitioned.ok).toBe(true) - if (transitioned.ok) { - expect(transitioned.model.workspaces).toEqual(mainModel.workspaces) - expect(transitioned.model.records).toEqual(mainModel.records) - } - }) -}) diff --git a/src/renderer/src/store/slices/worktrees/teardown/host-qualified-removal-refusal.test.ts b/src/renderer/src/store/slices/worktrees/teardown/host-qualified-removal-refusal.test.ts index d5cf488cab0..6e0795ecf5a 100644 --- a/src/renderer/src/store/slices/worktrees/teardown/host-qualified-removal-refusal.test.ts +++ b/src/renderer/src/store/slices/worktrees/teardown/host-qualified-removal-refusal.test.ts @@ -1,41 +1,12 @@ import { describe, expect, it, vi } from 'vitest' import { beginHostQualifiedRemoval } from './host-qualified-worktree-removal' -import { folderWorkspaceKey } from '../../../../../../shared/workspace-scope' +import '../../../../../../shared/workspace-scope' const WORKTREE_ID = 'repo1::/shared/workspace/path' /** Early refusal bypasses removal’s clearing catch; clear optimistic deleting state here or its spinner outlives the 10-second toast. */ // Confirmed hosts resolve directly; unresolved-owner refusal is reached only by hostless callers. describe('beginHostQualifiedRemoval refusals clear the delete state', () => { - function makeGet(clearWorktreeDeleteState: ReturnType) { - // Minimal store surface: no worktrees, so no route can resolve for MISSING_HOST. - return () => - ({ - clearWorktreeDeleteState, - allWorktrees: () => [], - worktreesByRepo: {}, - repos: [], - detectedWorktreesByRepo: {}, - settings: {}, - sshConnectionStates: new Map(), - sshTargetLabels: new Map(), - workspaceCleanupScan: null - }) as never - } - - it('clears when no route resolves and no host was confirmed', () => { - const clearWorktreeDeleteState = vi.fn() - const start = beginHostQualifiedRemoval( - makeGet(clearWorktreeDeleteState), - WORKTREE_ID, - null, - false - ) - - expect(start.ok).toBe(false) - expect(clearWorktreeDeleteState).toHaveBeenCalledWith(WORKTREE_ID) - }) - // Use populated unresolved-owner states too; an empty fixture proves clear but not real-user reachability. function makeRoutedGet( clearWorktreeDeleteState: ReturnType, @@ -80,23 +51,4 @@ describe('beginHostQualifiedRemoval refusals clear the delete state', () => { }) expect(clearWorktreeDeleteState).not.toHaveBeenCalled() }) - - // Folder workspaces fail closed on a stale id by design, so a row whose folder record is gone - // refuses instead of routing. - it('clears when a folder workspace id no longer has an owner', () => { - const clearWorktreeDeleteState = vi.fn() - const folderId = folderWorkspaceKey('fw-removed') - const start = beginHostQualifiedRemoval( - makeRoutedGet(clearWorktreeDeleteState, { - repos: [{ id: 'repo1', connectionId: null, executionHostId: 'local' }], - folderWorkspaces: [] - }), - folderId, - null, - false - ) - - expect(start.ok).toBe(false) - expect(clearWorktreeDeleteState).toHaveBeenCalledWith(folderId) - }) })