Files
orca/src/shared/github/pull-request-for-branch-outcome.test.ts
T
Neilandpetersindex 82c5484f66 fix(github): scope PR selection and clear rejected cached links
Apply the default-branch policy while probing each repository, so an
integration PR cannot preempt a valid result or suppress the same number
in another repository. Check branch heads by repository and server.

Invalidate remote defaults when their review scope or SSH provider changes.
Report rejected PR URLs through an optional refresh-result field, so merged
integration PRs clear from both caches even at the current worktree head.
Share the manual and coordinator cache update implementation.

Co-authored-by: petersindex <287557875+petersindex@users.noreply.github.com>
2026-10-10 17:08:10 -07:00

51 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import type { PRRefreshOutcome } from './pull-request-refresh-types'
import type { PRInfo } from './pull-request-types'
import { normalizeGitHubPRForBranchOutcome } from './pull-request-for-branch-outcome'
const PR = {
number: 42,
title: 'Feature',
state: 'merged',
url: 'https://github.com/acme/orca/pull/42',
checksStatus: 'success',
updatedAt: '2026-08-04T22:46:08Z',
mergeable: 'UNKNOWN'
} as PRInfo
describe('normalizeGitHubPRForBranchOutcome', () => {
it('preserves current classified outcomes', () => {
const outcome: PRRefreshOutcome = { kind: 'found', pr: PR, fetchedAt: 10 }
expect(normalizeGitHubPRForBranchOutcome(outcome, 20)).toBe(outcome)
})
it.each([
{ kind: 'no-pr' as const, fetchedAt: 10 },
{ kind: 'no-pr' as const, fetchedAt: 10, rejectedPRUrls: [PR.url] }
])('preserves no-PR responses from older and newer hosts', (outcome) => {
expect(normalizeGitHubPRForBranchOutcome(outcome, 20)).toEqual(outcome)
})
it('normalizes legacy PRInfo and null responses', () => {
expect(normalizeGitHubPRForBranchOutcome(PR, 20)).toEqual({
kind: 'found',
pr: PR,
fetchedAt: 20
})
expect(normalizeGitHubPRForBranchOutcome(null, 20)).toEqual({
kind: 'no-pr',
fetchedAt: 20
})
})
it('preserves classified upstream errors', () => {
const outcome: PRRefreshOutcome = {
kind: 'upstream-error',
errorType: 'network',
message: 'network unavailable',
fetchedAt: 10
}
expect(normalizeGitHubPRForBranchOutcome(outcome, 20)).toBe(outcome)
})
})