fix: clear hosted review request generations (#4190)

This commit is contained in:
Neil
2026-05-31 07:31:15 -07:00
committed by GitHub
parent 19119cf729
commit 9972cdd9bb
2 changed files with 22 additions and 1 deletions
@@ -1,7 +1,12 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { create } from 'zustand'
import type { AppState } from '../types'
import { createHostedReviewSlice, getHostedReviewCacheKey } from './hosted-review'
import {
_clearHostedReviewRequestGenerationsForTest,
_getHostedReviewRequestGenerationCountForTest,
createHostedReviewSlice,
getHostedReviewCacheKey
} from './hosted-review'
import type { HostedReviewInfo } from '../../../../shared/hosted-review'
const runtimeRpc = vi.hoisted(() => ({
@@ -63,10 +68,12 @@ describe('hosted review cache revalidation', () => {
mockApi.hostedReview.getCreationEligibility.mockReset()
mockApi.hostedReview.create.mockReset()
runtimeRpc.callRuntimeRpc.mockReset()
_clearHostedReviewRequestGenerationsForTest()
})
afterEach(() => {
vi.useRealTimers()
_clearHostedReviewRequestGenerationsForTest()
})
it('dedupes repeated linked PR retries while a stronger lookup is in flight', async () => {
@@ -192,5 +199,6 @@ describe('hosted review cache revalidation', () => {
?.data
).toMatchObject({ title: 'feature/cache-500' })
expect(Object.keys(store.getState().hostedReviewCache)).toHaveLength(500)
expect(_getHostedReviewRequestGenerationCountForTest()).toBe(0)
})
})
@@ -36,6 +36,16 @@ const inflightHostedReviewRequests = new Map<
>()
const requestGenerations = new Map<string, number>()
/** @internal - exposed for leak-regression tests only */
export function _getHostedReviewRequestGenerationCountForTest(): number {
return requestGenerations.size
}
/** @internal - exposed for leak-regression tests only */
export function _clearHostedReviewRequestGenerationsForTest(): void {
requestGenerations.clear()
}
function isFresh<T>(entry: CacheEntry<T> | undefined): entry is CacheEntry<T> {
return entry !== undefined && Date.now() - entry.fetchedAt < CACHE_TTL_MS
}
@@ -340,6 +350,9 @@ export const createHostedReviewSlice: StateCreator<AppState, [], [], HostedRevie
const activeRequest = inflightHostedReviewRequests.get(cacheKey)
if (activeRequest?.generation === generation) {
inflightHostedReviewRequests.delete(cacheKey)
if (requestGenerations.get(cacheKey) === generation) {
requestGenerations.delete(cacheKey)
}
}
}
})()