mirror of
https://github.com/stablyai/orca.git
synced 2026-10-30 00:27:39 +00:00
Second audit wave, targeting three more junk patterns: - assertion-free cases that run code and assert nothing, so they pass no matter what the code does; - inventory literals re-typed from a production declaration, where the only way the assertion can fail is someone editing one of the two copies; - export key-set and export-shape loops (`typeof x === 'function'` over every export) that restate what TypeScript already enforces. Yield is much smaller than wave 1 on purpose: the assertion-free scanner has a high false-positive rate, because many flagged blocks assert through a shared helper or their oracle is "this must not throw". Those were kept. `mobileWebCheckArgs` in `config/scripts/run-mobile-web-app-checks.mjs` is de-exported — after the inventory comparison went away, nothing outside the module read it.
93 lines
3.3 KiB
TypeScript
93 lines
3.3 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 { getAuthenticatedViewer: getAuthenticatedViewerMock, starOrca: starOrcaMock } = mocks.client
|
|
const { track: trackMock } = mocks.telemetry
|
|
const { getCohortAtEmit: getCohortAtEmitMock } = mocks.cohort
|
|
|
|
describe('registerGitHubHandlers', () => {
|
|
const harness = createGitHubIpcHarness(mocks)
|
|
const { handlers, store, stats } = harness
|
|
|
|
beforeEach(harness.reset)
|
|
|
|
it('forwards the authenticated viewer lookup', async () => {
|
|
getAuthenticatedViewerMock.mockResolvedValue({ login: 'octocat', email: 'octocat@example.com' })
|
|
|
|
registerGitHubHandlers(store as never, stats as never)
|
|
|
|
await expect(handlers['gh:viewer'](null, undefined)).resolves.toEqual({
|
|
login: 'octocat',
|
|
email: 'octocat@example.com'
|
|
})
|
|
expect(getAuthenticatedViewerMock).toHaveBeenCalled()
|
|
})
|
|
|
|
it('emits app_starred_orca once after a successful star with cohort context', async () => {
|
|
starOrcaMock.mockResolvedValue(true)
|
|
getCohortAtEmitMock.mockReturnValue({ nth_repo_added: 3 })
|
|
|
|
registerGitHubHandlers(store as never, stats as never)
|
|
|
|
await expect(handlers['gh:starOrca'](null, 'settings')).resolves.toBe(true)
|
|
|
|
expect(starOrcaMock).toHaveBeenCalledTimes(1)
|
|
expect(getCohortAtEmitMock).toHaveBeenCalledTimes(1)
|
|
expect(trackMock).toHaveBeenCalledTimes(1)
|
|
expect(trackMock).toHaveBeenCalledWith('app_starred_orca', {
|
|
source: 'settings',
|
|
nth_repo_added: 3
|
|
})
|
|
})
|
|
|
|
it('does not emit app_starred_orca when the star action returns false', async () => {
|
|
starOrcaMock.mockResolvedValue(false)
|
|
|
|
registerGitHubHandlers(store as never, stats as never)
|
|
|
|
await expect(handlers['gh:starOrca'](null, 'landing')).resolves.toBe(false)
|
|
|
|
expect(starOrcaMock).toHaveBeenCalledTimes(1)
|
|
expect(trackMock).not.toHaveBeenCalled()
|
|
expect(getCohortAtEmitMock).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('does not emit app_starred_orca when the star action throws', async () => {
|
|
starOrcaMock.mockRejectedValue(new Error('gh failed'))
|
|
|
|
registerGitHubHandlers(store as never, stats as never)
|
|
|
|
await expect(handlers['gh:starOrca'](null, 'star_nag')).rejects.toThrow('gh failed')
|
|
|
|
expect(trackMock).not.toHaveBeenCalled()
|
|
expect(getCohortAtEmitMock).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('preserves star result but skips telemetry for an invalid IPC source', async () => {
|
|
starOrcaMock.mockResolvedValue(true)
|
|
|
|
registerGitHubHandlers(store as never, stats as never)
|
|
|
|
await expect(handlers['gh:starOrca'](null, 'github_website')).resolves.toBe(true)
|
|
|
|
expect(starOrcaMock).toHaveBeenCalledTimes(1)
|
|
expect(trackMock).not.toHaveBeenCalled()
|
|
expect(getCohortAtEmitMock).not.toHaveBeenCalled()
|
|
})
|
|
})
|