mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
test: remove 120 low-value suites (#42585)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -1,168 +0,0 @@
|
||||
import type * as GithubRepositoryIdentityModule from '../../repositories/github-repository-identity'
|
||||
import type * as GithubEnterpriseRepositoryModule from '../../repositories/github-enterprise-repository'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const { ghExecFileAsyncMock, getOwnerRepoMock, rateLimitGuardMock } = vi.hoisted(() => ({
|
||||
ghExecFileAsyncMock: vi.fn(),
|
||||
getOwnerRepoMock: vi.fn(),
|
||||
rateLimitGuardMock: vi.fn(() => ({ blocked: false }))
|
||||
}))
|
||||
|
||||
vi.mock('../../execution/github-legacy-command', () => ({
|
||||
execFileAsync: 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>()),
|
||||
githubRepoContext: (repoPath: string, connectionId?: string | null) => ({
|
||||
repoPath,
|
||||
connectionId: connectionId ?? null
|
||||
}),
|
||||
ghRepoExecOptions: (context: { repoPath: string }) => ({ cwd: context.repoPath }),
|
||||
getOwnerRepoForRemote: (
|
||||
repoPath: string,
|
||||
remoteName: string,
|
||||
connectionId?: string | null,
|
||||
localGitOptions?: unknown
|
||||
) =>
|
||||
remoteName === 'origin'
|
||||
? getOwnerRepoMock(repoPath, connectionId, localGitOptions)
|
||||
: Promise.resolve(null),
|
||||
_resetOwnerRepoCache: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('../../repositories/github-owner-repo-selection', () => ({
|
||||
getOwnerRepo: getOwnerRepoMock
|
||||
}))
|
||||
|
||||
vi.mock('../../execution/github-operation-slots', () => ({
|
||||
acquire: vi.fn(),
|
||||
release: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('../../../git/command-runner/git-exec-file', async (importOriginal) => ({
|
||||
...(await importOriginal<Record<string, unknown>>()),
|
||||
gitExecFileAsync: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('../../repositories/github-enterprise-repository', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof GithubEnterpriseRepositoryModule>()),
|
||||
isGitHubHostAuthenticated: vi.fn().mockResolvedValue(true)
|
||||
}))
|
||||
|
||||
vi.mock('../../api/rate-limit', () => ({
|
||||
rateLimitGuard: rateLimitGuardMock,
|
||||
noteRateLimitSpend: vi.fn(),
|
||||
repositoryRateLimitGuard: vi.fn(() => ({ blocked: false })),
|
||||
noteRepositoryRateLimitSpend: vi.fn(),
|
||||
spendsSharedGitHubComQuota: vi.fn(() => true)
|
||||
}))
|
||||
|
||||
import { getPRCheckDetails } from './get-pr-check-details'
|
||||
import { _resetOwnerRepoCache } from '../../repositories/github-repository-identity'
|
||||
|
||||
describe('getPRCheckDetails', () => {
|
||||
beforeEach(() => {
|
||||
ghExecFileAsyncMock.mockReset()
|
||||
getOwnerRepoMock.mockReset()
|
||||
rateLimitGuardMock.mockReset()
|
||||
rateLimitGuardMock.mockReturnValue({ blocked: false })
|
||||
_resetOwnerRepoCache()
|
||||
})
|
||||
|
||||
it('aborts host work at the cumulative check-details deadline', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'acme', repo: 'widgets' })
|
||||
ghExecFileAsyncMock.mockImplementation(
|
||||
(_args: string[], options: { signal?: AbortSignal }) =>
|
||||
new Promise((_resolve, reject) => {
|
||||
options.signal?.addEventListener(
|
||||
'abort',
|
||||
() => {
|
||||
const error = new Error('aborted')
|
||||
error.name = 'AbortError'
|
||||
reject(error)
|
||||
},
|
||||
{ once: true }
|
||||
)
|
||||
})
|
||||
)
|
||||
const request = getPRCheckDetails('/repo-root', { checkRunId: 88 })
|
||||
const rejection = expect(request).rejects.toThrow('Timed out loading check details.')
|
||||
|
||||
await vi.advanceTimersByTimeAsync(25_000)
|
||||
|
||||
await rejection
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('stops waiting for shared repository resolution at the host deadline', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
getOwnerRepoMock.mockImplementationOnce(() => new Promise(() => {}))
|
||||
const request = getPRCheckDetails('/repo-root', { checkRunId: 88 })
|
||||
const rejection = expect(request).rejects.toThrow('Timed out loading check details.')
|
||||
|
||||
await vi.advanceTimersByTimeAsync(25_000)
|
||||
|
||||
await rejection
|
||||
expect(ghExecFileAsyncMock).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('reads a fine-grained token check from its Actions job when the check run is refused', async () => {
|
||||
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'acme', repo: 'widgets' })
|
||||
const job = {
|
||||
id: 71,
|
||||
run_id: 7,
|
||||
name: 'pytest',
|
||||
status: 'completed',
|
||||
conclusion: 'success',
|
||||
html_url: 'https://github.com/acme/widgets/actions/runs/7/job/71',
|
||||
started_at: '2026-11-10T10:00:00Z',
|
||||
completed_at: '2026-11-10T10:05:00Z',
|
||||
steps: []
|
||||
}
|
||||
ghExecFileAsyncMock.mockImplementation(async (args: string[]) => {
|
||||
const path = args.at(-1) ?? ''
|
||||
if (path.includes('/check-runs/71')) {
|
||||
throw Object.assign(new Error(`Command failed: gh api ${path}`), {
|
||||
stderr: 'gh: Resource not accessible by personal access token (HTTP 403)\n',
|
||||
stdout: ''
|
||||
})
|
||||
}
|
||||
if (path.endsWith('/actions/jobs/71')) {
|
||||
return { stdout: JSON.stringify(job), stderr: '' }
|
||||
}
|
||||
if (path.includes('/actions/runs/7/jobs')) {
|
||||
return { stdout: JSON.stringify({ jobs: [job] }), stderr: '' }
|
||||
}
|
||||
throw new Error(`unexpected ${path}`)
|
||||
})
|
||||
|
||||
const details = await getPRCheckDetails('/repo-root', {
|
||||
checkRunId: 71,
|
||||
workflowRunId: 7,
|
||||
checkName: 'pytest'
|
||||
})
|
||||
|
||||
expect(details).toMatchObject({
|
||||
name: 'pytest',
|
||||
status: 'completed',
|
||||
conclusion: 'success',
|
||||
url: 'https://github.com/acme/widgets/actions/runs/7/job/71',
|
||||
startedAt: '2026-11-10T10:00:00Z',
|
||||
completedAt: '2026-11-10T10:05:00Z',
|
||||
jobs: [{ id: 71, name: 'pytest', status: 'completed', conclusion: 'success' }]
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,63 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
GITHUB_PROJECT_REF_INPUT_MAX_BYTES,
|
||||
GITHUB_PROJECT_REF_INPUT_TOO_LARGE_ERROR
|
||||
} from '../../../shared/github/projects/project-ref-input'
|
||||
import {
|
||||
_getProjectViewCacheSizesForTests,
|
||||
_getProjectViewOwnerTypeForTests,
|
||||
_hasProjectViewParentFieldRetriedForTests,
|
||||
_hasProjectViewParentFieldWarningLoggedForTests,
|
||||
_markProjectViewParentFieldRetriedForTests,
|
||||
_markProjectViewParentFieldWarningLoggedForTests,
|
||||
_rememberProjectViewOwnerTypeForTests,
|
||||
_resetProjectViewCachesForTests
|
||||
} from './project-view-cache'
|
||||
import { parseProjectPaste, resolveProjectRef } from './project-view-reference'
|
||||
|
||||
describe('parseProjectPaste', () => {
|
||||
it('accepts enterprise-host URLs only when that host is provided (GHES)', () => {
|
||||
const url = 'https://github.corp.example/orgs/acme/projects/7/views/2'
|
||||
expect(parseProjectPaste(url, 'github.corp.example')).toEqual({
|
||||
kind: 'org',
|
||||
owner: 'acme',
|
||||
number: 7,
|
||||
host: 'github.corp.example',
|
||||
viewNumber: 2
|
||||
})
|
||||
expect(parseProjectPaste(url)).toBeNull()
|
||||
expect(
|
||||
parseProjectPaste('https://github.com/orgs/acme/projects/7', 'github.corp.example')
|
||||
).toEqual({ kind: 'org', owner: 'acme', number: 7, host: 'github.com' })
|
||||
})
|
||||
|
||||
it('rejects credentials and paths that only begin like a Project URL', () => {
|
||||
expect(parseProjectPaste('https://user:token@github.com/orgs/acme/projects/1')).toBeNull()
|
||||
expect(parseProjectPaste('https://github.com/orgs/acme/projects/1evil')).toBeNull()
|
||||
expect(parseProjectPaste('https://github.com/orgs/acme/projects/1/views/2evil')).toBeNull()
|
||||
expect(parseProjectPaste('https://github.com/orgs/acme/projects/1/files')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveProjectRef', () => {
|
||||
it('rejects oversized project refs with a metadata-only validation error', async () => {
|
||||
const secret = 'project-url-secret'
|
||||
const input = [
|
||||
'https://github.com/orgs/acme/projects/42?',
|
||||
secret,
|
||||
'x'.repeat(GITHUB_PROJECT_REF_INPUT_MAX_BYTES)
|
||||
].join('')
|
||||
|
||||
await expect(resolveProjectRef({ input })).resolves.toEqual({
|
||||
ok: false,
|
||||
error: {
|
||||
type: 'validation_error',
|
||||
message: GITHUB_PROJECT_REF_INPUT_TOO_LARGE_ERROR,
|
||||
reason: 'input_too_large'
|
||||
}
|
||||
})
|
||||
await expect(resolveProjectRef({ input })).resolves.not.toMatchObject({
|
||||
error: { message: expect.stringContaining(secret) }
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,162 +0,0 @@
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import type { PRRefreshOutcome } from '../../../../shared/github/pull-requests/refresh/pull-request-refresh-types'
|
||||
import { makeCandidate, makePR } from './pr-refresh-coordinator-test-harness'
|
||||
|
||||
const mocks = vi.hoisted(() => ({ resolve: vi.fn(), send: vi.fn(), selection: 0 }))
|
||||
vi.mock('../../client/lookup/branch-lookup-resolution', () => ({
|
||||
resolvePRForBranchOutcome: mocks.resolve
|
||||
}))
|
||||
vi.mock('../../accounts/github-project-account', () => ({
|
||||
githubPRPolicyProjects: () => ({ source: null, selection: mocks.selection }),
|
||||
resolveGitHubProjectAccount: () => null
|
||||
}))
|
||||
vi.mock('../../execution/github-operation-slots', () => ({
|
||||
acquire: async () => {},
|
||||
release: () => {}
|
||||
}))
|
||||
vi.mock('./pr-refresh-rate-limit-gate', () => ({ prRefreshRateLimitPausedUntil: async () => null }))
|
||||
vi.mock('./pr-refresh-renderer-port', () => ({
|
||||
prRefreshRenderers: () => ({ isRendererOpen: () => true, sendToTrustedUI: mocks.send })
|
||||
}))
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(1_000)
|
||||
mocks.selection = 0
|
||||
mocks.resolve.mockReset()
|
||||
mocks.send.mockReset()
|
||||
})
|
||||
afterEach(() => {
|
||||
vi.clearAllTimers()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
function found(overrides: Parameters<typeof makePR>[0] = {}): PRRefreshOutcome {
|
||||
return {
|
||||
kind: 'found',
|
||||
fetchedAt: Date.now(),
|
||||
pr: makePR({
|
||||
checksStatus: 'success',
|
||||
checksReadComplete: true,
|
||||
checksFinal: true,
|
||||
autoMergeEnabled: false,
|
||||
mergeQueueRequired: false,
|
||||
...overrides
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
it('delivers a real refresh after quiet evidence retires without repeating the cached follow-up', async () => {
|
||||
mocks.resolve.mockImplementation(async () => found())
|
||||
const coordinator = await import('./pr-refresh-coordinator')
|
||||
const { getPRForBranchOutcome } = await import('../../client/lookup/pr-for-branch-outcome')
|
||||
const candidate = makeCandidate({ currentHeadOid: 'head-sha' })
|
||||
const seed = () =>
|
||||
coordinator.runHostedPRRead(candidate, () =>
|
||||
getPRForBranchOutcome('/repo', candidate.branch, null, null, null, {
|
||||
currentHeadOid: 'head-sha'
|
||||
})
|
||||
)
|
||||
await seed()
|
||||
vi.setSystemTime(2_000)
|
||||
await seed()
|
||||
const visible = {
|
||||
...candidate,
|
||||
cachedFetchedAt: 2_000,
|
||||
cachedHeadOid: 'head-sha',
|
||||
cachedHasPR: true,
|
||||
cachedPRState: 'open' as const,
|
||||
cachedChecksStatus: 'success' as const
|
||||
}
|
||||
coordinator.reportVisiblePRRefreshCandidates([visible], 1, 1)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(mocks.resolve).toHaveBeenCalledTimes(2)
|
||||
vi.setSystemTime(132_001)
|
||||
mocks.selection++
|
||||
mocks.resolve.mockImplementation(async () => found({ title: 'updated' }))
|
||||
mocks.send.mockClear()
|
||||
mocks.send.mockImplementation(() => {
|
||||
// Bound the unfixed synchronous loop even though its fake clock would otherwise never advance.
|
||||
if (mocks.send.mock.calls.length === 8) {
|
||||
vi.setSystemTime(1_000_000)
|
||||
}
|
||||
})
|
||||
coordinator.reportVisiblePRRefreshCandidates([visible], 2, 1)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(mocks.resolve).toHaveBeenCalledTimes(3)
|
||||
expect(mocks.send.mock.calls.length).toBeLessThanOrEqual(2)
|
||||
expect(mocks.send.mock.calls.at(-1)?.[1]).toMatchObject({
|
||||
outcome: { fetchedAt: 132_001, pr: { title: 'updated' } }
|
||||
})
|
||||
await vi.advanceTimersByTimeAsync(120_001)
|
||||
expect(mocks.send.mock.calls.at(-1)?.[1]).toMatchObject({
|
||||
outcome: { fetchedAt: 252_001, pr: { title: 'updated' } }
|
||||
})
|
||||
})
|
||||
|
||||
it('rereads unresolved manual mergeability at its forced follow-up despite the timed cache', async () => {
|
||||
mocks.resolve
|
||||
.mockImplementationOnce(async () =>
|
||||
found({ mergeable: 'UNKNOWN', mergeStateStatus: 'UNKNOWN' })
|
||||
)
|
||||
.mockImplementation(async () => found({ mergeable: 'MERGEABLE', mergeStateStatus: 'CLEAN' }))
|
||||
const coordinator = await import('./pr-refresh-coordinator')
|
||||
const candidate = makeCandidate({ currentHeadOid: 'head-sha' })
|
||||
coordinator.reportVisiblePRRefreshCandidates([candidate], 1, 1)
|
||||
expect(await coordinator.refreshPRNow(candidate)).toMatchObject({
|
||||
pr: { mergeable: 'UNKNOWN' }
|
||||
})
|
||||
await vi.advanceTimersByTimeAsync(2_501)
|
||||
expect(mocks.resolve).toHaveBeenCalledTimes(2)
|
||||
expect(mocks.send.mock.calls.at(-1)?.[1]).toMatchObject({
|
||||
outcome: { pr: { mergeable: 'MERGEABLE', mergeStateStatus: 'CLEAN' } }
|
||||
})
|
||||
})
|
||||
|
||||
it.each([false, true])(
|
||||
'refreshes a settled row on re-exposure and shares a newer exact answer (refreshed while queued: %s)',
|
||||
async (refreshedWhileQueued) => {
|
||||
mocks.resolve.mockImplementation(async () => found({ state: 'merged' }))
|
||||
const coordinator = await import('./pr-refresh-coordinator')
|
||||
const { getPRForBranchOutcome } = await import('../../client/lookup/pr-for-branch-outcome')
|
||||
const candidate = makeCandidate({ currentHeadOid: 'head-sha', linkedPRNumber: 12 })
|
||||
const seed = () =>
|
||||
coordinator.runHostedPRRead(candidate, () =>
|
||||
getPRForBranchOutcome('/repo', candidate.branch, 12, null, null, {
|
||||
currentHeadOid: 'head-sha',
|
||||
userRefresh: true
|
||||
})
|
||||
)
|
||||
await seed()
|
||||
const visible = {
|
||||
...candidate,
|
||||
cachedFetchedAt: 1_000,
|
||||
cachedHeadOid: 'head-sha',
|
||||
cachedHasPR: true,
|
||||
cachedPRState: 'merged' as const,
|
||||
cachedChecksStatus: 'success' as const
|
||||
}
|
||||
coordinator.reportVisiblePRRefreshCandidates([visible], 1, 1)
|
||||
coordinator.reportVisiblePRRefreshCandidates([], 2, 1)
|
||||
vi.setSystemTime(2_000)
|
||||
coordinator.reportVisiblePRRefreshCandidates([visible], 3, 1)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(mocks.resolve).toHaveBeenCalledTimes(1)
|
||||
coordinator.reportVisiblePRRefreshCandidates([], 4, 1)
|
||||
vi.setSystemTime(21_000)
|
||||
mocks.resolve.mockImplementation(async () => found({ state: 'merged', title: 'updated' }))
|
||||
mocks.send.mockClear()
|
||||
coordinator.reportVisiblePRRefreshCandidates([visible], 5, 1)
|
||||
if (refreshedWhileQueued) {
|
||||
await seed()
|
||||
}
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(mocks.send.mock.calls.at(-1)?.[1]).toMatchObject({
|
||||
outcome: { fetchedAt: 21_000, pr: { state: 'merged', title: 'updated' } }
|
||||
})
|
||||
expect(mocks.resolve).toHaveBeenCalledTimes(2)
|
||||
await vi.advanceTimersByTimeAsync(600_000)
|
||||
expect(mocks.resolve).toHaveBeenCalledTimes(2)
|
||||
}
|
||||
)
|
||||
-170
@@ -1,170 +0,0 @@
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import { makeCandidate, makePR } from './pr-refresh-coordinator-test-harness'
|
||||
|
||||
const { coordinatorMocks, moduleMocks } = await vi.hoisted(async () => {
|
||||
const moduleMocks = await import('./pr-refresh-coordinator-test-mocks')
|
||||
return { coordinatorMocks: moduleMocks.createPRRefreshCoordinatorMocks(), moduleMocks }
|
||||
})
|
||||
// Only the provider is faked: the read, its exact cached result and the queue are the real ones.
|
||||
const provider = vi.hoisted(() => ({ resolve: vi.fn() }))
|
||||
vi.mock('./pr-refresh-renderer-port', () => moduleMocks.rendererPortModuleMock(coordinatorMocks))
|
||||
vi.mock('./pr-refresh-rate-limit-gate', () => ({
|
||||
prRefreshRateLimitPausedUntil: async () => null
|
||||
}))
|
||||
vi.mock('../../client/lookup/branch-lookup-resolution', () => ({
|
||||
resolvePRForBranchOutcome: provider.resolve
|
||||
}))
|
||||
vi.mock('../../execution/github-operation-slots', () => ({
|
||||
acquire: async () => {},
|
||||
release: () => {}
|
||||
}))
|
||||
|
||||
beforeEach(() => {
|
||||
moduleMocks.resetPRRefreshCoordinatorMocks(coordinatorMocks)
|
||||
provider.resolve.mockReset().mockImplementation(async () => ({
|
||||
kind: 'found',
|
||||
// ast-grep-ignore: test-no-wall-clock -- resetPRRefreshCoordinatorMocks installs fake timers
|
||||
fetchedAt: Date.now(),
|
||||
pr: makePR({ checksStatus: 'pending' })
|
||||
}))
|
||||
})
|
||||
afterEach(() => vi.useRealTimers())
|
||||
|
||||
it.each(['default', 'reduced', 'off'] as const)(
|
||||
'a return to a PR whose data is past the Default interval reads it under %s, then follows the timers',
|
||||
async (cadence) => {
|
||||
const policy = await import('../../../../shared/review-refresh-policy')
|
||||
policy.setPRAutoRefreshCadence(cadence)
|
||||
const coordinator = await import('./pr-refresh-coordinator')
|
||||
const candidate = makeCandidate({ isSelected: true, currentHeadOid: 'head-sha' })
|
||||
coordinator.reportVisiblePRRefreshCandidates([candidate], 1, 1)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(provider.resolve).toHaveBeenCalledTimes(1)
|
||||
|
||||
coordinator.clearVisiblePRRefreshWindow(1)
|
||||
await vi.advanceTimersByTimeAsync(90_000)
|
||||
coordinator.reportVisiblePRRefreshCandidates(
|
||||
[
|
||||
{
|
||||
...candidate,
|
||||
cachedFetchedAt: 1_000,
|
||||
cachedHeadOid: 'head-sha',
|
||||
cachedHasPR: true,
|
||||
cachedPRState: 'open',
|
||||
cachedChecksStatus: 'pending'
|
||||
}
|
||||
],
|
||||
2,
|
||||
1
|
||||
)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(provider.resolve).toHaveBeenCalledTimes(2)
|
||||
|
||||
// Default keeps its one-minute timer; Reduced waits five minutes and Off has none.
|
||||
await vi.advanceTimersByTimeAsync(4 * 60_000)
|
||||
expect(provider.resolve.mock.calls.length > 2).toBe(cadence === 'default')
|
||||
}
|
||||
)
|
||||
|
||||
it.each([
|
||||
['default', 5_000, 21_000],
|
||||
['reduced', 31_000, 91_000],
|
||||
['off', 31_000, 91_000]
|
||||
] as const)(
|
||||
'a settled PR shown again under %s reads only once past its settled age, and delivers the change without a timer after',
|
||||
async (cadence, earlyAt, dueAt) => {
|
||||
const policy = await import('../../../../shared/review-refresh-policy')
|
||||
policy.setPRAutoRefreshCadence(cadence)
|
||||
const coordinator = await import('./pr-refresh-coordinator')
|
||||
const settled = (title: string) => async () => ({
|
||||
kind: 'found',
|
||||
// ast-grep-ignore: test-no-wall-clock -- resetPRRefreshCoordinatorMocks installs fake timers
|
||||
fetchedAt: Date.now(),
|
||||
pr: makePR({ title, state: 'merged', checksStatus: 'success' })
|
||||
})
|
||||
provider.resolve.mockImplementation(settled('merged'))
|
||||
const candidate = makeCandidate({ currentHeadOid: 'head-sha' })
|
||||
coordinator.reportVisiblePRRefreshCandidates([candidate], 1, 1)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(provider.resolve).toHaveBeenCalledTimes(1)
|
||||
const shownAgain = {
|
||||
...candidate,
|
||||
cachedFetchedAt: 1_000,
|
||||
cachedHeadOid: 'head-sha',
|
||||
cachedHasPR: true,
|
||||
cachedPRState: 'merged' as const,
|
||||
cachedChecksStatus: 'success' as const
|
||||
}
|
||||
|
||||
// Shown again inside the settled age (10 s on Default, a minute otherwise): nothing is read.
|
||||
coordinator.clearVisiblePRRefreshWindow(1)
|
||||
await vi.advanceTimersByTimeAsync(earlyAt - 1_000)
|
||||
coordinator.reportVisiblePRRefreshCandidates([shownAgain], 2, 1)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(provider.resolve).toHaveBeenCalledTimes(1)
|
||||
|
||||
// Shown again past it: the cached answer cannot satisfy the earned read, the change arrives.
|
||||
coordinator.clearVisiblePRRefreshWindow(1)
|
||||
await vi.advanceTimersByTimeAsync(dueAt - earlyAt)
|
||||
provider.resolve.mockImplementation(settled('changed'))
|
||||
coordinator.reportVisiblePRRefreshCandidates([shownAgain], 3, 1)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(provider.resolve).toHaveBeenCalledTimes(2)
|
||||
expect(coordinatorMocks.sendToTrustedUIRendererMock.mock.calls.at(-1)?.[1]).toMatchObject({
|
||||
outcome: { pr: { title: 'changed' } }
|
||||
})
|
||||
await vi.advanceTimersByTimeAsync(60 * 60_000)
|
||||
expect(provider.resolve).toHaveBeenCalledTimes(2)
|
||||
}
|
||||
)
|
||||
|
||||
it('a settled PR shown again takes the answer another reader just fetched instead of reading again', async () => {
|
||||
const coordinator = await import('./pr-refresh-coordinator')
|
||||
const { getPRForBranchOutcome } = await import('../../client/lookup/pr-for-branch-outcome')
|
||||
const { hostedReviewOptionArgs } = await import('./pr-refresh-candidate-policy')
|
||||
const settled = (title: string) => async () => ({
|
||||
kind: 'found',
|
||||
// ast-grep-ignore: test-no-wall-clock -- resetPRRefreshCoordinatorMocks installs fake timers
|
||||
fetchedAt: Date.now(),
|
||||
pr: makePR({ title, state: 'merged', checksStatus: 'success' })
|
||||
})
|
||||
provider.resolve.mockImplementation(settled('merged'))
|
||||
const candidate = makeCandidate({ currentHeadOid: 'head-sha' })
|
||||
coordinator.reportVisiblePRRefreshCandidates([candidate], 1, 1)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
coordinator.clearVisiblePRRefreshWindow(1)
|
||||
await vi.advanceTimersByTimeAsync(20_000)
|
||||
|
||||
// Another reader of the same request reads it just before the row is shown again.
|
||||
provider.resolve.mockImplementation(settled('shared'))
|
||||
await coordinator.runHostedPRRead(candidate, () =>
|
||||
getPRForBranchOutcome(
|
||||
candidate.repoPath,
|
||||
candidate.branch,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
hostedReviewOptionArgs(candidate, 'visible')[0] ?? {}
|
||||
)
|
||||
)
|
||||
expect(provider.resolve).toHaveBeenCalledTimes(2)
|
||||
coordinator.reportVisiblePRRefreshCandidates(
|
||||
[
|
||||
{
|
||||
...candidate,
|
||||
cachedFetchedAt: 1_000,
|
||||
cachedHeadOid: 'head-sha',
|
||||
cachedHasPR: true,
|
||||
cachedPRState: 'merged',
|
||||
cachedChecksStatus: 'success'
|
||||
}
|
||||
],
|
||||
2,
|
||||
1
|
||||
)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(provider.resolve).toHaveBeenCalledTimes(2)
|
||||
expect(coordinatorMocks.sendToTrustedUIRendererMock.mock.calls.at(-1)?.[1]).toMatchObject({
|
||||
outcome: { pr: { title: 'shared' } }
|
||||
})
|
||||
})
|
||||
@@ -1,138 +0,0 @@
|
||||
import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const { gitExecFileAsyncMock } = vi.hoisted(() => ({
|
||||
gitExecFileAsyncMock: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('../../git/command-runner/git-exec-file', async (importOriginal) => ({
|
||||
...(await importOriginal<Record<string, unknown>>()),
|
||||
gitExecFileAsync: gitExecFileAsyncMock
|
||||
}))
|
||||
|
||||
vi.mock('../../git/command-runner/hosted-cli/gh-exec-file', async (importOriginal) => ({
|
||||
...(await importOriginal<Record<string, unknown>>()),
|
||||
ghExecFileAsync: vi.fn()
|
||||
}))
|
||||
|
||||
import { _resetRemoteNameListingCache } from '../../git/remotes/remote-name-listing'
|
||||
import {
|
||||
_getOwnerRepoCacheSize,
|
||||
_resetOwnerRepoCache,
|
||||
getOwnerRepoForRemote
|
||||
} from './github-repository-identity'
|
||||
import { getOwnerRepo } from './github-owner-repo-selection'
|
||||
import { __resetLocalGitConfigSignatureCacheForTests } from './local-git-config-signature'
|
||||
|
||||
function gitRemoteGetUrlCalls(remoteName: string): unknown[][] {
|
||||
return gitExecFileAsyncMock.mock.calls.filter(
|
||||
([args]) =>
|
||||
Array.isArray(args) && args[0] === 'remote' && args[1] === 'get-url' && args[2] === remoteName
|
||||
)
|
||||
}
|
||||
|
||||
describe('github owner/repo resolution', () => {
|
||||
beforeEach(() => {
|
||||
gitExecFileAsyncMock.mockReset()
|
||||
_resetOwnerRepoCache()
|
||||
_resetRemoteNameListingCache()
|
||||
__resetLocalGitConfigSignatureCacheForTests()
|
||||
})
|
||||
|
||||
it('keeps local host and local WSL owner/repo cache entries separate for the same path', async () => {
|
||||
gitExecFileAsyncMock.mockImplementation(
|
||||
async (args: string[], options: { wslDistro?: string } = {}) => {
|
||||
if (args[0] === 'remote' && args[1] !== 'get-url') {
|
||||
return { stdout: 'origin\n' }
|
||||
}
|
||||
if (args[2] === 'upstream') {
|
||||
throw new Error("fatal: No such remote 'upstream'")
|
||||
}
|
||||
return {
|
||||
stdout: options.wslDistro
|
||||
? 'git@github.com:wsl/orca.git\n'
|
||||
: 'git@github.com:host/orca.git\n'
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
await expect(getOwnerRepo('/repo')).resolves.toEqual({ owner: 'host', repo: 'orca' })
|
||||
await expect(getOwnerRepo('/repo', null, { wslDistro: 'Ubuntu' })).resolves.toEqual({
|
||||
owner: 'wsl',
|
||||
repo: 'orca'
|
||||
})
|
||||
await expect(getOwnerRepo('/repo', null, { wslDistro: 'Ubuntu' })).resolves.toEqual({
|
||||
owner: 'wsl',
|
||||
repo: 'orca'
|
||||
})
|
||||
|
||||
// 2 runtimes x (1 remote list + 1 origin hit); repeat WSL call is cached.
|
||||
expect(gitExecFileAsyncMock).toHaveBeenCalledTimes(4)
|
||||
expect(gitRemoteGetUrlCalls('upstream')).toHaveLength(0)
|
||||
expect(gitExecFileAsyncMock).toHaveBeenCalledWith(['remote', 'get-url', 'origin'], {
|
||||
cwd: '/repo',
|
||||
timeout: 30_000
|
||||
})
|
||||
expect(gitExecFileAsyncMock).toHaveBeenCalledWith(['remote', 'get-url', 'origin'], {
|
||||
cwd: '/repo',
|
||||
timeout: 30_000,
|
||||
wslDistro: 'Ubuntu'
|
||||
})
|
||||
})
|
||||
|
||||
it('does not apply the long negative TTL when git remote get-url fails transiently', async () => {
|
||||
const repoPath = await mkdtemp(join(tmpdir(), 'orca-gh-utils-'))
|
||||
await mkdir(join(repoPath, '.git'))
|
||||
await writeFile(join(repoPath, '.git', 'config'), '[core]\n\trepositoryformatversion = 0\n')
|
||||
try {
|
||||
gitExecFileAsyncMock
|
||||
.mockRejectedValueOnce(new Error('fatal: cannot lock ref'))
|
||||
.mockResolvedValueOnce({ stdout: 'git@github.com:acme/widgets.git\n' })
|
||||
|
||||
await expect(getOwnerRepoForRemote(repoPath, 'origin')).resolves.toBeNull()
|
||||
await expect(getOwnerRepoForRemote(repoPath, 'origin')).resolves.toEqual({
|
||||
owner: 'acme',
|
||||
repo: 'widgets'
|
||||
})
|
||||
expect(gitExecFileAsyncMock).toHaveBeenCalledTimes(2)
|
||||
} finally {
|
||||
await rm(repoPath, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('invalidates a cached local missing remote when an included git config changes', async () => {
|
||||
const repoPath = await mkdtemp(join(tmpdir(), 'orca-gh-utils-'))
|
||||
await mkdir(join(repoPath, '.git'))
|
||||
const includedConfigPath = join(repoPath, 'remote.inc')
|
||||
await writeFile(
|
||||
join(repoPath, '.git', 'config'),
|
||||
`[core]\n\trepositoryformatversion = 0\n[include]\n\tpath = ${includedConfigPath}\n`
|
||||
)
|
||||
await writeFile(includedConfigPath, '')
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
vi.setSystemTime(1_000)
|
||||
gitExecFileAsyncMock
|
||||
.mockRejectedValueOnce(new Error("error: No such remote 'origin'"))
|
||||
.mockResolvedValueOnce({ stdout: 'git@github.com:acme/widgets.git\n' })
|
||||
|
||||
await expect(getOwnerRepoForRemote(repoPath, 'origin')).resolves.toBeNull()
|
||||
await writeFile(
|
||||
includedConfigPath,
|
||||
'[remote "origin"]\n\turl = git@github.com:acme/widgets.git\n'
|
||||
)
|
||||
vi.setSystemTime(32_000)
|
||||
|
||||
await expect(getOwnerRepoForRemote(repoPath, 'origin')).resolves.toEqual({
|
||||
owner: 'acme',
|
||||
repo: 'widgets'
|
||||
})
|
||||
expect(gitExecFileAsyncMock).toHaveBeenCalledTimes(2)
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
await rm(repoPath, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user