fix(github): align PR source and review head origin (#10677)

* fix(github): align PR source and review head origin

* fix(github): pin number-based work item open to the repo source preference

Open-by-number and details still ran the upstream-first multi-candidate PR
probe, so a fork and its upstream sharing a PR number opened different PRs
than the list and start-point paths did once #10677 pinned those to origin.

Thread repo.issueSourcePreference through dispatchWorkItem, getWorkItemDetails,
getRepoWorkItem, and getRepoWorkItemDetails. getWorkItemByOwnerRepo is left
alone: explicit owner/repo already pins identity. auto/upstream/undefined keep
the multi-candidate probe.

Co-authored-by: Orca <help@stably.ai>

* test(github): enforce origin preference in review head origin resolution

The explicit origin preference must short-circuit before any identity probe, so no remote queries should occur. Add validation to reject unexpected remotes and tighten the test assertion to verify no remote get-url calls happen at all.

* fix(github): enforce origin preference in issue open-by-number lookup

listWorkItems and getWorkItem must share preference so origin/upstream
toggles cannot disagree. Explicit origin preference now fail-closes when
origin identity is unresolved (no bare-lookup fallback), matching the
PR candidate resolution rule.

---------

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinjing
2026-07-25 22:48:53 -07:00
committed by GitHub
co-authored by Orca
parent 8cb45318d7
commit 33bd676644
18 changed files with 654 additions and 69 deletions
+38
View File
@@ -3530,6 +3530,44 @@ describe('getPRForBranch', () => {
})
})
it('pins explicit origin push-target lookup when upstream has the same PR number', async () => {
getOwnerRepoMock.mockResolvedValue({ owner: 'fork', repo: 'orca' })
resolvePRRepositoryCandidatesMock.mockResolvedValue({
candidates: [
{ owner: 'upstream', repo: 'orca' },
{ owner: 'fork', repo: 'orca' }
],
headRepo: { owner: 'fork', repo: 'orca' }
})
ghExecFileAsyncMock.mockResolvedValueOnce({
stdout: JSON.stringify({
head: {
ref: 'contributor/fix',
repo: {
full_name: 'contributor/orca',
name: 'orca',
clone_url: 'https://github.com/contributor/orca.git',
ssh_url: 'git@github.com:contributor/orca.git',
owner: { login: 'contributor' }
}
}
})
})
getRemoteUrlForRepoMock.mockResolvedValueOnce('git@github.com:fork/orca.git')
await getPullRequestPushTarget('/repo-root', 1738, null, {}, 'origin')
expect(resolvePRRepositoryCandidatesMock).not.toHaveBeenCalled()
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(['api', 'repos/fork/orca/pulls/1738'], {
cwd: '/repo-root',
host: 'github.com'
})
expect(ghExecFileAsyncMock).not.toHaveBeenCalledWith(
['api', 'repos/upstream/orca/pulls/1738'],
expect.anything()
)
})
it('surfaces maintainer_can_modify=false alongside a fork PR push target', async () => {
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
getOwnerRepoForRemoteMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })