feat(github): per-repo issue-source selector (#1317)

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Brennan Benson
2026-05-01 21:48:51 -07:00
committed by GitHub
co-authored by Orca
parent 2c7dddbbc4
commit 70befde774
19 changed files with 1316 additions and 123 deletions
+85 -19
View File
@@ -1,13 +1,20 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
const { handleMock, getPRForBranchMock, getIssueMock, listIssuesMock, getAuthenticatedViewerMock } =
vi.hoisted(() => ({
handleMock: vi.fn(),
getPRForBranchMock: vi.fn(),
getIssueMock: vi.fn(),
listIssuesMock: vi.fn(),
getAuthenticatedViewerMock: vi.fn()
}))
const {
handleMock,
getPRForBranchMock,
getIssueMock,
listIssuesMock,
listWorkItemsMock,
getAuthenticatedViewerMock
} = vi.hoisted(() => ({
handleMock: vi.fn(),
getPRForBranchMock: vi.fn(),
getIssueMock: vi.fn(),
listIssuesMock: vi.fn(),
listWorkItemsMock: vi.fn(),
getAuthenticatedViewerMock: vi.fn()
}))
vi.mock('electron', () => ({
ipcMain: {
@@ -19,6 +26,7 @@ vi.mock('../github/client', () => ({
getPRForBranch: getPRForBranchMock,
getIssue: getIssueMock,
listIssues: listIssuesMock,
listWorkItems: listWorkItemsMock,
getAuthenticatedViewer: getAuthenticatedViewerMock
}))
@@ -28,16 +36,17 @@ type HandlerMap = Record<string, (_event: unknown, args: unknown) => unknown>
describe('registerGitHubHandlers', () => {
const handlers: HandlerMap = {}
type FixtureRepo = {
id: string
path: string
displayName: string
badgeColor: string
addedAt: number
issueSourcePreference?: 'origin' | 'upstream'
}
let repos: FixtureRepo[] = []
const store = {
getRepos: () => [
{
id: 'repo-1',
path: '/workspace/repo',
displayName: 'repo',
badgeColor: '#000',
addedAt: 0
}
]
getRepos: () => repos
}
const stats = {
hasCountedPR: () => false,
@@ -49,11 +58,26 @@ describe('registerGitHubHandlers', () => {
getPRForBranchMock.mockReset()
getIssueMock.mockReset()
listIssuesMock.mockReset()
listWorkItemsMock.mockReset()
getAuthenticatedViewerMock.mockReset()
for (const key of Object.keys(handlers)) {
delete handlers[key]
}
// Reset fixture repos to the default single-repo fixture each test, so
// individual tests can mutate the list without leaking preferences across
// tests (e.g. a preference-threading test could otherwise shadow the
// default-undefined assertions in sibling tests).
repos = [
{
id: 'repo-1',
path: '/workspace/repo',
displayName: 'repo',
badgeColor: '#000',
addedAt: 0
}
]
handleMock.mockImplementation((channel, handler) => {
handlers[channel] = handler
})
@@ -95,7 +119,7 @@ describe('registerGitHubHandlers', () => {
limit: 5
})
expect(listIssuesMock).toHaveBeenCalledWith('/workspace/repo', 5)
expect(listIssuesMock).toHaveBeenCalledWith('/workspace/repo', 5, undefined)
expect(result).toEqual([])
})
@@ -123,10 +147,52 @@ describe('registerGitHubHandlers', () => {
limit: 5
})
expect(listIssuesMock).toHaveBeenCalledWith('/workspace/repo', 5)
expect(listIssuesMock).toHaveBeenCalledWith('/workspace/repo', 5, undefined)
expect(result).toEqual([])
})
it('threads issueSourcePreference through gh:listIssues', async () => {
// Why: repo.issueSourcePreference must reach listIssues so the upstream
// repo is queried when configured. A regression that drops the arg would
// pass the default-fixture tests (which assert `undefined`) silently, so
// this test pins the non-undefined preference-threading contract.
repos[0].issueSourcePreference = 'upstream'
listIssuesMock.mockResolvedValue({ items: [] })
registerGitHubHandlers(store as never, stats as never)
await handlers['gh:listIssues'](null, {
repoPath: '/workspace/repo',
limit: 5
})
expect(listIssuesMock).toHaveBeenCalledWith('/workspace/repo', 5, 'upstream')
})
it('threads issueSourcePreference through gh:listWorkItems', async () => {
// Why: gh:listWorkItems must also forward repo.issueSourcePreference
// (5th arg) so the work-items view honors the per-repo source selector.
repos[0].issueSourcePreference = 'origin'
listWorkItemsMock.mockResolvedValue({ items: [] })
registerGitHubHandlers(store as never, stats as never)
await handlers['gh:listWorkItems'](null, {
repoPath: '/workspace/repo',
limit: 10,
query: 'is:open',
before: 'cursor-1'
})
expect(listWorkItemsMock).toHaveBeenCalledWith(
'/workspace/repo',
10,
'is:open',
'cursor-1',
'origin'
)
})
it('forwards the authenticated viewer lookup', async () => {
getAuthenticatedViewerMock.mockResolvedValue({ login: 'octocat', email: 'octocat@example.com' })