Files
orca/src/main/git/runner-gh-host-args.test.ts
T
Jinjing 5487dff295 Fix gh CLI GHES host pinning and rate-limit scope leaks
- Pin `--host` on every gh call site so a process-level GH_HOST can't
  silently redirect requests, and qualify `-R`/`-R=` repo shorthand
  alongside the existing `--repo=` handling.
- Check the target scope for an active rate-limit block before each
  WSL/native or host fallback retry, not just on the initial attempt,
  so a blocked scope can't be hit again through a fallback path.
- Compute idempotency once per call instead of re-deriving it after
  fallback reassigns args.
2026-07-16 22:32:04 -07:00

126 lines
3.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { applyGhHostToArgs } from './runner'
describe('applyGhHostToArgs', () => {
it('returns args unchanged when no host is given', () => {
const args = ['api', 'repos/a/b/pulls']
expect(applyGhHostToArgs(args)).toBe(args)
expect(applyGhHostToArgs(['pr', 'list', '--repo', 'a/b'])).toEqual([
'pr',
'list',
'--repo',
'a/b'
])
})
it('injects --hostname right after `api` for any host', () => {
expect(applyGhHostToArgs(['api', 'rate_limit'], 'github.com')).toEqual([
'api',
'--hostname',
'github.com',
'rate_limit'
])
expect(applyGhHostToArgs(['api', 'repos/a/b/pulls'], 'github.acme-corp.com')).toEqual([
'api',
'--hostname',
'github.acme-corp.com',
'repos/a/b/pulls'
])
})
it('does not double-inject when --hostname is already present', () => {
expect(
applyGhHostToArgs(['api', '--hostname', 'github.com', 'rate_limit'], 'github.acme-corp.com')
).toEqual(['api', '--hostname', 'github.com', 'rate_limit'])
expect(
applyGhHostToArgs(['api', '--hostname=github.com', 'rate_limit'], 'github.acme-corp.com')
).toEqual(['api', '--hostname=github.com', 'rate_limit'])
})
it('qualifies bare owner/repo in --repo / -R for a GHES host', () => {
expect(applyGhHostToArgs(['pr', 'list', '--repo', 'a/b'], 'github.acme-corp.com')).toEqual([
'pr',
'list',
'--repo',
'github.acme-corp.com/a/b'
])
expect(applyGhHostToArgs(['pr', 'list', '-R', 'a/b'], 'github.acme-corp.com')).toEqual([
'pr',
'list',
'-R',
'github.acme-corp.com/a/b'
])
})
it('qualifies inline long and short repo forms for a GHES host', () => {
expect(applyGhHostToArgs(['pr', 'list', '--repo=a/b'], 'github.acme-corp.com')).toEqual([
'pr',
'list',
'--repo=github.acme-corp.com/a/b'
])
expect(applyGhHostToArgs(['pr', 'list', '-R=a/b'], 'github.acme-corp.com')).toEqual([
'pr',
'list',
'-R=github.acme-corp.com/a/b'
])
expect(applyGhHostToArgs(['pr', 'list', '-Ra/b'], 'github.acme-corp.com')).toEqual([
'pr',
'list',
'-Rgithub.acme-corp.com/a/b'
])
})
it('leaves --repo untouched for the github.com host (gh default resolution)', () => {
expect(applyGhHostToArgs(['pr', 'list', '--repo', 'a/b'], 'github.com')).toEqual([
'pr',
'list',
'--repo',
'a/b'
])
expect(applyGhHostToArgs(['pr', 'list', '--repo', 'a/b'], 'GitHub.com')).toEqual([
'pr',
'list',
'--repo',
'a/b'
])
})
it('passes through URL and already-qualified 3-part --repo values', () => {
expect(
applyGhHostToArgs(
['pr', 'list', '--repo', 'https://github.acme-corp.com/a/b'],
'github.acme-corp.com'
)
).toEqual(['pr', 'list', '--repo', 'https://github.acme-corp.com/a/b'])
expect(
applyGhHostToArgs(
['pr', 'list', '--repo', 'github.acme-corp.com/a/b'],
'github.acme-corp.com'
)
).toEqual(['pr', 'list', '--repo', 'github.acme-corp.com/a/b'])
expect(
applyGhHostToArgs(
['pr', 'list', '-R=https://github.acme-corp.com/a/b'],
'github.acme-corp.com'
)
).toEqual(['pr', 'list', '-R=https://github.acme-corp.com/a/b'])
expect(
applyGhHostToArgs(['pr', 'list', '-Rgithub.acme-corp.com/a/b'], 'github.acme-corp.com')
).toEqual(['pr', 'list', '-Rgithub.acme-corp.com/a/b'])
})
it('injects --hostname and qualifies --repo together for GHES api calls', () => {
expect(
applyGhHostToArgs(['api', 'repos/a/b/pulls', '--repo', 'a/b'], 'github.acme-corp.com')
).toEqual([
'api',
'--hostname',
'github.acme-corp.com',
'repos/a/b/pulls',
'--repo',
'github.acme-corp.com/a/b'
])
})
})