test(github): cover persist, hydrate, and complete open-list misses

Add store persist/hydrate regressions for terminal branch associations
and a server test that a complete empty open list does not query closed
PRs. Inline the open-only matcher state so the next repo target can win.

Co-authored-by: serkraser <serkraser@gmail.com>
This commit is contained in:
Cursor Agent
2026-08-15 04:27:52 +00:00
co-authored by serkraser
parent 5e9e35897f
commit 13cbbc76d7
3 changed files with 120 additions and 7 deletions
+4 -7
View File
@@ -514,14 +514,11 @@ const findFirstMatchingPr = async ({ octokit, target, branch, sourceCandidates,
// Branch status associates the current head with an open PR only. Returning a
// closed/merged PR here made the client cache a terminal status that could not
// self-heal until a manual forced refresh.
const state = 'open';
// Shared per-repo list first: one pulls.list answers every branch of the
// repo within the TTL. A miss in a complete list is authoritative — skip
// the per-branch query fan entirely.
// self-heal until a manual forced refresh. A miss also lets the next repo
// target run, so an open upstream PR wins over a merged fork PR.
let listWasComplete = false;
try {
const listEntry = await getRepoPulls(octokit, target.repo, state, { force });
const listEntry = await getRepoPulls(octokit, target.repo, 'open', { force });
const fromList = pickPreferred(listEntry.prs);
if (fromList) {
return fromList;
@@ -539,7 +536,7 @@ const findFirstMatchingPr = async ({ octokit, target, branch, sourceCandidates,
const directCandidates = await safeListPulls(octokit, {
owner: target.repo.owner,
repo: target.repo.repo,
state,
state: 'open',
head: `${owner}:${branch}`,
per_page: 100,
});
@@ -86,4 +86,20 @@ describe('findFirstMatchingPr open-only branch status', () => {
expect(listMock.mock.calls.every((call) => call[0]?.state === 'open')).toBe(true);
expect(listMock.mock.calls.some((call) => call[0]?.state === 'closed')).toBe(false);
});
test('does not query closed PRs when the open list is complete and empty', async () => {
listMock.mockImplementation(async () => ({ data: [] }));
const pr = await findFirstMatchingPr({
octokit: { rest: { pulls: { list: listMock } } },
target: { repo: { owner: 'acme', repo: 'app' }, remoteName: 'origin' },
branch: 'feature',
sourceCandidates: [{ repo: { owner: 'acme', repo: 'app' } }],
force: true,
});
expect(pr).toBeNull();
expect(listMock.mock.calls).toHaveLength(1);
expect(listMock.mock.calls[0]?.[0]?.state).toBe('open');
});
});