Files
orca/src/main/github/gh-capability-state.test.ts
T
Jinjing 0d4eb242d7 Recover failed-job log retrieval onto main (#29180)
* feat(checks): add optional job log outcome

* fix(checks): preserve host capture lifetimes and safe outcomes

* fix(checks): retrieve and retry bounded failed-job logs

* test(checks): cover queued snapshots and captured error safety

* test(checks): verify sanitized host excerpts and paired failures

* test(checks): identify measurements and preserve paired cleanup

* Use the generated check-log fixture in host retrieval tests

* Keep real paired-server shutdown outside the injected stall deadline
2026-10-15 10:36:21 -07:00

68 lines
2.1 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const { ghExecFileAsyncMock } = vi.hoisted(() => ({
ghExecFileAsyncMock: vi.fn()
}))
vi.mock('../git/runner', () => ({
ghExecFileAsync: ghExecFileAsyncMock
}))
import {
clearGhCapabilityStateForTests,
getGhExecutionHostKey,
getGhMultiAccountCapability,
invalidateGhMultiAccountCapability
} from './gh-capability-state'
describe('gh-capability-state', () => {
beforeEach(() => {
clearGhCapabilityStateForTests()
ghExecFileAsyncMock.mockReset()
})
afterEach(() => {
clearGhCapabilityStateForTests()
})
it('keys local vs wsl execution hosts', () => {
expect(getGhExecutionHostKey({})).toBe('local')
expect(getGhExecutionHostKey({ wslDistro: 'Ubuntu' })).toBe('wsl:Ubuntu')
})
it('reports supported when help lists --user', async () => {
ghExecFileAsyncMock.mockResolvedValue({
stdout: 'Usage: gh auth token [--user login]',
stderr: ''
})
await expect(getGhMultiAccountCapability()).resolves.toBe('supported')
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
['auth', 'token', '--help'],
expect.objectContaining({ timeout: 10_000 }),
expect.objectContaining({ onTerminationPending: expect.any(Function) })
)
})
it('reports unsupported when help omits --user', async () => {
ghExecFileAsyncMock.mockResolvedValue({
stdout: 'Usage: gh auth token',
stderr: ''
})
await expect(getGhMultiAccountCapability({ wslDistro: 'Ubuntu' })).resolves.toBe('unsupported')
})
it('caches per runtime and invalidates on request', async () => {
ghExecFileAsyncMock.mockResolvedValue({
stdout: 'Usage: gh auth token [--user login]',
stderr: ''
})
await getGhMultiAccountCapability({ wslDistro: 'Ubuntu' })
await getGhMultiAccountCapability({ wslDistro: 'Ubuntu' })
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(1)
invalidateGhMultiAccountCapability({ wslDistro: 'Ubuntu' })
await getGhMultiAccountCapability({ wslDistro: 'Ubuntu' })
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(2)
})
})