Files
orca/src/main/github/pull-requests/refresh/merged-pr-commit-membership.test.ts
T
Jinjing c9c1960ffb fix(github): discover configured push heads without unsafe merge claims (#41205)
* fix(github): attach PRs from configured push heads and rebased-away heads

Branch PR discovery only tried origin's same-named branch and %(upstream).
A fork reached through a separate pushurl, branch.<name>.pushRemote,
remote.pushDefault, or a push refspec publishing under another name never
matched, so the workspace never attached its PR.

- After those lookups miss, read where a plain push publishes the branch
  (the review branch source GitLab already uses) and look up that head's
  repository + branch. Push URLs resolve through SSH aliases and
  authenticated Enterprise hosts.
- A merged PR whose head was rebased and force-pushed from another
  checkout no longer lists the old commit in commits/{sha}/pulls; check
  the PR's force-push history so a checkout still at that commit keeps
  the merged PR.

* test(github): register push-head mocks at current feature owners

* style(github): consolidate repository probe imports

* fix(github): preserve exact push identity and uncertain review history

* test(github): verify upstream publication through a separate push URL

* fix(github): use fetch identity when resolving review default branches

* fix(github): separate historical association from merged containment proof

* fix(github): separate publish eligibility from existing review discovery

* fix(git): keep explicit refspec precedence in push destination proof

* fix(github): honor upstream admission and filtered force-push pagination

* fix(github): keep local and incomplete upstreams out of hosted push inference
2026-11-14 13:09:38 -08:00

82 lines
2.5 KiB
TypeScript

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')
})
})