Files
orca/src/main/git/worktree-move.test.ts
T
OrcaWinandOrcaWin 4687e90a16 [comment audit] Continue main-process comment cleanup (#32946)
* [comment audit] Shorten daemon, hook, and emulator comments [skip ci]

* [comment audit] Shorten VM, conversation, SQLite, and theme-import comments [skip ci]

* [comment audit] Tighten Git execution and source-control comment contracts [skip ci]

* [comment audit] Clarify repository probes and maintenance comments [skip ci]

* [comment audit] Shorten status, diff-cache, and checkout comments [skip ci]

* [comment audit] Clarify worktree lifecycle and WSL routing comments [skip ci]

* [comment audit] Shorten forge identity and review-refresh comments [skip ci]

* [comment audit] Tighten hosted-review client comment contracts [skip ci]

* [comment audit] Clarify GitLab compatibility and review comments [skip ci]

* [comment audit] Tighten hook ownership and watchdog rationale [skip ci]

* [comment audit] Condense host and integration compatibility comments [skip ci]

* [comment audit] Clarify IPC authority and remote-routing rationale [skip ci]

* [comment audit] Finalize file-import and containment comment cleanup

* [comment audit] Fix stale Jira type imports blocking full CI

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-23 16:27:37 -07:00

79 lines
2.7 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
const {
gitExecFileAsyncMock,
gitExecFileSyncMock,
translateWslOutputPathsMock,
detectSparseCheckoutMock
} = vi.hoisted(() => ({
gitExecFileAsyncMock: vi.fn(),
gitExecFileSyncMock: vi.fn(),
translateWslOutputPathsMock: vi.fn((output: string) => output),
detectSparseCheckoutMock: vi.fn()
}))
vi.mock('./runner', () => ({
gitExecFileAsync: gitExecFileAsyncMock,
gitExecFileSync: gitExecFileSyncMock,
translateWslOutputPaths: translateWslOutputPathsMock
}))
vi.mock('./worktree-sparse-state', () => ({
detectSparseCheckout: detectSparseCheckoutMock,
resolveGitCommonDir: vi.fn()
}))
import { moveWorktree } from './worktree'
import { registerWorktreeSuiteHooks } from './worktree-test-harness'
import {
__getSparseCheckoutStateCacheSizeForTests,
detectSparseCheckoutCached
} from './worktree-sparse-checkout-cache'
registerWorktreeSuiteHooks()
describe('moveWorktree', () => {
beforeEach(() => {
gitExecFileAsyncMock.mockReset()
})
it('runs `git worktree move` from the repo with old and new paths', async () => {
gitExecFileAsyncMock.mockResolvedValueOnce({ stdout: '', stderr: '' })
await moveWorktree('/repo', '/ws/cunner', '/ws/worktree-creation-spinner')
expect(gitExecFileAsyncMock).toHaveBeenCalledWith(
['worktree', 'move', '/ws/cunner', '/ws/worktree-creation-spinner'],
{ cwd: '/repo' }
)
})
it('propagates git failures so the caller can fall back', async () => {
gitExecFileAsyncMock.mockRejectedValueOnce(new Error('fatal: destination exists'))
await expect(moveWorktree('/repo', '/ws/cunner', '/ws/taken')).rejects.toThrow(
'destination exists'
)
})
it('drops cached sparse-checkout state for both the old and new path', async () => {
detectSparseCheckoutMock.mockResolvedValue(true)
await detectSparseCheckoutCached('/repo', '/ws/cunner')
await detectSparseCheckoutCached('/repo', '/ws/worktree-creation-spinner')
expect(__getSparseCheckoutStateCacheSizeForTests()).toBe(2)
gitExecFileAsyncMock.mockResolvedValueOnce({ stdout: '', stderr: '' })
await moveWorktree('/repo', '/ws/cunner', '/ws/worktree-creation-spinner')
expect(__getSparseCheckoutStateCacheSizeForTests()).toBe(0)
})
it('drops cached sparse-checkout state for both paths even when the move fails', async () => {
detectSparseCheckoutMock.mockResolvedValue(true)
await detectSparseCheckoutCached('/repo', '/ws/cunner')
await detectSparseCheckoutCached('/repo', '/ws/taken')
gitExecFileAsyncMock.mockRejectedValueOnce(new Error('fatal: destination exists'))
await expect(moveWorktree('/repo', '/ws/cunner', '/ws/taken')).rejects.toThrow()
expect(__getSparseCheckoutStateCacheSizeForTests()).toBe(0)
})
})