Files
orca/src/shared/git-status-upstream-ref.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

44 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { isSafeGitRefName, isSafeGitStatusUpstreamRef } from './git-status-upstream-ref'
describe('git status upstream refs', () => {
it.each([
'refs/heads/feature./valid',
'refs/heads/feature./运动记录',
'refs/remotes/origin./main'
])('accepts a trailing dot in an intermediate component: %s', (ref) => {
expect(isSafeGitRefName(ref)).toBe(true)
})
it.each(['refs/heads/feature.', 'refs/heads/.hidden/valid', 'refs/heads/feature.lock/valid'])(
'rejects an unsafe dot placement: %s',
(ref) => {
expect(isSafeGitRefName(ref)).toBe(false)
}
)
it('accepts exact remote and custom upstream namespaces', () => {
expect(isSafeGitStatusUpstreamRef('refs/remotes/team/fork/feature/nested')).toBe(true)
expect(isSafeGitStatusUpstreamRef('refs/custom/origin/main')).toBe(true)
expect(isSafeGitStatusUpstreamRef('refs/tracking/main')).toBe(true)
expect(isSafeGitStatusUpstreamRef('refs/tracked-main')).toBe(true)
})
it('recognizes local branch refs without accepting them for dynamic status polling', () => {
expect(isSafeGitRefName('refs/heads/feature/base')).toBe(true)
expect(isSafeGitStatusUpstreamRef('refs/heads/feature/base')).toBe(false)
expect(isSafeGitStatusUpstreamRef('refs/worktree/feature/base')).toBe(false)
})
it.each([
'refs/heads/main',
'/refs/remotes/origin/main',
'refs/remotes/origin/../main',
'refs/remotes/origin/main.lock',
'refs/remotes/origin/feature\\escape',
'refs/remotes/origin/@{upstream}'
])('rejects unsafe or non-remote ref %s', (ref) => {
expect(isSafeGitStatusUpstreamRef(ref)).toBe(false)
})
})