🐛 fix(vscode): worktreePath 消费侧统一解析 ~/绝对/相对,修复带 ~ 的存量工单与绝对路径 worktree 误判

新增 resolveWorktreePath(stored, workspaceRoot) 三态合一解析:开头 ~ 展开为 home、
已是绝对原样、相对拼到 workspaceRoot。替换全部消费点,原先「判 isAbsolute 再 join」
不认 ~、issueLoader 算 worktreeExists 更是裸 join 连绝对路径都拼坏。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-24 03:01:08 +08:00
co-authored by Claude Opus 4.7
parent 9a69aeed48
commit 5e7a3d20d9
4 changed files with 28 additions and 23 deletions
+6 -10
View File
@@ -12,7 +12,7 @@ import { watchForNewCodexSession } from '../../cc/codexSessionWatcher'
import { getBrainstormContinuePrompt, getImplementPlanPrompt } from '../../cc/prompts'
import { projectsDirFor, watchForNewSession } from '../../cc/sessionWatcher'
import { detectRepo } from '../../git/remote'
import { createWorktree } from '../../git/worktree'
import { createWorktree, resolveWorktreePath } from '../../git/worktree'
import { logger } from '../../logging/logger'
import { getSettings } from '../../settings/store'
import { webhookCoordinator } from '../../webhook/coordinator'
@@ -257,7 +257,7 @@ export async function handleResumeReviewSession(panel: KanbanWebviewPanel, sessi
void window.showErrorMessage(`审查会话无法恢复 #${issueNumber}worktree 路径未记录`)
return
}
const worktreeAbs = path.join(workspaceRoot, relCwd)
const worktreeAbs = resolveWorktreePath(relCwd, workspaceRoot)
if (!fs.existsSync(worktreeAbs)) {
void window.showErrorMessage(`审查会话无法恢复 #${issueNumber}worktree 不存在 ${worktreeAbs}`)
return
@@ -335,9 +335,7 @@ export async function triggerAutoReviewTab(panel: KanbanWebviewPanel, opts: {
let effectiveCwd = opts.workspaceRoot
let cwdFallback = false
if (opts.worktreePath) {
const abs = path.isAbsolute(opts.worktreePath)
? opts.worktreePath
: path.join(opts.workspaceRoot, opts.worktreePath)
const abs = resolveWorktreePath(opts.worktreePath, opts.workspaceRoot)
if (fs.existsSync(abs))
effectiveCwd = abs
else
@@ -1400,10 +1398,8 @@ export async function startConflictResolution(panel: KanbanWebviewPanel, opts: {
const settings = getSettings(panel.context)
const devBranch = settings.devBranch || 'main'
// worktreePath 在 state JSON 里通常是 workspace-relative解析为绝对路径。
const worktreeAbs = path.isAbsolute(worktreePath)
? worktreePath
: path.join(workspaceRoot, worktreePath)
// worktreePath 可能是相对、绝对或带 ~ 的存量值;统一解析为绝对路径。
const worktreeAbs = resolveWorktreePath(worktreePath, workspaceRoot)
// worktree 是实施阶段建好的,按理一直存在;被清理过算异常,拒绝继续。
if (!fs.existsSync(worktreeAbs)) {
@@ -1626,7 +1622,7 @@ export function resolveTestProfilePath(_panel: KanbanWebviewPanel, testProfilePa
*/
async function resolveTestSessionCwd(workspaceRoot: string, worktreePathRel?: string): Promise<string> {
if (worktreePathRel) {
const abs = path.join(workspaceRoot, worktreePathRel)
const abs = resolveWorktreePath(worktreePathRel, workspaceRoot)
try {
await fsp.stat(abs)
return abs