refactor(github): organize concrete feature owners (#41601)

This commit is contained in:
Neil
2026-11-12 09:17:26 -08:00
committed by GitHub
parent ff9fd6634b
commit fb8d6f950b
1003 changed files with 4460 additions and 8422 deletions
@@ -1,4 +1,4 @@
import { normalizeGhAccountBinding } from '../../../../shared/github/account-binding'
import { normalizeGhAccountBinding } from '../../../../shared/github/accounts/account-binding'
import type { GhExecOptions } from './gh-exec-file'
import { collectGhArgvHostSignals } from './gh-host-args'
import type { ResolvedCommand } from '../host-routing/wsl-command-resolution'
@@ -38,7 +38,7 @@ export async function resolveBoundGhExecEnv(
createGhBoundAccountHostMismatchError,
createGhBoundAccountUnavailableError,
resolveGhAccountToken
} = await import('../../../github/gh-account-token')
} = await import('../../../github/accounts/gh-account-token')
const normalized = normalizeGhAccountBinding(binding)
if (!normalized) {
throw createGhBoundAccountUnavailableError(binding)
@@ -1,5 +1,5 @@
import type * as GhAccountTokenModule from '../../../github/accounts/gh-account-token'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createFakeSpawnedChild as mockChild } from '../../../../shared/__fixtures__/fake-spawned-child'
const {
spawnMock,
@@ -28,9 +28,7 @@ vi.mock('node:child_process', async (importOriginal) => ({
spawn: spawnMock
}))
import type * as GhAccountTokenModule from '../../../github/gh-account-token'
vi.mock('../../../github/gh-account-token', async (importOriginal) => {
vi.mock('../../../github/accounts/gh-account-token', async (importOriginal) => {
const actual = await importOriginal<typeof GhAccountTokenModule>()
return {
...actual,
@@ -44,24 +42,6 @@ import { ghExecFileAsync } from './gh-exec-file'
import { _resetGhRateLimitBreaker, recordGhPrimaryRateLimit } from './gh-rate-limit-breaker'
/** Spawns a child that settles with `stdout`, capturing the env the runner handed it. */
function spawnSettledChild(stdout: string): {
env: () => NodeJS.ProcessEnv | undefined
} {
let capturedEnv: NodeJS.ProcessEnv | undefined
spawnMock.mockImplementation(
(_cmd: string, _args: string[], opts: { env?: NodeJS.ProcessEnv }) => {
capturedEnv = opts.env
const child = mockChild()
queueMicrotask(() => {
child.stdout?.emit('data', Buffer.from(stdout))
child.emit('exit', 0, null)
child.emit('close', 0, null)
})
return child
}
)
return { env: () => capturedEnv }
}
describe('ghExecFileAsync account binding', () => {
beforeEach(() => {
@@ -93,19 +73,6 @@ describe('ghExecFileAsync account binding', () => {
_resetGhRateLimitBreaker()
})
it('skips injection for auth probes', async () => {
const spawned = spawnSettledChild('')
await ghExecFileAsync(['auth', 'status'], {
host: 'github.com',
ghAccount: { host: 'github.com', user: 'Alice' },
env: { ...process.env, GH_TOKEN: 'ambient' }
})
expect(resolveGhAccountTokenMock).not.toHaveBeenCalled()
expect(spawned.env()?.GH_TOKEN).toBe('ambient')
})
it('fails closed when argv host signals disagree with the binding', async () => {
await expect(
ghExecFileAsync(['pr', 'list', '--repo', 'github.acme.com/a/b'], {
@@ -129,20 +96,6 @@ describe('ghExecFileAsync account binding', () => {
}
)
it('still spawns the keyring token read while the core bucket is blocked', async () => {
recordGhPrimaryRateLimit('core', Date.now() + 60_000, 'native:github.com')
const spawned = spawnSettledChild('gho_bound\n')
const { stdout } = await ghExecFileAsync(
['auth', 'token', '--user', 'Alice', '--hostname', 'github.com'],
{ host: 'github.com' }
)
expect(stdout.trim()).toBe('gho_bound')
expect(spawnMock).toHaveBeenCalledTimes(1)
expect(spawned.env()).toBeDefined()
})
it('fails a bound API call fast on a blocked bucket without resolving a token', async () => {
recordGhPrimaryRateLimit('core', Date.now() + 60_000, 'native:github.com')
@@ -10,8 +10,8 @@ import {
import {
__resetPRConflictSummaryCachesForTests,
getPRConflictSummary
} from '../../github/conflict-summary'
import { __resetPRConflictSummaryDerivationCachesForTests } from '../../github/conflict-summary-cache'
} from '../../github/pull-requests/conflicts/conflict-summary'
import { __resetPRConflictSummaryDerivationCachesForTests } from '../../github/pull-requests/conflicts/conflict-summary-cache'
import { getLocalGitCapabilityCache } from '../command-runner/host-routing/git-capability-state'
import { deleteBranchAfterWorktreeRemoval } from '../worktrees/removal/worktree-branch-removal'
@@ -9,16 +9,12 @@ vi.mock('../command-runner/git-exec-file', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
gitExecFileAsync: gitExecFileAsyncMock
}))
vi.mock('../../github/local-git-config-signature', () => ({
vi.mock('../../github/repositories/local-git-config-signature', () => ({
readLocalGitConfigSignature: readLocalGitConfigSignatureMock
}))
import { REMOTE_URL_PROBE_TIMEOUT_MS } from './remote-url-probe'
import {
_resetRemoteNameListingCache,
listCachedRemoteNames,
shouldProbeGitRemote
} from './remote-name-listing'
import { _resetRemoteNameListingCache, shouldProbeGitRemote } from './remote-name-listing'
function remoteListCalls(): unknown[][] {
return gitExecFileAsyncMock.mock.calls.filter(
@@ -92,22 +88,6 @@ describe('cached git remote name listing', () => {
expect(remoteListCalls()).toHaveLength(2)
})
it('coalesces concurrent listings onto one spawn', async () => {
gitExecFileAsyncMock.mockImplementation(async () => {
await Promise.resolve()
return { stdout: 'origin\n' }
})
await expect(
Promise.all([
shouldProbeGitRemote('/repo', 'upstream'),
shouldProbeGitRemote('/repo', 'upstream'),
listCachedRemoteNames('/repo')
])
).resolves.toEqual([false, false, ['origin']])
expect(remoteListCalls()).toHaveLength(1)
})
it('keeps host and WSL listings separate', async () => {
gitExecFileAsyncMock.mockImplementation(
async (_args: string[], options: { wslDistro?: string } = {}) => ({
+1 -1
View File
@@ -1,4 +1,4 @@
import { readLocalGitConfigSignature } from '../../github/local-git-config-signature'
import { readLocalGitConfigSignature } from '../../github/repositories/local-git-config-signature'
import { runCoalescedProbe, type CoalescedProbes } from './coalesced-probe'
import type { GitAdmissionTier } from '../../../shared/rpc-contract/git-admission-tier-params'
import { REMOTE_URL_PROBE_TIMEOUT_MS } from './remote-url-probe'
@@ -1,7 +1,7 @@
import { parseGitRemoteVerboseOutput } from '../../../shared/git/remotes/git-remote-identity'
import { isDefaultGitHubHost } from '../../../shared/github/repository-identity-key'
import { isGitHubHostAuthenticated } from '../../github/github-enterprise-repository'
import { parseGitHubRemoteIdentity } from '../../github/github-remote-identity-parsing'
import { isDefaultGitHubHost } from '../../../shared/github/repositories/repository-identity-key'
import { isGitHubHostAuthenticated } from '../../github/repositories/github-enterprise-repository'
import { parseGitHubRemoteIdentity } from '../../github/repositories/github-remote-identity-parsing'
import {
getGlabKnownHosts,
getGlabPartialHosts
@@ -3,7 +3,7 @@
import type { Store } from '../../persistence/loading-store/store'
import type { WorktreeMeta } from '../../../shared/worktree/meta-types'
import type { GitPushTarget } from '../../../shared/worktree/types'
import { parseGitHubOwnerRepo } from '../../github/github-remote-identity-parsing'
import { parseGitHubOwnerRepo } from '../../github/repositories/github-remote-identity-parsing'
import { getRepoIdFromWorktreeId } from '../../../shared/worktree/id'
import { iterateProcessOutputLines } from '../../../shared/process-output-field-scanner'