fix: address review findings (#2695)
This commit is contained in:
@@ -3,7 +3,8 @@ import {
|
||||
WORKTREE_ID_SEPARATOR,
|
||||
getRepoIdFromWorktreeId,
|
||||
getWorktreePathBasenameFromId,
|
||||
splitWorktreeId
|
||||
splitWorktreeId,
|
||||
splitWorktreeIdForFilesystem
|
||||
} from './worktree-id'
|
||||
|
||||
describe('WORKTREE_ID_SEPARATOR', () => {
|
||||
@@ -73,6 +74,23 @@ describe('splitWorktreeId', () => {
|
||||
it('splits on the first separator when the path itself contains "::"', () => {
|
||||
expect(splitWorktreeId('repo::a::b')).toEqual({ repoId: 'repo', worktreePath: 'a::b' })
|
||||
})
|
||||
|
||||
it('preserves folder workspace instance suffixes in the literal parsed path', () => {
|
||||
expect(
|
||||
splitWorktreeId('repo::/folder::workspace:123e4567-e89b-12d3-a456-426614174000')
|
||||
).toEqual({
|
||||
repoId: 'repo',
|
||||
worktreePath: '/folder::workspace:123e4567-e89b-12d3-a456-426614174000'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('splitWorktreeIdForFilesystem', () => {
|
||||
it('strips folder workspace instance suffixes from the parsed path', () => {
|
||||
expect(
|
||||
splitWorktreeIdForFilesystem('repo::/folder::workspace:123e4567-e89b-12d3-a456-426614174000')
|
||||
).toEqual({ repoId: 'repo', worktreePath: '/folder' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('getWorktreePathBasenameFromId', () => {
|
||||
@@ -88,6 +106,14 @@ describe('getWorktreePathBasenameFromId', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('returns the real folder basename for folder workspace instance ids', () => {
|
||||
expect(
|
||||
getWorktreePathBasenameFromId(
|
||||
'repo-123::/abs/project::workspace:123e4567-e89b-12d3-a456-426614174000'
|
||||
)
|
||||
).toBe('project')
|
||||
})
|
||||
|
||||
it('returns null when no worktree path is available', () => {
|
||||
expect(getWorktreePathBasenameFromId('repo-123')).toBeNull()
|
||||
expect(getWorktreePathBasenameFromId('repo-123::')).toBeNull()
|
||||
|
||||
@@ -7,6 +7,11 @@ export type ParsedWorktreeId = {
|
||||
worktreePath: string
|
||||
}
|
||||
|
||||
export const FOLDER_WORKSPACE_INSTANCE_SEPARATOR = '::workspace:'
|
||||
const FOLDER_WORKSPACE_INSTANCE_SUFFIX = new RegExp(
|
||||
`${FOLDER_WORKSPACE_INSTANCE_SEPARATOR.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[0-9a-f-]{36}$`
|
||||
)
|
||||
|
||||
export function getRepoIdFromWorktreeId(worktreeId: string): string {
|
||||
const separatorIdx = worktreeId.indexOf(WORKTREE_ID_SEPARATOR)
|
||||
return separatorIdx === -1 ? worktreeId : worktreeId.slice(0, separatorIdx)
|
||||
@@ -23,8 +28,22 @@ export function splitWorktreeId(worktreeId: string): ParsedWorktreeId | null {
|
||||
}
|
||||
}
|
||||
|
||||
export function getWorktreePathBasenameFromId(worktreeId: string): string | null {
|
||||
export function splitWorktreeIdForFilesystem(worktreeId: string): ParsedWorktreeId | null {
|
||||
const parsed = splitWorktreeId(worktreeId)
|
||||
if (!parsed) {
|
||||
return null
|
||||
}
|
||||
return {
|
||||
repoId: parsed.repoId,
|
||||
// Why: folder projects can have multiple workspace sessions backed by the
|
||||
// same directory. Their IDs carry a UUID suffix, but filesystem callers
|
||||
// still need the real folder path as cwd/root.
|
||||
worktreePath: parsed.worktreePath.replace(FOLDER_WORKSPACE_INSTANCE_SUFFIX, '')
|
||||
}
|
||||
}
|
||||
|
||||
export function getWorktreePathBasenameFromId(worktreeId: string): string | null {
|
||||
const parsed = splitWorktreeIdForFilesystem(worktreeId)
|
||||
const normalizedPath = parsed?.worktreePath.trim().replace(/[\\/]+$/g, '') ?? ''
|
||||
if (!normalizedPath) {
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user