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 description.
- Assistant
Let me find the specific files mentioned in the issue description:
- Assistant
Let me look at the main files mentioned in the issue:
src/main/github/client.tsandsrc/renderer/src/components/TaskPage.tsx. - Assistant
Let me examine the GitHub client.ts file to understand how
listWorkItemsandcountWorkItemswork, and how they handleprOwnerRepoand upstream selection. - Assistant
Let me examine the
listWorkItemsfunction and surrounding code to understand the issue. - Assistant
Let me continue viewing the countWorkItems function to see how it handles preferences.
- Assistant
Now I see the issue clearly. In both
listWorkItemsandcountWorkItems,prOwnerRepois always resolved usinggetOwnerRepo(repoPath, connectionId), which returns the origin repo. Thepreferenceparameter is only used for issues (viaresolveIssueSource), but not for PRs.Let me check the
resolveIssueSourcefunction to understand how it handles preferences: - Assistant
Let me look at the
resolveIssueSourcefunction to understand how it handles preferences. - Assistant
Let me look at the
gh-utils.tsfile whereresolveIssueSourceis likely defined. - Assistant
Let me examine the
resolveIssueSourcefunction to understand how it resolves the source based on the preference. - Assistant
Now I understand the issue. The
resolveIssueSourcefunction correctly handles the preference for issues, butprOwnerRepois always resolved usinggetOwnerRepo(repoPath, connectionId)which always returns the origin repo. Let me check whatgetOwnerRepodoes: - Assistant
Let me check what
getOwnerRepodoes: - Assistant
Now I understand the issue.
getOwnerRepo()always returns the origin repo. InlistWorkItems, thepreferenceparameter is used to resolve the issue source (issues), but PRs always usegetOwnerRepo()which returns origin.The fix should be to resolve the PR source based on the
preferenceas well. Let me check whatlistRecentWorkItemsandlistQueriedWorkItemsdo withprOwnerRepo.Let me also look at the
listRecentWorkItemsandlistQueriedWorkItemsfunctions. - Assistant
Let me look at the listRecentWorkItems and listQueriedWorkItems functions.
- Assistant
Now let me look at the
listQueriedWorkItemsfunction. - Assistant
Let me understand the issue better. Looking at the
listWorkItemsfunction, I can see that:issueResolvedis resolved withresolveIssueSource(repoPath, preference, connectionId)which properly handlespreference='upstream'prOwnerRepois resolved withgetOwnerRepo(repoPath, connectionId)which always returns the origin repo- The
prOwnerRepois then passed tolistRecentWorkItemsandlistQueriedWorkItemswhich use it for PR queries
The issue is that
prOwnerRepodoesn't respect thepreferenceparameter. Whenpreference='upstream', PRs should be fetched from the upstream repo, not origin.Similarly for
countWorkItems,prOwnerRepois resolved withgetOwnerRepo(repoPath, connectionId)which always returns origin.Let me look at the test files to understand the expected behavior.
- Assistant
Let me check the existing test file to understand the expected behavior and test structure.
- Assistant
Now I need to understand the issue more deeply. Let me look at how the preference parameter flows through the system and where the PR owner/repo should be resolved based on preference.
- Assistant
Let me look at the
resolveIssueSourcefunction more carefully and see if we need a similar function for PRs. - Assistant
Let me look at the full
resolveIssueSourcefunction and understand the pattern: - Assistant
Now I understand the issue. The
resolveIssueSourcefunction correctly handles thepreferenceparameter, butprOwnerRepois always resolved viagetOwnerRepo()which always returns origin. I need to create a similar function for PRs.Let me first check the current state of the files and understand the test structure better:
- Assistant
Let me look at the existing test file for work items more thoroughly to understand the patterns:
- Assistant
Let me search for existing tests that use the 'upstream' preference to see if there are any existing tests for this specific case.
- Assistant
Let me check if there are tests for the preference parameter at all:
- Assistant
Now I understand the issue. The
prOwnerRepois always resolved viagetOwnerRepo()which returns origin, regardless of thepreferenceparameter. Whenpreference === 'upstream', it should use the upstream remote instead.Let me create a reproduction script first to verify the issue:
- Assistant
Let me look at the existing tests more carefully to understand the patterns and then make the necessary changes.
Let me look at how
buildWorkItemListArgsuses ownerRepo: - Assistant
Let me look at the buildWorkItemListArgs function:
- Assistant
Let me look at the
countWorkItemsForQueryfunction to understand how it usesownerRepo: - Assistant
Let me look at the
countWorkItemsfunction more carefully to see the full picture: - Assistant
Let me check what
IssueSourcePreferencetype is: - Assistant
Now I understand the full picture. The issue is that when
preference === 'upstream', the PR owner/repo should be resolved from the upstream remote, but currently it's always resolved from origin. I need to create aresolvePRSourcefunction similar toresolveIssueSourceand use it inlistWorkItemsandcountWorkItems.Let me look at the
getOwnerRepoForRemotefunction: - Assistant
Let me check the test file to see how the tests are structured:
- Assistant
Now I have a clear understanding of the issue. Let me implement the fix. I'll create a
resolvePRSourcefunction ingh-utils.tsthat handles the preference for PRs similar to howresolveIssueSourcehandles it for issues, then modifylistWorkItemsandcountWorkItemsto use it.Let me first look at the exports from
gh-utils.tsto understand what's available: - Assistant
Let me look at the
ResolvedIssueSourcetype to understand its structure: - Assistant
Now I have a clear understanding of the issue and the fix needed. Let me plan my approach:
- Create a
resolvePRSourcefunction ingh-utils.tssimilar toresolveIssueSourcethat resolves the PR source based on the preference - Update
listWorkItemsinclient.tsto useresolvePRSourceinstead of justgetOwnerRepoforprOwnerRepo - Update
countWorkItemsinclient.tsto useresolvePRSourceinstead of justgetOwnerRepoforprOwnerRepo - Add tests to verify the fix works correctly
Let me start by creating the
resolvePRSourcefunction ingh-utils.ts: - Create a
- Assistant
Let me look at the
resolveIssueSourcefunction and add a similarresolvePRSourcefunction right after it. - Assistant
Now I'll add a
resolvePRSourcefunction that mirrorsresolveIssueSourcebut for PRs. The logic is similar: when preference is 'upstream', use upstream; when 'origin', use origin; when auto/undefined, use origin (default behavior for PRs). - Assistant
Let me check the file to see what happened with the edit:
- Assistant
Let me check the area around line 393 to see if the
resolveIssueSourcefunction is properly closed: - Assistant
I see the issue - the closing brace of
resolveIssueSourcegot removed. Let me fix that. - Assistant
I see there's a duplicate return line. Let me fix that.
- Assistant
There are issues with the file now. Let me fix it properly.
- Assistant
I see the issue - there's a duplicate comment and an extra closing brace. Let me fix this properly.
- Assistant
Good, the
resolvePRSourcefunction has been added togh-utils.ts. Now I need to updateclient.tsto import and use it. Let me check the imports: - Assistant
Now I need to add
resolvePRSourceto the import list. Let me update the import statement. - Assistant
I see that the edit command edited the wrong file - it edited
gh-utils.tsinstead ofclient.ts. Let me fix this: - Assistant
Now I need to add
resolvePRSourceto the import list in client.ts: - Assistant
Good, the import has been added. Now I need to modify the
listWorkItemsandcountWorkItemsfunctions to useresolvePRSourceinstead ofgetOwnerRepowhen resolvingprOwnerRepo. Let me look at thelistWorkItemsfunction again: - Assistant
Now I need to update the
listWorkItemsfunction to useresolvePRSourceinstead ofgetOwnerRepoforprOwnerRepo. Let me make the change: - Assistant
I see there's a duplicate in the file. Let me fix it:
- Assistant
I see the issue - there's duplicate text. Let me fix it properly:
- Assistant
Good, now I need to update the
countWorkItemsfunction similarly. Let me look at it: - Assistant
Now I need to update the
countWorkItemsfunction to useresolvePRSourceinstead ofgetOwnerRepo: - Assistant
I see there's a duplicate line. Let me fix it:
- Assistant
Let me look at the duplicate line:
- Assistant
There's a duplicate line. Let me fix it:
- Assistant
Now let me verify the gh-utils.ts file is correct:
- Assistant
The edit to gh-utils.ts was incorrectly applied - it modified the wrong location (the classifyGhError comment text). Let me check and fix:
- Assistant
The gh-utils.ts file is messed up from the earlier accidental edit. Let me restore it:
- Assistant
Good, the file has been restored. Now let me add the
resolvePRSourcefunction to gh-utils.ts properly: - Assistant
Now let me navigate to the end of the file to add the resolvePRSource function:
- Assistant
Now let me add the
resolvePRSourcefunction at the end of the file: - Assistant
Good, now let me verify both files are correct:
- Assistant
Good, gh-utils.ts looks correct. Let me verify the client.ts changes:
- Assistant
Wait, that's showing the wrong file. Let me check the client.ts imports:
- Assistant
Good, the import is there. Let me verify the listWorkItems function:
- Assistant
Good, the listWorkItems function looks correct. Let me verify the countWorkItems function:
- Assistant
Both functions are now properly updated to use
resolvePRSource. Now let me run the existing tests to make sure I haven't broken anything: - Assistant
Let me try running the test directly with vitest
- Assistant
The tests are failing because the mock doesn't include
resolvePRSource. I need to update the test file to add the mock forresolvePRSource. Let me look at the test file to see how it's structured: - Assistant
I need to add the
resolvePRSourcemock to the test file. Let me update it to add the mock and make it usegetOwnerRepoMockby default: - Assistant
The edit command edited the wrong file again. Let me fix this by opening the test file directly:
- Assistant
I need to re-apply the changes to client.ts since I reverted it. Let me do it more carefully using
--fileoption: - Assistant
Let me use sed to make the changes to client.ts to avoid the issue with the edit command editing the wrong file:
- Assistant
Now let me make the changes to the
listWorkItemsandcountWorkItemsfunctions in client.ts: - Assistant
Good, the import is added. Now let me update the listWorkItems function:
- Assistant
I need to change the listWorkItems function to use resolvePRSource. Let me use sed:
- Assistant
Let me verify the changes to the listWorkItems function:
- Assistant
Good, the listWorkItems function is updated. Now let me update the countWorkItems function:
- Assistant
I need to update the countWorkItems function. Let me find the exact line numbers:
- Assistant
Now let me update the countWorkItems function to use resolvePRSource:
- Assistant
Let me verify the changes to the countWorkItems function:
- Assistant
Good, the countWorkItems function is updated. Now I need to add the
resolvePRSourcemock to the test file. Let me open the test file: - Assistant
I need to add
resolvePRSourceMockto the test file. Let me update it: - Assistant
Now I need to add the mock definition for
resolvePRSourceMockin the vi.hoisted block: - Assistant
I see that
resolvePRSourceMockwas added to the destructuring but not to the vi.hoisted() call. Let me add it there too: - Assistant
Now I need to add
resolvePRSourceto the vi.mock call: - Assistant
I need to add
resolvePRSource: resolvePRSourceMockafter the resolveIssueSource line in the vi.mock call: - Assistant
Now I need to update the beforeEach to reset and set up the mock. Let me check the beforeEach section:
- Assistant
Now I need to add the reset and mockImplementation for resolvePRSourceMock. Let me add them:
- Assistant
Now I need to add the mockImplementation for resolvePRSourceMock. Let me find the right place to add it:
- Assistant
Let me check what's around that line:
- Assistant
Now I need to add the resolvePRSourceMock implementation after the resolveIssueSourceMock implementation:
- Assistant
Let me verify the test file looks correct now:
- Assistant
Good, the test file is updated. Now let me run the tests to see if they pass:
- Assistant
All existing tests pass. Now let me add the new tests as suggested in the issue description. Let me 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 withrepo:<upstream-owner>/<repo>.
Let me add these tests to the test file:
- Assistant
Let me add the new tests before the SSH test. Let me first look at the pattern for countWorkItems tests:
- Assistant
Let me look at one of the countWorkItems tests to understand the pattern:
- Assistant
Now let me add the new tests. Let me add them before the SSH test at line 636:
- Assistant
Now let me add the new tests before the SSH test:
- Assistant
Let me verify the test file looks correct now:
- Assistant
Good, the tests are added. Now let me run the tests to see if they pass:
- Assistant
All 14 tests pass. Now let me also check if the gh-utils test file needs updating for the new
resolvePRSourcefunction: - Assistant
Let me check if there are tests for resolveIssueSource in gh-utils.test.ts that I should also update for resolvePRSource:
- Assistant
I should also add tests for
resolvePRSourcein the gh-utils.test.ts file. Let me look at the structure: - Assistant
Let me check if
resolvePRSourceis imported in the test file: - Assistant
I need to add
resolvePRSourceto the import list and add tests for it. Let me update the test file: - Assistant
Let me verify the import was added correctly:
- Assistant
Good, the import is added. Now let me add tests for
resolvePRSourceafter theresolveIssueSourcetests. Let me find where the resolveIssueSource tests end: - Assistant
Now let me add the tests for
resolvePRSourcebefore line 361: - Assistant
Let me add the tests for
resolvePRSourcebefore line 361: - Assistant
Let me verify the tests were added correctly:
- Assistant
Good, the tests are added. Let me run the gh-utils tests to see if they pass:
- Assistant
The test has a syntax error. The quotes are not properly escaped. Let me fix them:
- Assistant
I see the issue - the quotes are malformed. Let me rewrite the test section properly:
- Assistant
Let me use node to fix the test file:
- Assistant
Let me verify the fix was applied correctly:
- Assistant
There's an extra
)after the closing})of the describe block. Let me fix that: - Assistant
Let me verify the fix:
- Assistant
Let me check the end of the resolvePRSource describe block:
- Assistant
Good, the test file looks correct now. Let me run the tests again:
- Assistant
I see. The test expectations for 'auto' and 'undefined' are wrong. For
resolvePRSource, when preference is 'auto' or undefined, it callsgetOwnerRepo()which only queries theoriginremote. Let me look at howgetOwnerRepoForRemoteworks: - Assistant
I see - the test mocks are wrong. For
'auto'andundefinedpreference inresolvePRSource, it callsgetOwnerRepo()which only queries origin. So we only need one mock call. Let me fix the tests: - Assistant
Let me run the tests again to see if they pass now:
- Assistant
All 27 tests pass. Now let me run both test files together to make sure everything works:
- Assistant
All tests pass. Let me also check if there are other test files that might be affected by our changes:
- Assistant
The issue is that
client-issue-source.test.tsalso mocks modules but doesn't includeresolvePRSource. Let me check it: - Assistant
I see - this test file also needs to add the
resolvePRSourceMock. Let me update it: - Assistant
I need to add
resolvePRSourceMockto client-issue-source.test.ts. Let me update it: - Assistant
I need to add
resolvePRSourceMockto this test file. Let me update it: - Assistant
Good, I added
resolvePRSourceMockto the destructuring. Now I need to add it to the vi.hoisted call: - Assistant
Good, I added
resolvePRSourceMockto the vi.hoisted call. Now I need to addresolvePRSource: resolvePRSourceMockto the vi.mock call: - Assistant
Good, I added
resolvePRSource: resolvePRSourceMockto the vi.mock call. Now I need to add the reset and mockImplementation to the beforeEach: - Assistant
Good, I added
resolvePRSourceMock.mockReset(). Now I need to add the mock implementation forresolvePRSourceMock. Let me add it after the resolveIssueSourceMock.mockImplementation: - Assistant
I see there's a duplicate
resolveIssueSourceMock.mockImplementationblock. Let me fix that: - Assistant
I see there's a duplicate and broken code. Let me fix it:
- Assistant
Good, the test file looks correct now. Let me run the tests to see if they pass:
- Assistant
There's still a failure in a test that expects
getOwnerRepoMockto be called. Since we now callresolvePRSourceinstead, the test needs to be updated. Let me look at that test: - Assistant
The test at line 189 checks that
getOwnerRepoMockwas called directly. Since we now callresolvePRSourceinstead, this assertion will fail. But the instructions say "If existing tests break because they need to be updated to reflect the changes you made, just ignore it." So this is expected.Let me also check for other test files that might need updating:
- Assistant
Good - only 1 test fails, and it's the expected one that checks
getOwnerRepoMockwas called directly. Since the instructions say to ignore tests that break because they need to be updated to reflect the changes made, this is fine.Let me also check if there are other test files that might be affected:
- Assistant
The github.test.ts failure is a native module issue unrelated to our changes. Let me also run the renderer tests to make sure nothing is broken:
- Assistant
All 90 tests in the renderer pass. Let me now do a final check on the changes I made:
- Assistant
Good, the changes look clean. Let me verify all the core changes are correct by reviewing them:
- Assistant
The gh-utils.ts change looks correct. Let me also check the client.ts changes:
- Assistant
The client.ts changes look correct. Let me now run all the key tests one more time to make sure everything is working:
- Assistant
All tests pass. Let me now create a summary of the changes I made and submit them.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.