mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
test: remove 54 low-value suites (#42578)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { revalidateGitHubRestJson } from './github-rest-revalidation'
|
||||
|
||||
const { gh, spend } = vi.hoisted(() => ({ gh: vi.fn(), spend: vi.fn() }))
|
||||
vi.mock('../../git/command-runner/hosted-cli/gh-exec-file', () => ({
|
||||
ghExecFileAsync: gh
|
||||
}))
|
||||
vi.mock('./rate-limit', () => ({
|
||||
noteRepositoryRateLimitSpend: spend
|
||||
}))
|
||||
|
||||
const repository = { owner: 'acme', repo: 'widgets', host: 'github.com' }
|
||||
const endpoint = 'repos/acme/widgets/pulls/7'
|
||||
const options = { cwd: '/repo' }
|
||||
let read: typeof revalidateGitHubRestJson
|
||||
function http(status: number, body = '', etag?: string): { stdout: string; stderr: string } {
|
||||
return {
|
||||
stdout: `HTTP/2.0 ${status} ${status === 304 ? 'Not Modified' : 'OK'}\n${etag ? `Etag: ${etag}\r\n` : ''}\r\n${body}`,
|
||||
stderr: ''
|
||||
}
|
||||
}
|
||||
function notModified() {
|
||||
return Object.assign(new Error('gh: HTTP 304'), http(304))
|
||||
}
|
||||
|
||||
describe('GitHub REST revalidation', () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules()
|
||||
gh.mockReset()
|
||||
spend.mockReset()
|
||||
read = (await import('./github-rest-revalidation')).revalidateGitHubRestJson
|
||||
})
|
||||
afterEach(() => vi.unstubAllEnvs())
|
||||
|
||||
it('revalidates immediately and returns the validated body on gh HTTP 304 exits without spending quota', async () => {
|
||||
gh.mockResolvedValueOnce(http(200, '{"number":7}', 'W/"v1"')).mockRejectedValueOnce(
|
||||
notModified()
|
||||
)
|
||||
expect(await read(repository, endpoint, options)).toBe('{"number":7}')
|
||||
expect(await read(repository, endpoint, options)).toBe('{"number":7}')
|
||||
expect(gh.mock.calls[1][0]).toEqual([
|
||||
'api',
|
||||
endpoint,
|
||||
'--include',
|
||||
'-H',
|
||||
'If-None-Match: W/"v1"'
|
||||
])
|
||||
expect(spend).toHaveBeenCalledTimes(1)
|
||||
expect(spend).toHaveBeenCalledWith(repository, 'core', 1, expect.objectContaining(options))
|
||||
})
|
||||
|
||||
it('does not return cached data after authorization failures and discards its validator', async () => {
|
||||
gh.mockResolvedValueOnce(http(200, '{"number":7}', '"v1"'))
|
||||
await read(repository, endpoint, options)
|
||||
const failure = Object.assign(
|
||||
new Error('HTTP 403 forbidden'),
|
||||
http(403, '{"message":"forbidden"}')
|
||||
)
|
||||
gh.mockRejectedValueOnce(failure).mockResolvedValueOnce(http(200, '{"number":8}'))
|
||||
await expect(read(repository, endpoint, options)).rejects.toBe(failure)
|
||||
expect(await read(repository, endpoint, options)).toBe('{"number":8}')
|
||||
expect(gh.mock.calls[2][0]).not.toContain('-H')
|
||||
})
|
||||
|
||||
it('does not retain malformed or validator-free bodies and rejects ungrounded 304 responses', async () => {
|
||||
gh.mockResolvedValueOnce(http(200, '{"number":7}'))
|
||||
.mockResolvedValueOnce(http(200, 'truncated', '"bad"'))
|
||||
.mockRejectedValueOnce(notModified())
|
||||
await read(repository, endpoint, options)
|
||||
await expect(read(repository, endpoint, options)).rejects.toThrow()
|
||||
await expect(read(repository, endpoint, options)).rejects.toThrow(
|
||||
'without a cached representation'
|
||||
)
|
||||
expect(gh.mock.calls.every(([args]) => !args.includes('-H'))).toBe(true)
|
||||
})
|
||||
|
||||
it('does not let an older read replace a newer validator', async () => {
|
||||
let finish: (result: ReturnType<typeof http>) => void = () => {}
|
||||
gh.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
finish = resolve
|
||||
})
|
||||
)
|
||||
.mockResolvedValueOnce(http(200, '{"number":8}', '"new"'))
|
||||
.mockRejectedValueOnce(notModified())
|
||||
const older = read(repository, endpoint, options)
|
||||
await read(repository, endpoint, options)
|
||||
finish(http(200, '{"number":7}', '"old"'))
|
||||
await older
|
||||
expect(await read(repository, endpoint, options)).toBe('{"number":8}')
|
||||
expect(gh.mock.calls[2][0]).toContain('If-None-Match: "new"')
|
||||
})
|
||||
})
|
||||
@@ -1,81 +0,0 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const { ghExecFileAsyncMock } = vi.hoisted(() => ({ ghExecFileAsyncMock: vi.fn() }))
|
||||
|
||||
vi.mock('../../../git/command-runner/hosted-cli/gh-exec-file', () => ({
|
||||
ghExecFileAsync: ghExecFileAsyncMock
|
||||
}))
|
||||
vi.mock('../../api/rate-limit', () => ({
|
||||
repositoryRateLimitGuard: () => ({ blocked: false }),
|
||||
noteRepositoryRateLimitSpend: () => {}
|
||||
}))
|
||||
|
||||
import {
|
||||
getMergedPRHeadRelationship,
|
||||
resetMergedPRCommitMembershipCacheForTest
|
||||
} from './merged-pr-commit-membership'
|
||||
|
||||
const REBASED_AWAY = '6ada46e391c5e4025d13d0304c4c0729af13a923'
|
||||
|
||||
function membership() {
|
||||
return getMergedPRHeadRelationship({
|
||||
ownerRepo: { owner: 'stablyai', repo: 'orca' },
|
||||
prNumber: 41082,
|
||||
commitOid: REBASED_AWAY,
|
||||
ghOptions: { cwd: '/repo' }
|
||||
})
|
||||
}
|
||||
|
||||
function scriptForcePushes(beforeOids: (string | null)[], hasPreviousPage = false): void {
|
||||
ghExecFileAsyncMock.mockImplementation(async (args: string[]) => {
|
||||
if (args[1] === 'graphql') {
|
||||
return {
|
||||
stdout: JSON.stringify({
|
||||
data: {
|
||||
repository: {
|
||||
pullRequest: {
|
||||
timelineItems: {
|
||||
totalCount: 23,
|
||||
pageInfo: { hasPreviousPage },
|
||||
nodes: beforeOids.map((oid) => ({ beforeCommit: oid ? { oid } : null }))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
// GitHub drops a force-pushed-away commit's PR association.
|
||||
return { stdout: '[]' }
|
||||
})
|
||||
}
|
||||
|
||||
describe('getMergedPRHeadRelationship', () => {
|
||||
it('proves absence from a complete filtered page despite an unfiltered total count', async () => {
|
||||
scriptForcePushes([
|
||||
'1111111111111111111111111111111111111111',
|
||||
'2222222222222222222222222222222222222222'
|
||||
])
|
||||
await expect(membership()).resolves.toBe('not-contained')
|
||||
})
|
||||
|
||||
it('keeps absence unknown when a previous filtered page exists', async () => {
|
||||
scriptForcePushes(['1111111111111111111111111111111111111111'], true)
|
||||
await expect(membership()).resolves.toBe('unknown')
|
||||
})
|
||||
|
||||
it('preserves uncertainty when a force-push event has no prior commit', async () => {
|
||||
scriptForcePushes([null])
|
||||
await expect(membership()).resolves.toBe('unknown')
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
ghExecFileAsyncMock.mockReset()
|
||||
resetMergedPRCommitMembershipCacheForTest()
|
||||
})
|
||||
|
||||
it('treats a force-pushed-away head as association without claiming its changes landed', async () => {
|
||||
scriptForcePushes([null, REBASED_AWAY])
|
||||
await expect(membership()).resolves.toBe('associated')
|
||||
})
|
||||
})
|
||||
@@ -1,153 +0,0 @@
|
||||
import type * as CommandExecFileModule from '../../git/command-runner/process-capture/command-exec-file'
|
||||
import type * as GitExecFileModule from '../../git/command-runner/git-exec-file'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const {
|
||||
commandExecFileAsyncMock,
|
||||
gitExecFileAsyncMock,
|
||||
resolveWithSshGMock,
|
||||
readLocalGitConfigSignatureMock
|
||||
} = vi.hoisted(() => ({
|
||||
commandExecFileAsyncMock: vi.fn(),
|
||||
gitExecFileAsyncMock: vi.fn(),
|
||||
resolveWithSshGMock: vi.fn(),
|
||||
readLocalGitConfigSignatureMock: vi.fn(async () => 'sig-10284')
|
||||
}))
|
||||
|
||||
vi.mock('../../git/command-runner/process-capture/command-exec-file', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof CommandExecFileModule>()),
|
||||
commandExecFileAsync: commandExecFileAsyncMock
|
||||
}))
|
||||
|
||||
vi.mock('../../git/command-runner/git-exec-file', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof GitExecFileModule>()),
|
||||
gitExecFileAsync: gitExecFileAsyncMock
|
||||
}))
|
||||
|
||||
vi.mock('./local-git-config-signature', () => ({
|
||||
readLocalGitConfigSignature: readLocalGitConfigSignatureMock
|
||||
}))
|
||||
|
||||
vi.mock('../../ssh/config/ssh-g-config-resolution', () => ({
|
||||
resolveWithSshG: resolveWithSshGMock
|
||||
}))
|
||||
|
||||
import {
|
||||
getOwnerRepoForRemote,
|
||||
_resetOwnerRepoCache,
|
||||
_getOwnerRepoCacheSize
|
||||
} from './github-repository-identity'
|
||||
import {
|
||||
classifyGitHubOwnerRepoFromRemoteUrl,
|
||||
resolveGitHubOwnerRepoFromRemoteUrl,
|
||||
_resetSshHostnameResolutionCache
|
||||
} from './github-ssh-host-alias-resolution'
|
||||
|
||||
const REPO = '/tmp/ssh-alias-checkout'
|
||||
|
||||
function sshConfig(hostname: string, port = 22) {
|
||||
return {
|
||||
hostname,
|
||||
port,
|
||||
identityFile: [],
|
||||
identitiesOnly: false,
|
||||
forwardAgent: false,
|
||||
proxyUseFdpass: false,
|
||||
controlMaster: 'no',
|
||||
controlPersist: 'no'
|
||||
}
|
||||
}
|
||||
|
||||
function mockRemoteUrl(url: string): void {
|
||||
gitExecFileAsyncMock.mockImplementation(async (args: string[]) => {
|
||||
if (args[0] === 'remote' && args[1] === 'get-url') {
|
||||
return { stdout: `${url}\n` }
|
||||
}
|
||||
throw new Error(`unexpected git args: ${args.join(' ')}`)
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
_resetOwnerRepoCache()
|
||||
_resetSshHostnameResolutionCache()
|
||||
commandExecFileAsyncMock.mockReset()
|
||||
gitExecFileAsyncMock.mockReset()
|
||||
resolveWithSshGMock.mockReset()
|
||||
readLocalGitConfigSignatureMock.mockClear()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
describe('#10284 SSH Host alias → github.com owner/repo', () => {
|
||||
it('does not read an SSH repoPath locally when its provider is missing', async () => {
|
||||
await expect(
|
||||
getOwnerRepoForRemote(
|
||||
'/remote/repo',
|
||||
'origin',
|
||||
'ssh-1',
|
||||
{},
|
||||
{
|
||||
requireVerifiedSshProbe: true
|
||||
}
|
||||
)
|
||||
).rejects.toThrow('Remote connection dropped.')
|
||||
expect(gitExecFileAsyncMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('isolates the same alias across native and WSL runtimes', async () => {
|
||||
resolveWithSshGMock.mockResolvedValueOnce(sshConfig('github.com'))
|
||||
commandExecFileAsyncMock.mockResolvedValueOnce({
|
||||
stdout: 'hostname gitlab.com\nport 22\n',
|
||||
stderr: ''
|
||||
})
|
||||
|
||||
await expect(
|
||||
resolveGitHubOwnerRepoFromRemoteUrl('git@forge-work:team/orca.git')
|
||||
).resolves.toEqual({ owner: 'team', repo: 'orca' })
|
||||
await expect(
|
||||
resolveGitHubOwnerRepoFromRemoteUrl('git@forge-work:team/orca.git', {
|
||||
repoPath: REPO,
|
||||
wslDistro: 'Ubuntu'
|
||||
})
|
||||
).resolves.toBeNull()
|
||||
expect(resolveWithSshGMock).toHaveBeenCalledTimes(1)
|
||||
expect(commandExecFileAsyncMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('does not pin an SSH-config-dependent miss to the Git config signature', async () => {
|
||||
vi.useFakeTimers()
|
||||
mockRemoteUrl('git@forge-work:team/orca.git')
|
||||
resolveWithSshGMock
|
||||
.mockResolvedValueOnce(sshConfig('gitlab.com'))
|
||||
.mockResolvedValueOnce(sshConfig('github.com'))
|
||||
|
||||
await expect(getOwnerRepoForRemote(REPO, 'origin')).resolves.toBeNull()
|
||||
await vi.advanceTimersByTimeAsync(60_001)
|
||||
await expect(getOwnerRepoForRemote(REPO, 'origin')).resolves.toEqual({
|
||||
owner: 'team',
|
||||
repo: 'orca'
|
||||
})
|
||||
})
|
||||
|
||||
it('isolates case-sensitive OpenSSH Host aliases in the cache', async () => {
|
||||
resolveWithSshGMock.mockImplementation(async (host: string) =>
|
||||
sshConfig(host === 'GitHub-Work' ? 'github.com' : 'gitlab.com')
|
||||
)
|
||||
|
||||
await expect(
|
||||
classifyGitHubOwnerRepoFromRemoteUrl('git@GitHub-Work:team/orca.git')
|
||||
).resolves.toEqual({
|
||||
kind: 'github',
|
||||
ownerRepo: { owner: 'team', repo: 'orca' }
|
||||
})
|
||||
await expect(
|
||||
classifyGitHubOwnerRepoFromRemoteUrl('git@github-work:team/orca.git')
|
||||
).resolves.toEqual({
|
||||
kind: 'not-github',
|
||||
cacheWithGitConfigSignature: false
|
||||
})
|
||||
expect(resolveWithSshGMock).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user