fix(github): preserve search budget on count fallback

This commit is contained in:
m4air
2026-09-13 00:23:43 -07:00
parent 8b093a388e
commit b0cd7e789f
2 changed files with 22 additions and 0 deletions
@@ -47,6 +47,9 @@ export async function countWorkItemsForQuery(
}
}
}
if (repositoryRateLimitGuard(ownerRepo, 'search', ghOptions).blocked) {
return 0
}
const { stdout } = await ghExecFileAsync(
[
'api',
@@ -4,6 +4,25 @@ import { listWorkItems } from './client/list/list-work-items'
import { countWorkItems } from './client/list/count-work-items'
import metadata from './__fixtures__/work-item-search-metadata.json'
it('preserves the Search budget floor when the preferred count fails', async () => {
api.restSearches = 29
api.aliasErrorRepo = 'fixture/repo'
expect(await countWorkItems('fixture/repo', 'is:issue')).toBe(0)
expect(api.calls.some((call) => call.args.includes('graphql'))).toBe(true)
expect(api.calls.some((call) => call.args.some((arg) => arg.startsWith('search/issues?')))).toBe(
false
)
expect(api.restSearches).toBe(29)
})
it('still counts through GraphQL when the REST Search budget is below its floor', async () => {
api.restSearches = 29
expect(await countWorkItems('fixture/repo', 'is:issue')).toBe(120)
expect(api.restSearches).toBe(29)
})
it('keeps REST fallback on the credential captured for the failed preferred search', async () => {
vi.stubEnv('GH_TOKEN', 'fixture-original-credential')
api.aliasErrorRepo = 'fixture/repo'