ISSUE DESCRIPTION Tasks PR Upstream source still queries origin This was generated by AI…
- User
ISSUE DESCRIPTION
Tasks PR Upstream source still queries origin
This was generated by AI during triage.
Summary
In the Tasks page, selecting the
PRstab and choosingUpstreamin the source selector can showNo matching GitHub workeven when matching upstream PRs exist.The upstream/origin selector is visible in the PRs view, but the GitHub client still resolves PR list/count queries from
origin, sois:pr is:open author:@mesearches the fork/origin repo instead of the selected upstream repo.Reproduction
- Open a forked repository in Orca where
originpoints to the fork andupstreampoints to the canonical repo. - Open Tasks.
- Select
PRs. - Select
Upstreamin the source selector. - Use a PR-only query such as
is:pr is:open author:@me.
Actual behavior
The list can be empty with
No matching GitHub work, despite matching PRs existing in the upstream repository.Expected behavior
When
Upstreamis selected, PR list and PR count queries should use the upstream owner/repo, so the PRs tab returns matching upstream PRs.Code evidence
src/main/github/client.tsresolvesissueResolvedwith the selected preference, but resolvesprOwnerReposeparately viagetOwnerRepo(repoPath, connectionId), which is the origin repo.listWorkItemspasses thatprOwnerRepointo both recent and queried PR fetches.countWorkItemsuses the sameprOwnerRepofor PR count queries, so pagination/count can also be wrong.src/renderer/src/components/TaskPage.tsxrenders the selector usingorigin={s.sources.prs}andupstream={s.sources.upstreamCandidate}, which makes the control appear relevant in the PRs surface while the backend still routes PR queries to origin.
Suggested regression coverage
Add tests for:
listWorkItems('/repo-root', 10, 'is:pr is:open author:@me', undefined, 'upstream')using the upstream slug in--repo.countWorkItems('/repo-root', 'is:pr is:open author:@me', 'upstream')building a search query with .
- Open a forked repository in Orca where
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant files mentioned in the issue.
- Assistant
Let me look at the specific files mentioned in the issue:
src/main/github/client.tsandsrc/renderer/src/components/TaskPage.tsx. - Assistant
Let me examine these files to understand the issue.
- Assistant
Let me search for the
listWorkItemsandcountWorkItemsfunctions: - Assistant
Let me examine the
listWorkItemsfunction: - Assistant
Let me examine the
countWorkItemsfunction: - Assistant
Let me look at the
listRecentWorkItemsandlistQueriedWorkItemsfunctions: - Assistant
Let me examine those functions to understand how they use
prOwnerRepo: - Assistant
Let me examine the
listQueriedWorkItemsfunction: - Assistant
Let me look at the
buildWorkItemListArgsfunction: - Assistant
Let me look at that function:
- Assistant
Let me look at the
resolveIssueSourcefunction andgetOwnerRepoto understand the difference: - Assistant
Let me look at the
resolveIssueSourcefunction: - Assistant
Let me check the
getOwnerRepofunction: - Assistant
Let me check the
IssueSourcePreferencetype and theresolveIssueSourcereturn type: - Assistant
Let me look at the IssueSourcePreference type.
- Assistant
Now let me explore the test files to understand the testing pattern:
- Assistant
Let me check the existing work items test file:
- Assistant
Let me see more of the test file to understand the testing patterns better.
- Assistant
Let me look at
countWorkItemsForQuery: - Assistant
Let me examine the
resolveIssueSourcefunction ingh-utils.ts: - Assistant
Now let me examine the test file for work items to understand the testing patterns:
- Assistant
Now let me look at the issue source test file to understand how preference is tested:
- Assistant
Now I have a clear understanding of the issue. Let me examine the current code flow:
-
In
listWorkItems:issueResolved=resolveIssueSource(repoPath, preference, connectionId)- preference-awareprOwnerRepo=getOwnerRepo(repoPath, connectionId)- always origin, ignoring preference
-
In
countWorkItems:issueResolved=resolveIssueSource(repoPath, preference, connectionId)- preference-awareprOwnerRepo=getOwnerRepo(repoPath, connectionId)- always origin, ignoring preference
The fix: I need to create a
resolvePRSourcefunction similar toresolveIssueSourcethat respects the user's preference. Let me implement this step by step.First, let me look at the
gh-utils.tsfile more carefully to understand the structure: -
- Assistant
Let me also look at what's exported from
gh-utils.tsto see the existing pattern: - Assistant
Now I have a clear understanding of the issue. Let me trace through the code:
-
In
listWorkItems:prOwnerRepois always resolved viagetOwnerRepo(repoPath, connectionId)which always returns the origin remote, regardless of thepreferenceparameter. -
In
countWorkItems: Same issue -prOwnerRepoalways usesgetOwnerRepo.
The fix: Create a
resolvePRSourcefunction similar toresolveIssueSourcethat respects the upstream preference. Let me implement this step by step.First, let me add the
resolvePRSourcefunction togh-utils.ts: -
- Assistant
Let me see the full resolveIssueSource function and the end of gh-utils.ts:
- Assistant
Now let me look at the IPC layer and the TaskPage component to understand the full picture:
- Assistant
Let me check how the IPC layer passes the preference:
- Assistant
Now I have a complete understanding of the issue. Let me create a plan:
The Problem:
listWorkItemsandcountWorkItemsusegetOwnerRepo(repoPath, connectionId)for PR owner/repo resolution, which always returns the origin remoteresolveIssueSourcecorrectly handles the preference for issues, but there's no equivalent for PRs- When preference is 'upstream', PR queries should use the upstream remote
The Fix:
- Add a
resolvePRSourcefunction togh-utils.tsthat handles preference for PRs - Update
listWorkItemsandcountWorkItemsinclient.tsto useresolvePRSourceinstead ofgetOwnerRepo - Update tests
Let me implement this step by step:
- Assistant
Now let me add a
resolvePRSourcefunction togh-utils.ts. This will handle the preference for PR source resolution: - Assistant
Now let me add this function to the actual
gh-utils.tsfile right afterresolveIssueSource: - Assistant
Now let me add the
resolvePRSourcefunction togh-utils.ts: - Assistant
Let me check what was inserted:
- Assistant
I see there's a duplicate line. Let me fix that by removing the duplicate:
- Assistant
Let me verify the fix:
- Assistant
I see the closing brace for
resolveIssueSourceis missing. Let me fix this properly: - Assistant
I need to add the missing closing brace for
resolveIssueSource: - Assistant
Let me verify the file looks correct now:
- Assistant
Good. Now I need to update the
listWorkItemsandcountWorkItemsfunctions inclient.tsto useresolvePRSourceinstead ofgetOwnerRepo. Let me update the imports first: - Assistant
Let me look at the import statement in client.ts:
- Assistant
Now let me add
resolvePRSourceto the import statement: - Assistant
Now let me update the
listWorkItemsfunction to useresolvePRSource: - Assistant
Now I need to update the
listWorkItemsfunction to useresolvePRSourceinstead ofgetOwnerRepo: - Assistant
Now I need to replace these lines:
- Assistant
Let me verify the change was made correctly:
- Assistant
Good. Now I need to update the
countWorkItemsfunction similarly: - Assistant
I need to update line 1357 (the
getOwnerRepo(repoPath, connectionId)line incountWorkItems) to useresolvePRSource(repoPath, preference, connectionId). - Assistant
Now let me verify the change was made correctly in countWorkItems:
- Assistant
Now I need to update the test files to mock
resolvePRSource. Let me first check theclient-work-items.test.tsfile: - Assistant
Let me look at the mock in client-work-items.test.ts:
- Assistant
I need to add
resolvePRSourcemock to the test file. Let me first add the hoisted variable and then update the mock: - Assistant
Now let me update the test files. First, let me open the work items test file:
- Assistant
Now I need to update the test file to add the
resolvePRSourcemock. Let me make the edits: - Assistant
Now I need to add
resolvePRSource: resolvePRSourceMockto the mock and add reset/setup in beforeEach: - Assistant
Now I need to add
resolvePRSourceMock.mockReset()to beforeEach and setup a default mock implementation: - Assistant
Good. Now I need to update the
client-issue-source.test.tsfile as well: - Assistant
Now I need to update the
client-issue-source.test.tsfile similarly. Let me addresolvePRSourceMockto the hoisted variables and mock: - Assistant
Now I need to add
resolvePRSource: resolvePRSourceMockto the mock and add reset/setup in beforeEach: - Assistant
Now I need to add
resolvePRSourceMock.mockReset()and default mock implementation to beforeEach: - Assistant
Now let me look at the specific tests that verify the 'upstream' preference to see if they need to be updated. The key test is "preference='upstream' + upstream exists → queries upstream":
- Assistant
Let me look at the specific test that needs updating:
- Assistant
The test at line 469 needs to be updated. When preference is 'upstream', PRs should now also come from upstream. Let me update it:
- Assistant
I see the next test got garbled. Let me check what happened:
- Assistant
I see the issue. The replacement removed part of the next test. Let me fix this:
- Assistant
Good. Now let me run the existing tests to see if they pass:
- Assistant
The test command timed out due to environment setup. Let me try running it directly with npx vitest:
- Assistant
Good, the work items test passes. Now let me run the issue source test:
- Assistant
There's one failing test that expects
getOwnerRepoMockto be called but nowresolvePRSourceMockis being called instead. Let me look at that test: - Assistant
The test expects
getOwnerRepoMockto be called but nowresolvePRSourceMockis being called instead. Since the test is checking SSH repo behavior with'auto'preference, I need to update it to useresolvePRSourceMock: - Assistant
Now let me run the test again to see if it passes:
- Assistant
Both tests pass. Now let me run all the GitHub-related tests to make sure nothing is broken:
- Assistant
All tests pass. Now let me check if there are any other test files that might be affected:
- Assistant
The other test files are testing different functions (like
createGitHubPullRequest), notlistWorkItemsorcountWorkItems, so they don't need updating. Let me also check the IPC layer to see if there are any changes needed there: - Assistant
Let me also run the IPC tests to make sure nothing is broken there:
- Assistant
All tests pass. Now let me also run the
gh-utils.test.tsto make sure the new function doesn't break anything: - Assistant
Let me also check if there are other places in the codebase that might need updating for consistency:
- Assistant
Let me also check if there are any TypeScript compilation errors:
- Assistant
Good, no TypeScript errors. Now let me also verify the TaskPage.tsx component to see if it needs any changes:
- Assistant
The TaskPage.tsx component doesn't need changes - it's the backend that was incorrectly routing PR queries. Let me also run any remaining related tests to make sure nothing is broken:
- Assistant
All tests pass. Let me now also check if there are any other functions in
client.tsthat might need similar updates. Let me look at thegetWorkItemfunction: - Assistant
Let me check the
getWorkItemfunction to see if it also needs updating: - Assistant
The
getWorkItemfunction is used for individual item lookups (by number), not for listing or counting. It doesn't take apreferenceparameter, so it doesn't need updating. The issue description specifically mentionslistWorkItemsandcountWorkItems, which I've already fixed.Let me do a final review of all the changes I've made:
- Assistant
Let me look at the full diff to review all changes:
- Assistant
The diff looks good. Let me run the full test suite one more time to make sure everything is working:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.