test: remove 48 low-value suites (#42573)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-11-14 18:14:46 -08:00
committed by GitHub
co-authored by OrcaWin
parent d816232198
commit 7ff5252b03
51 changed files with 0 additions and 5166 deletions
@@ -1,138 +0,0 @@
import type * as GithubRepositoryIdentityModule from '../../repositories/github-repository-identity'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { LocalGitExecOptions } from '../../repositories/github-repository-identity'
const { exec, guard, spend } = vi.hoisted(() => ({ exec: vi.fn(), guard: vi.fn(), spend: vi.fn() }))
vi.mock('../../../git/command-runner/hosted-cli/gh-exec-file', () => ({
ghExecFileAsync: exec
}))
vi.mock('../../repositories/github-repository-identity', async (importOriginal) => ({
...(await importOriginal<typeof GithubRepositoryIdentityModule>()),
githubRepoContext: (
repoPath: string,
connectionId: string | null,
options: LocalGitExecOptions
) => ({ repoPath, connectionId, ...options }),
ghRepoExecOptions: ({ repoPath, ...options }: { repoPath: string }) => ({
cwd: repoPath,
...options
})
}))
vi.mock('../../api/rate-limit', () => ({
repositoryRateLimitGuard: guard,
noteRepositoryRateLimitSpend: spend
}))
import { getPRDetailContext } from './pull-request-detail-context'
const repository = { owner: 'acme', repo: 'widgets', host: 'github.com' }
const participant = { login: 'reviewer', name: null, avatarUrl: 'https://avatars/reviewer' }
const files = {
pageInfo: { hasNextPage: false, endCursor: null },
nodes: [{ path: 'src/changed.ts', viewerViewedState: 'VIEWED' }]
}
function response(
pullRequest: Record<string, unknown> | null = { participants: { nodes: [participant] } },
viewedPullRequest: Record<string, unknown> | null = { id: 'PR_42', files },
errors?: Record<string, unknown>[]
) {
return {
stdout: JSON.stringify({ data: { repository: { pullRequest, viewedPullRequest } }, errors })
}
}
function mockReads(reads: ({ stdout: string } | Error | { code: number; stdout: string })[]) {
exec.mockImplementation(async (args: string[]) => {
if (args.includes('graphql')) {
const next = reads.shift()
if (!next) {
throw new Error('Unexpected GraphQL read')
}
if (next instanceof Error || 'code' in next) {
throw next
}
return next
}
throw new Error('Unexpected non-GraphQL read')
})
}
function graphqlCalls(): string[][] {
return exec.mock.calls.flatMap(([args]) => (args.includes('graphql') ? [args] : []))
}
beforeEach(() => {
vi.resetAllMocks()
guard.mockReturnValue({ blocked: false })
})
describe('PR detail context requests', () => {
it('paginates only files after the first page and retains nullable viewer states', async () => {
mockReads([
response(undefined, {
id: 'PR_42',
files: { ...files, pageInfo: { hasNextPage: true, endCursor: 'cursor-1' } }
}),
response(null, {
id: 'PR_42',
files: { ...files, nodes: [null, { path: 'src/unknown.ts', viewerViewedState: null }] }
})
])
const result = await getPRDetailContext('/repo', 42, repository)
expect(result.viewedStates?.viewedStates).toEqual(new Map([['src/changed.ts', 'VIEWED']]))
expect(result.participants).toEqual([participant])
expect(graphqlCalls()).toHaveLength(2)
expect(graphqlCalls()[1]).toContain('after=cursor-1')
expect(graphqlCalls()[1].join(' ')).not.toContain('participants')
})
it.each([
{ path: ['repository', 'pullRequest', 'participants'] },
{ path: ['repository', 'pullRequest'] }
])('retains viewed files when an error nulls the participant PR at $path', async ({ path }) => {
mockReads([{ code: 1, ...response(null, { id: 'PR_42', files }, [{ path }]) }, response()])
const result = await getPRDetailContext('/repo', 42, repository)
expect(result.participants).toEqual([participant])
expect(result.viewedStates?.pullRequestId).toBe('PR_42')
expect(result.viewedStates?.viewedStates.get('src/changed.ts')).toBe('VIEWED')
expect(graphqlCalls()).toHaveLength(2)
expect(graphqlCalls()[1].join(' ')).not.toContain('viewerViewedState')
})
it('retains participants when the viewed PR alias is nulled', async () => {
mockReads([
{
code: 1,
...response(undefined, null, [{ path: ['repository', 'viewedPullRequest', 'id'] }])
}
])
const result = await getPRDetailContext('/repo', 42, repository)
expect(result.participants).toEqual([participant])
expect(result.viewedStates).toBeNull()
expect(graphqlCalls()).toHaveLength(1)
})
it('does not publish partially paginated viewed files after a later page fails', async () => {
mockReads([
response(undefined, {
id: 'PR_42',
files: { ...files, pageInfo: { hasNextPage: true, endCursor: 'next' } }
}),
new Error('file page unavailable')
])
const result = await getPRDetailContext('/repo', 42, repository)
expect(result.participants).toEqual([participant])
expect(result.viewedStates).toBeNull()
expect(graphqlCalls()).toHaveLength(2)
})
it('recovers participants after a failed query without retrying unavailable viewed state', async () => {
mockReads([new Error('Query failed'), response()])
const result = await getPRDetailContext('/repo', 42, repository)
expect(result.participants).toEqual([participant])
expect(result.viewedStates).toBeNull()
expect(graphqlCalls()).toHaveLength(2)
})
})
@@ -1,176 +0,0 @@
import type * as GithubRepositoryIdentityModule from '../../repositories/github-repository-identity'
import { beforeEach, describe, expect, it, vi } from 'vitest'
const { ghExecFileAsyncMock, repositoryMock } = vi.hoisted(() => ({
ghExecFileAsyncMock: vi.fn(),
repositoryMock: vi.fn()
}))
vi.mock('../../execution/github-operation-slots', () => ({
acquire: vi.fn(),
release: vi.fn()
}))
vi.mock('../../../git/command-runner/hosted-cli/gh-exec-file', () => ({
ghExecFileAsync: ghExecFileAsyncMock
}))
vi.mock('../../repositories/github-repository-identity', async (importOriginal) => ({
...(await importOriginal<typeof GithubRepositoryIdentityModule>()),
ghRepoExecOptions: (context: { repoPath: string; connectionId?: string | null }) =>
context.connectionId ? {} : { cwd: context.repoPath },
githubRepoContext: (
repoPath: string,
connectionId?: string | null,
localGitOptions?: Record<string, unknown>
) => ({ repoPath, connectionId, localGitOptions })
}))
vi.mock('../../repositories/github-api-repository-remote-probe', () => ({
getOriginGitHubApiRepository: repositoryMock
}))
vi.mock('../../repositories/github-repository-host', () => ({
githubHostExecOptions: (repository: { host?: string }) => ({ host: repository.host })
}))
import {
prepareGitHubStackedPullRequest,
registerGitHubStackedPullRequest
} from './stacked-pr-creation'
const repository = { owner: 'acme', repo: 'orca', host: 'github.com' }
const parentReview = { number: 41, url: 'https://github.com/acme/orca/pull/41' }
const currentReview = { number: 42, url: 'https://github.com/acme/orca/pull/42' }
function pullRequest(number: number, head: string, base: string) {
return {
number,
html_url: `https://github.com/acme/orca/pull/${number}`,
head: { ref: head },
base: { ref: base }
}
}
function stack(number: number, pullRequests: number[]) {
return {
number,
open: true,
pull_requests: pullRequests.map((pullRequestNumber) => ({ number: pullRequestNumber }))
}
}
beforeEach(() => {
ghExecFileAsyncMock.mockReset()
repositoryMock.mockReset()
repositoryMock.mockResolvedValue(repository)
})
describe('prepareGitHubStackedPullRequest', () => {
it('allows an idempotent retry after the child was already registered', async () => {
ghExecFileAsyncMock
.mockResolvedValueOnce({ stdout: JSON.stringify([pullRequest(41, 'stack/parent', 'main')]) })
.mockResolvedValueOnce({
stdout: JSON.stringify([pullRequest(42, 'stack/child', 'stack/parent')])
})
.mockResolvedValueOnce({ stdout: JSON.stringify([stack(50, [41, 42])]) })
.mockResolvedValueOnce({ stdout: JSON.stringify([stack(50, [41, 42])]) })
const result = await prepareGitHubStackedPullRequest(
'/repo',
{
provider: 'github',
base: 'stack/parent',
head: 'stack/child',
title: 'Child'
},
'local'
)
expect(result).toMatchObject({ ok: true, currentReview: { number: 42 } })
})
it('rejects a parent that is not the top of its stack', async () => {
ghExecFileAsyncMock
.mockResolvedValueOnce({ stdout: JSON.stringify([pullRequest(41, 'stack/parent', 'main')]) })
.mockResolvedValueOnce({ stdout: '[]' })
.mockResolvedValueOnce({ stdout: JSON.stringify([stack(50, [41, 45])]) })
const result = await prepareGitHubStackedPullRequest(
'/repo',
{
provider: 'github',
base: 'stack/parent',
head: 'stack/child',
title: 'Child'
},
'local'
)
expect(result).toMatchObject({ ok: false, code: 'validation' })
if (!result.ok) {
expect(result.error).toContain('top pull request')
}
})
})
describe('registerGitHubStackedPullRequest', () => {
it('treats an already registered parent-child pair as success', async () => {
ghExecFileAsyncMock
.mockResolvedValueOnce({ stdout: JSON.stringify([stack(50, [41, 42])]) })
.mockResolvedValueOnce({ stdout: JSON.stringify([stack(50, [41, 42])]) })
const result = await registerGitHubStackedPullRequest({
executionHostId: 'local',
repoPath: '/repo',
repository,
parentReview,
currentReview
})
expect(result).toMatchObject({ ok: true, stackNumber: 50 })
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(2)
})
it('does not claim registration when the stack no longer holds the parent', async () => {
// A missing parent gives -1; reading its successor would falsely identify the first entry as its child.
ghExecFileAsyncMock
.mockResolvedValueOnce({ stdout: JSON.stringify([stack(50, [42])]) })
.mockResolvedValueOnce({ stdout: JSON.stringify([stack(50, [42])]) })
const result = await registerGitHubStackedPullRequest({
executionHostId: 'local',
repoPath: '/repo',
repository,
parentReview,
currentReview
})
expect(result).toMatchObject({
ok: false,
error: 'The pull request already belongs to a different GitHub stack.',
reason: 'stack_conflict',
createdReview: currentReview
})
})
it('preserves the created PR when registration fails', async () => {
ghExecFileAsyncMock
.mockResolvedValueOnce({ stdout: '[]' })
.mockResolvedValueOnce({ stdout: '[]' })
.mockRejectedValueOnce(new Error('HTTP 422'))
const result = await registerGitHubStackedPullRequest({
executionHostId: 'local',
repoPath: '/repo',
repository,
parentReview,
currentReview
})
expect(result).toMatchObject({
ok: false,
createdReview: currentReview
})
})
})
@@ -1,129 +0,0 @@
import type * as GithubOwnerRepoSelectionModule from './github-owner-repo-selection'
import type * as GithubRepositoryIdentityModule from './github-repository-identity'
import type * as GithubEnterpriseRepositoryModule from './github-enterprise-repository'
import { beforeEach, describe, expect, it, vi } from 'vitest'
const {
getEnterpriseGitHubRepoSlugMock,
getOwnerRepoMock,
getOwnerRepoForRemoteMock,
isGitHubHostAuthenticatedMock,
shouldProbeGitRemoteMock
} = vi.hoisted(() => ({
getEnterpriseGitHubRepoSlugMock: vi.fn(),
getOwnerRepoMock: vi.fn(),
getOwnerRepoForRemoteMock: vi.fn(),
isGitHubHostAuthenticatedMock: vi.fn(),
shouldProbeGitRemoteMock: vi.fn(async () => true)
}))
vi.mock('./github-owner-repo-selection', async (importOriginal) => ({
...(await importOriginal<typeof GithubOwnerRepoSelectionModule>()),
getOwnerRepo: getOwnerRepoMock
}))
vi.mock('./github-repository-identity', async (importOriginal) => ({
...(await importOriginal<typeof GithubRepositoryIdentityModule>()),
getOwnerRepoForRemote: getOwnerRepoForRemoteMock
}))
vi.mock('./github-enterprise-repository', async (importOriginal) => ({
...(await importOriginal<typeof GithubEnterpriseRepositoryModule>()),
getEnterpriseGitHubRepoSlug: getEnterpriseGitHubRepoSlugMock,
isGitHubHostAuthenticated: isGitHubHostAuthenticatedMock
}))
vi.mock('../../git/remotes/remote-name-listing', () => ({
shouldProbeGitRemote: shouldProbeGitRemoteMock,
listCachedRemoteNames: async () => null
}))
import {
_resetOriginGitHubApiRepositoryCache,
getGitHubApiRepositoryForRemote
} from './github-api-repository-remote-probe'
import { resolveGitHubApiRepository, resolveGitHubRepoExecution } from './github-api-repository'
beforeEach(() => {
_resetOriginGitHubApiRepositoryCache()
getEnterpriseGitHubRepoSlugMock.mockReset().mockResolvedValue(null)
getOwnerRepoMock.mockReset().mockResolvedValue(null)
getOwnerRepoForRemoteMock.mockReset().mockResolvedValue(null)
isGitHubHostAuthenticatedMock.mockReset().mockResolvedValue(false)
shouldProbeGitRemoteMock.mockReset().mockResolvedValue(true)
})
describe('resolveGitHubRepoExecution', () => {
it('rejects an explicit Enterprise host absent from the local gh auth inventory', async () => {
await expect(
resolveGitHubApiRepository(
'/remote/repo',
{
owner: 'acme',
repo: 'widgets',
host: 'evil.example.test'
},
'ssh-1'
)
).resolves.toBeNull()
expect(isGitHubHostAuthenticatedMock).toHaveBeenCalledWith(
'evil.example.test',
'/remote/repo',
'ssh-1',
{}
)
})
it.each([
{ owner: 'acme%2Fadmin', repo: 'widgets' },
{ owner: 'acme', repo: '..' }
])('rejects repository overrides that could alter a gh REST path: %o', async (repository) => {
await expect(
resolveGitHubApiRepository('/repo', {
...repository,
host: 'github.com'
})
).resolves.toBeNull()
expect(isGitHubHostAuthenticatedMock).not.toHaveBeenCalled()
})
it('rejects a host-less caller-specific resolver for a connection-backed repository', async () => {
await expect(
resolveGitHubRepoExecution(
'/remote/repo',
async () => ({ owner: 'upstream', repo: 'widgets' }),
'ssh-1'
)
).resolves.toEqual({ ownerRepo: null, ghOptions: {} })
})
it('preserves an authoritative null from a caller-specific resolver', async () => {
getOwnerRepoMock.mockResolvedValue({ owner: 'origin', repo: 'widgets' })
await expect(resolveGitHubRepoExecution('/repo', async () => null)).resolves.toEqual({
ownerRepo: null,
ghOptions: { cwd: '/repo' }
})
expect(getOwnerRepoMock).not.toHaveBeenCalled()
})
})
describe('origin repository cache', () => {
it('keeps an indeterminate auth inventory unverifiable during candidate discovery', async () => {
getEnterpriseGitHubRepoSlugMock.mockResolvedValue(undefined)
await expect(
getGitHubApiRepositoryForRemote(
'/remote/repo',
'origin',
'ssh-1',
{},
{
requireVerifiedSshProbe: true
}
)
).rejects.toThrow('GitHub repository identity is unverifiable.')
})
})