🐛 fix(vscode): resume 会话用 resolveWorktreePath 避免误判 worktree 已清理

This commit is contained in:
cruldra committed 2026-07-16 01:51:08 +08:00
1 parent aff4ee2758
commit b45257a38d
2 files changed
+25 -4

No files matched your search

+21 -1
View File
@@ -3,7 +3,27 @@ import { existsSync, mkdtempSync, rmSync } from 'node:fs'
import * as os from 'node:os'
import * as path from 'node:path'
import { describe, expect, it } from 'vitest'
import { findProcessesUsingWorktree } from './worktree'
import { findProcessesUsingWorktree, resolveWorktreePath } from './worktree'
describe('resolveWorktreePath', () => {
const workspaceRoot = '/workspace/project'
it('绝对路径原样返回', () => {
const abs = '/home/user/Sources/worktree/repo/session-foo'
expect(resolveWorktreePath(abs, workspaceRoot)).toBe(abs)
})
it('~/... 展开为 home 下路径', () => {
const home = os.homedir()
expect(resolveWorktreePath('~/Sources/worktree/repo/session-foo', workspaceRoot))
.toBe(path.join(home, 'Sources/worktree/repo/session-foo'))
})
it('相对路径拼到 workspaceRoot 下', () => {
expect(resolveWorktreePath('.claude/worktrees/abc123', workspaceRoot))
.toBe(path.join(workspaceRoot, '.claude/worktrees/abc123'))
})
})
// 检测靠扫 /proc,只有 Linux 有;别的平台整组跳过(函数本身也会返回空)。
describe.runIf(existsSync('/proc'))('findProcessesUsingWorktree', () => {