perf(source-control): drop redundant GHES gh auth probe in eligibility

Review follow-up. Detection only routes a GHES remote to the GitHub provider
after getEnterpriseGitHubRepoSlug has confirmed gh is authenticated to its
host, so isGitHubAuthenticated can trust a non-null slug as authenticated and
skip a second, rate-limited `gh auth status` spawn per eligibility poll.
Reaching the github.com probe now implies the remote is github.com. Tests
assert the enterprise path fires no redundant gh probe.
This commit is contained in:
Brennan Benson
2026-07-13 15:49:08 -07:00
parent b64a69bc49
commit ff9dce0788
2 changed files with 15 additions and 16 deletions
@@ -388,11 +388,9 @@ describe('createHostedReview', () => {
url: 'https://github.com/acme/orca/pull/12'
})
// The auth probe must target the GHES host, not the hardcoded github.com.
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
['auth', 'status', '--hostname', 'github.acme-corp.com'],
{ cwd: '/repo' }
)
// Detection already confirmed gh is authed to the GHES host, so the auth
// gate must not fire a second (rate-limited) gh probe.
expect(ghExecFileAsyncMock).not.toHaveBeenCalled()
expect(createGitHubPullRequestMock).toHaveBeenCalled()
expect(createGiteaPullRequestMock).not.toHaveBeenCalled()
})
@@ -704,11 +702,9 @@ describe('getHostedReviewCreationEligibility', () => {
nextAction: null
})
// The auth gate must probe the GHES host, not the hardcoded github.com.
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
['auth', 'status', '--hostname', 'github.acme-corp.com'],
{ cwd: '/repo' }
)
// Enterprise auth was already confirmed during detection; the gate must not
// fire a redundant gh probe.
expect(ghExecFileAsyncMock).not.toHaveBeenCalled()
})
it('resolves remote eligibility through SSH repo metadata without generating PR copy', async () => {
@@ -60,15 +60,18 @@ async function isGitHubAuthenticated(
connectionId?: string | null,
options: HostedReviewExecutionOptions = {}
): Promise<boolean> {
// Why: a GHES repo authenticates against its own custom host, so a hardcoded
// github.com probe reports "not authenticated" for Enterprise users (#8312).
// Resolve the repo's actual GitHub host, defaulting to github.com.
const enterprise = await getEnterpriseGitHubRepoSlug(repoPath, connectionId, options)
const hostname = enterprise?.host ?? 'github.com'
// Why: a GHES remote is only routed to the GitHub provider once detection has
// confirmed gh is authenticated to its enterprise host, so a non-null slug
// already means authenticated — skip a redundant, rate-limited gh probe.
// Reaching the github.com check below therefore means the remote is github.com
// (its own custom host would have resolved above) (#8312).
if (await getEnterpriseGitHubRepoSlug(repoPath, connectionId, options)) {
return true
}
await acquire()
try {
await ghExecFileAsync(
['auth', 'status', '--hostname', hostname],
['auth', 'status', '--hostname', 'github.com'],
connectionId ? {} : { cwd: repoPath, ...getHostedReviewLocalGitOptions(options) }
)
return true