Files
orca/src/main/git/base-ref-search-selector.test.ts
T
Neilandkino 1de3aa405f Fix truncated Unicode branch names in base ref search
Preserve complete branch selectors when Git truncates or disambiguates short names, and keep slash-named local branches separate from remote-tracking refs through worktree creation and reuse.

Keep native/SSH namespace boundaries and mixed-version client capability gates intact. Accept Git-valid dotted components and cover collisions with configured and orphan tracking refs.

Adapted from @nishino-tsukasa's #19540. Independently reviewed in seven adversarial rounds; 235 focused tests and 77 affected-Apple-Git tests pass, along with typecheck, quality checks, and the desktop build.

Correct the inherited file-explorer cache-scan expectation while retaining its exact constant-work bound.

Correct the inherited release-parser compatibility assertion to match the pinned test dependency; all 121 cross-version tests pass locally.

Fixes #19515

Co-authored-by: kino <nishinotsukasavirgo@gmail.com>
2026-10-05 23:47:01 -07:00

67 lines
3.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { parseAndFilterSearchRefDetails } from './repo-base-ref-search'
import { resolveBaseRefSearchSelector } from './base-ref-search-selector'
describe('base ref search selectors', () => {
it('qualifies slash-named locals even when no remote is configured', () => {
expect(resolveBaseRefSearchSelector('refs/heads/origin/feature', 'origin/feature')).toBe(
'refs/heads/origin/feature'
)
expect(resolveBaseRefSearchSelector('refs/heads/foo/bar/feature', 'foo/bar/feature')).toBe(
'refs/heads/foo/bar/feature'
)
expect(resolveBaseRefSearchSelector('refs/heads/feature/local', 'feature/local')).toBe(
'refs/heads/feature/local'
)
expect(resolveBaseRefSearchSelector('refs/heads/main', 'main')).toBe('main')
})
it.each([
['refs/heads/feature/加', 'feature/�', 'refs/heads/feature/加'],
['refs/heads/feature/加', 'feature/', 'refs/heads/feature/加'],
['refs/heads/feature/�', 'feature/�', 'refs/heads/feature/�'],
['refs/heads/�', '�', '�'],
['refs/heads/feature/�', 'refs/heads/feature/�', 'refs/heads/feature/�'],
['refs/heads/feature', 'heads/feature', 'refs/heads/feature'],
['refs/remotes/origin/feature', 'remotes/origin/feature', 'refs/remotes/origin/feature'],
['refs/remotes/refs/heads/feature', 'refs/heads/feature', 'refs/remotes/refs/heads/feature'],
['refs/remotes/origin/feature/HEAD', 'origin/feature', 'refs/remotes/origin/feature/HEAD'],
[
'refs/heads/refs/remotes/origin/feature',
'refs/remotes/origin/feature',
'refs/heads/refs/remotes/origin/feature'
],
[
'refs/remotes/refs/remotes/feature',
'refs/remotes/feature',
'refs/remotes/refs/remotes/feature'
],
['refs/remotes/origin/feature/HEAD', 'origin/fea', 'refs/remotes/origin/feature/HEAD']
])('preserves the identity of %s with short field %s', (full, short, expected) => {
expect(resolveBaseRefSearchSelector(full, short)).toBe(expected)
})
it('filters unsupported selectors before the page limit and deduplicates recovered full refs', () => {
const stdout = [
'refs/heads/feature/加\0feature/�',
'refs/heads/feature/加\0feature/�',
'refs/remotes/origin/feature/加\0origin/feature/�',
'refs/heads/safe-one\0safe-one',
'refs/heads/safe-two\0safe-two',
'refs/heads/safe-three\0safe-three'
].join('\n')
expect(parseAndFilterSearchRefDetails(stdout, 2, ['origin'], false)).toEqual([
{ refName: 'safe-one', localBranchName: 'safe-one' },
{ refName: 'safe-two', localBranchName: 'safe-two' }
])
expect(parseAndFilterSearchRefDetails(stdout, 3, ['origin'])).toEqual([
{ refName: 'refs/heads/feature/加', localBranchName: 'feature/加' },
{ refName: 'refs/remotes/origin/feature/加', localBranchName: 'feature/加' },
{ refName: 'safe-one', localBranchName: 'safe-one' }
])
})
it('does not publish malformed full refs', () => {
expect(parseAndFilterSearchRefDetails('refs/heads/bad..name\0bad..name', 10)).toEqual([])
})
})