From b0cd7e789fc19107f8e582ec0fa55fcd8b21f6b6 Mon Sep 17 00:00:00 2001 From: m4air Date: Sun, 13 Sep 2026 00:23:43 -0700 Subject: [PATCH] fix(github): preserve search budget on count fallback --- .../github/client/list/count-work-items.ts | 3 +++ ...k-item-search-fallback-environment.test.ts | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main/github/client/list/count-work-items.ts b/src/main/github/client/list/count-work-items.ts index c495615d016..570220586f9 100644 --- a/src/main/github/client/list/count-work-items.ts +++ b/src/main/github/client/list/count-work-items.ts @@ -47,6 +47,9 @@ export async function countWorkItemsForQuery( } } } + if (repositoryRateLimitGuard(ownerRepo, 'search', ghOptions).blocked) { + return 0 + } const { stdout } = await ghExecFileAsync( [ 'api', diff --git a/src/main/github/work-item-search-fallback-environment.test.ts b/src/main/github/work-item-search-fallback-environment.test.ts index 19910f151da..9f57048d9f6 100644 --- a/src/main/github/work-item-search-fallback-environment.test.ts +++ b/src/main/github/work-item-search-fallback-environment.test.ts @@ -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'