🐛 fix(vscode): 接管时把会话文件里的发送方路径重写为本机路径

Claude-Session: https://claude.ai/code/session_011cEyL6k351U2BzX1Qmygph
This commit is contained in:
cruldra committed 2026-08-26 19:04:09 +08:00
1 parent 07c40897e2
commit 71a91fe7ec
7 files changed
+151 -10

No files matched your search

+41
View File
@@ -106,4 +106,45 @@ describe('pack → unpack → install', () => {
await installHandoffBundle(staging, manifest, { projectsRoot, codexRoot: tempDir('receiver-codex-'), workspaceProjectsDir })
expect(existsSync(path.join(workspaceProjectsDir, `${IMPL}.jsonl`))).toBe(true)
})
it('带 worktreePath + pathRewrite:装机文件里的发送方路径全部改写成接收方路径', async () => {
const WORKTREE_FROM = '/Users/chw/wt/x'
const WORKTREE_TO = '/home/me/wt/x'
const roots = senderRoots()
// sender 会话文件里嵌入发送方的 worktree 路径(plain / file:// 两种形式)
const wt = path.join(roots.projectsRoot, '-Users-chw-wt-x')
writeFileSync(path.join(wt, `${IMPL}.jsonl`), `{"cwd":"${WORKTREE_FROM}"}\n{"cwd":"file://${WORKTREE_FROM}"}\n`)
writeFileSync(path.join(wt, IMPL, 'subagents', 'agent-1.jsonl'), `{"cwd":"${WORKTREE_FROM}"}\n`)
const day = path.join(roots.codexRoot, '2026', '08', '26')
writeFileSync(path.join(day, `rollout-2026-08-26T01-02-03-${REVIEW}.jsonl`), `{"cwd":"${WORKTREE_FROM}"}\n{"cwd":"file://${WORKTREE_FROM}"}\n`)
const staging = tempDir('staging-')
const manifest = await stageHandoffBundle({
issueNumber: 7,
from: 'chw',
worktreePath: WORKTREE_FROM,
sessions: { implementSessionId: IMPL, reviewSessionId: REVIEW },
profiles: {},
}, staging, roots)
expect(manifest.worktreePath).toBe(WORKTREE_FROM)
const projectsRoot = tempDir('receiver-projects-')
const codexRoot = tempDir('receiver-codex-')
const worktreeProjectsDir = path.join(projectsRoot, '-home-me-wt-x')
await installHandoffBundle(staging, manifest, {
projectsRoot,
codexRoot,
workspaceProjectsDir: path.join(projectsRoot, '-home-me-proj'),
worktreeProjectsDir,
pathRewrite: { from: WORKTREE_FROM, to: WORKTREE_TO },
})
const installedJsonl = readFileSync(path.join(worktreeProjectsDir, `${IMPL}.jsonl`), 'utf8')
const installedSubagent = readFileSync(path.join(worktreeProjectsDir, IMPL, 'subagents', 'agent-1.jsonl'), 'utf8')
const installedRollout = readFileSync(path.join(codexRoot, manifest.codex[0].relPath), 'utf8')
for (const content of [installedJsonl, installedSubagent, installedRollout]) {
expect(content).toContain(WORKTREE_TO)
expect(content).not.toContain(WORKTREE_FROM)
}
})
})