fix: clear stale pr refresh backoff entries (#4207)
This commit is contained in:
@@ -427,6 +427,36 @@ describe('pr-refresh-coordinator', () => {
|
||||
expect(getPRForBranchOutcomeMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('clears visible retry backoff when a non-visible manual refresh steals the retry', async () => {
|
||||
const {
|
||||
_getPRRefreshErrorBackoffCountForTests,
|
||||
refreshPRNow,
|
||||
reportVisiblePRRefreshCandidates
|
||||
} = await import('./pr-refresh-coordinator')
|
||||
getPRForBranchOutcomeMock
|
||||
.mockResolvedValueOnce({
|
||||
kind: 'upstream-error',
|
||||
errorType: 'network',
|
||||
message: 'network down',
|
||||
fetchedAt: Date.now()
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
kind: 'found',
|
||||
pr: makePR({ checksStatus: 'success' }),
|
||||
fetchedAt: Date.now()
|
||||
})
|
||||
|
||||
const candidate = makeCandidate()
|
||||
reportVisiblePRRefreshCandidates([candidate], 1, 1)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(_getPRRefreshErrorBackoffCountForTests()).toBe(1)
|
||||
|
||||
getAllWebContentsMock.mockReturnValue([])
|
||||
await refreshPRNow(candidate)
|
||||
|
||||
expect(_getPRRefreshErrorBackoffCountForTests()).toBe(0)
|
||||
})
|
||||
|
||||
it('retries visible PRs with unknown mergeability before the success-check interval', async () => {
|
||||
const { reportVisiblePRRefreshCandidates } = await import('./pr-refresh-coordinator')
|
||||
getPRForBranchOutcomeMock
|
||||
|
||||
@@ -276,6 +276,9 @@ function scheduleVisibleFollowUp(
|
||||
windowId?: number
|
||||
): void {
|
||||
if (!isVisibleKey(key)) {
|
||||
// Why: manual/active refreshes can remove the queued visible retry after
|
||||
// its owner window is gone, leaving the retry backoff without an owner.
|
||||
errorBackoff.delete(key)
|
||||
return
|
||||
}
|
||||
if (outcome.kind === 'upstream-error') {
|
||||
@@ -582,6 +585,10 @@ export function _getVisiblePRRefreshWindowCountForTests(): number {
|
||||
return visibleByWindow.size
|
||||
}
|
||||
|
||||
export function _getPRRefreshErrorBackoffCountForTests(): number {
|
||||
return errorBackoff.size
|
||||
}
|
||||
|
||||
export async function refreshPRNow(candidate: GitHubPRRefreshCandidate): Promise<PRRefreshOutcome> {
|
||||
const alias = aliasFromCandidate(candidate)
|
||||
const key = refreshKey(candidate)
|
||||
|
||||
Reference in New Issue
Block a user