Files
orca/src/main/ipc/github-issue-source-preference.test.ts
T
Neil 7980ab9942 test: remove mock echoes and duplicate contracts that only reading finds (#23953)
* test: remove mock echoes and duplicate contracts that only reading finds

Two veins in one wave, both requiring the production path to be read rather than
pattern-matched.

Mock echoes (36 strongest candidates reviewed, 2 real): the flagged shape —
literals shared between a mock factory and an expect matcher — is almost always
a test feeding an input and asserting a transform. The two genuine echoes are in
`pty-management.test.ts`, where the handler returns
`getDaemonFolderAccessMismatch(identity)` verbatim, so asserting the mock's own
`evidence('allowed')` object and its `null` proved only the mock. One case's own
comment conceded the handler makes no decision. The branch-exercising cases in
that file stay.

Semantic sweep of 80 files no detector flagged, 27 junk cases removed. What it
found has no mechanical signature:
- a handler that is literally `() => getComputerUsePermissionStatus()`, so
  `resolves.toBe(result)` guarded nothing;
- "does not mutate a stale registration off Linux" whose refusal came from a
  DIFFERENT guard — `cli.ts` has no platform check, and the test's own mock made
  `resolveAppImageRuntimeIdentity` return null, which a sibling case already owns;
- "keeps probing a host that is still retained" asserting a no-op, because
  `retainScopes` only cancels queued probes and stores no state;
- two cases comparing against `referenceAllowedRoots`, a verbatim copy of the
  pre-change algorithm kept in the test file — expected values produced by the
  thing under test. The third such case stays: it calls the old algorithm to
  COUNT its work (100_000 containment checks vs 100), a real bound on the
  authorization hot path;
- a remote-folder refusal that came from the fake provider's own rejection
  message rather than any Orca guard;
- "advertises each capability once", where a duplicate entry is inert in
  production because membership is `includes`;
- an Antigravity `scaffold self-check` built on a hand-typed five-line screen —
  the exact fixture shape docs/reference/antigravity-readiness-evidence.md blames
  for five failed detector attempts — whose banner had already drifted to
  `Antigravity CLI 1.0.3` against a real captured `1.2.0`. The raw-capture
  provenance guard and the transcript checklist ratchet in that file stay.

No production file is touched and no test file is deleted.

* test: retire duplicate daemon and filesystem cases the sweep found

Continues the semantic sweep into src/main/ipc filesystem handlers and
src/main/daemon. 16 cases removed across 13 files; no production file touched.

The recurring shape is a case that reaches the same branch as its sibling by a
different-looking route:
- `parseArgs` is a flag-scanning loop, so "handles flags in any order" asserts the
  identical result object as the in-order case, and "throws with no args" lands on
  the same `Usage:` throw the two missing-flag cases already reach;
- an ENOENT case with "no code at all" and its sibling with a numeric transport
  code both fall through to the same `ENOENT_MESSAGE.test` branch;
- "establishes connection with hello handshake" and "receives stream events" are
  strict subsets of cases that require two matching authenticated sockets and a
  frame split inside a multibyte character.

Two were vacuous rather than duplicated: a fixture self-comparison asserting
`String.normalize` gives different NFC and NFD spellings, and a
`not.toThrow` batch case whose 200k events are truncated by
`MAX_BATCHED_WATCHER_EVENTS = 5_000` long before the argument spread it was
written to exercise.

One whole-file deletion was reversed: `freebuff-detection.test.ts` looked like a
table restatement, but the sibling detection test covers only dependency ordering
and platform gating, not freebuff/codebuff independence — and those two names
share a suffix, so it is the only guard against one shadowing the other.
2026-09-29 17:35:12 -07:00

147 lines
4.7 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
const mocks = await vi.hoisted(async () => {
const { createGitHubIpcMocks } = await import('./github-ipc-module-mocks')
return createGitHubIpcMocks()
})
vi.mock('electron', () => mocks.electron)
vi.mock('../github/client', () => mocks.client)
vi.mock('../github/work-item-details', () => mocks.workItemDetails)
vi.mock('../github/pr-refresh-coordinator', () => mocks.prRefresh)
vi.mock('../telemetry/client', () => mocks.telemetry)
vi.mock('../telemetry/cohort-classifier', () => mocks.cohort)
vi.mock('./ui', () => mocks.ui)
import { registerGitHubHandlers } from './github'
import { createGitHubIpcHarness } from './github-ipc-test-harness'
const {
listIssues: listIssuesMock,
listWorkItems: listWorkItemsMock,
getWorkItem: getWorkItemMock
} = mocks.client
const { getWorkItemDetails: getWorkItemDetailsMock } = mocks.workItemDetails
describe('registerGitHubHandlers', () => {
const harness = createGitHubIpcHarness(mocks)
const { handlers, store, stats } = harness
beforeEach(harness.reset)
it('drops the error field from listIssues envelope at the IPC boundary', async () => {
// Why: src/main/ipc/github.ts intentionally unwraps the { items, error? }
// envelope to just `items` to preserve the pre-feature-1
// `Promise<IssueInfo[]>` contract for `gh:listIssues`. Feature 1's UI
// consumes the richer envelope through `gh:listWorkItems` instead. This
// test locks in that intentional drop so a future change that starts
// propagating the error through this channel (or that throws when an
// error is present) is caught.
listIssuesMock.mockResolvedValue({
items: [],
error: {
type: 'permission_denied',
message:
"You don't have permission to read issues for this repository. Check your GitHub token scopes."
}
})
registerGitHubHandlers(store as never, stats as never)
const result = await handlers['gh:listIssues'](null, {
repoPath: '/workspace/repo',
limit: 5
})
expect(listIssuesMock).toHaveBeenCalledWith('/workspace/repo', 5, undefined, null)
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.
harness.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', null)
})
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.
harness.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',
page: 2,
noCache: true
})
expect(listWorkItemsMock).toHaveBeenCalledWith(
'/workspace/repo',
10,
'is:open',
2,
'origin',
null,
true
)
})
// Why: open-by-number must pin the same source the list uses, else a fork and
// its upstream sharing PR #42 open different PRs from the same click.
it('pins the repo origin source preference on work item and details IPC', async () => {
harness.repos = [
{
id: 'repo-1',
path: '/workspace/repo',
displayName: 'repo',
badgeColor: '#000',
addedAt: 0,
issueSourcePreference: 'origin'
}
]
getWorkItemMock.mockResolvedValue(null)
getWorkItemDetailsMock.mockResolvedValue(null)
registerGitHubHandlers(store as never, stats as never)
await handlers['gh:workItem'](null, { repoPath: '/workspace/repo', number: 42, type: 'pr' })
await handlers['gh:workItemDetails'](null, {
repoPath: '/workspace/repo',
number: 42,
type: 'pr'
})
expect(getWorkItemMock).toHaveBeenCalledWith(
'/workspace/repo',
42,
'pr',
null,
undefined,
'origin'
)
expect(getWorkItemDetailsMock).toHaveBeenCalledWith(
'/workspace/repo',
42,
'pr',
null,
undefined,
'origin'
)
})
})