38 lines
1.8 KiB
TypeScript
38 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { planResumeCwd, resumeTerminalName } from './resumeTarget'
|
|
|
|
const ROOT = '/repo'
|
|
const WT = '/repo-worktrees/feature-x'
|
|
|
|
describe('resumeTerminalName', () => {
|
|
it('实施会话 → issue-N-实施', () => {
|
|
expect(resumeTerminalName('implement', 'abcdef1234', 398)).toBe('issue-398-实施')
|
|
})
|
|
it('规划会话 → issue-N-规划', () => {
|
|
expect(resumeTerminalName('brainstorm', 'abcdef1234', 398)).toBe('issue-398-规划')
|
|
})
|
|
it('没有工单号 → 按会话 id 前 8 位命名', () => {
|
|
expect(resumeTerminalName('implement', 'abcdef1234', undefined)).toBe('Claude · abcdef12')
|
|
})
|
|
})
|
|
|
|
describe('planResumeCwd', () => {
|
|
it('规划会话永远在工作区根目录', () => {
|
|
expect(planResumeCwd({ kind: 'brainstorm', workspaceRoot: ROOT, worktreeAbs: WT, worktreeExists: true }))
|
|
.toEqual({ cwd: ROOT, worktreeMissing: false })
|
|
})
|
|
it('实施会话 worktree 在 → cwd 用 worktree', () => {
|
|
expect(planResumeCwd({ kind: 'implement', workspaceRoot: ROOT, worktreeAbs: WT, worktreeExists: true }))
|
|
.toEqual({ cwd: WT, worktreeMissing: false })
|
|
})
|
|
it('实施会话 worktree 记了但磁盘上没了 → 退回根目录并标记缺失', () => {
|
|
expect(planResumeCwd({ kind: 'implement', workspaceRoot: ROOT, worktreeAbs: WT, worktreeExists: false }))
|
|
.toEqual({ cwd: ROOT, worktreeMissing: true })
|
|
})
|
|
it('实施会话工单里没记 worktreePath(PR 合并后清掉)→ 同样标记缺失,角色不变', () => {
|
|
expect(planResumeCwd({ kind: 'implement', workspaceRoot: ROOT, worktreeAbs: undefined, worktreeExists: false }))
|
|
.toEqual({ cwd: ROOT, worktreeMissing: true })
|
|
expect(resumeTerminalName('implement', 'abcdef1234', 398)).toBe('issue-398-实施')
|
|
})
|
|
})
|