mirror of
https://github.com/stablyai/orca.git
synced 2026-09-23 16:02:24 +00:00
Co-authored-by: Orca <help@stably.ai> Co-authored-by: Alexander Saavedra <mralexsaavedra@gmail.com> Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com> Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: brennanb2025 <brennankbenson@gmail.com>
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { gitExecFileAsyncMock } = vi.hoisted(() => ({
|
|
gitExecFileAsyncMock: vi.fn()
|
|
}))
|
|
|
|
vi.mock('./runner', () => ({
|
|
gitExecFileAsync: gitExecFileAsyncMock
|
|
}))
|
|
|
|
import { getUpstreamStatus } from './upstream'
|
|
|
|
const missingTrackingRefError = new Error(
|
|
"fatal: ambiguous argument 'HEAD@{u}': unknown revision or path not in the working tree.\n" +
|
|
"Use '--' to separate paths from revisions, like this:\n" +
|
|
"'git <command> [<revision>...] -- [<file>...]'"
|
|
)
|
|
|
|
describe('getUpstreamStatus', () => {
|
|
beforeEach(() => {
|
|
gitExecFileAsyncMock.mockReset()
|
|
})
|
|
|
|
it('returns upstream and ahead/behind counts when tracking is configured', async () => {
|
|
gitExecFileAsyncMock
|
|
.mockResolvedValueOnce({ stdout: 'origin/main\n' })
|
|
.mockResolvedValueOnce({ stdout: '2\t3\n' })
|
|
|
|
const result = await getUpstreamStatus('/repo')
|
|
|
|
expect(result).toEqual({
|
|
hasUpstream: true,
|
|
upstreamName: 'origin/main',
|
|
ahead: 2,
|
|
behind: 3
|
|
})
|
|
})
|
|
|
|
it('returns hasUpstream=false when upstream is missing', async () => {
|
|
gitExecFileAsyncMock.mockRejectedValueOnce(new Error('fatal: no upstream configured'))
|
|
|
|
const result = await getUpstreamStatus('/repo')
|
|
|
|
expect(result).toEqual({
|
|
hasUpstream: false,
|
|
ahead: 0,
|
|
behind: 0
|
|
})
|
|
})
|
|
|
|
it('returns hasUpstream=false when the configured tracking ref is missing', async () => {
|
|
gitExecFileAsyncMock.mockRejectedValueOnce(missingTrackingRefError)
|
|
|
|
const result = await getUpstreamStatus('/repo')
|
|
|
|
expect(result).toEqual({
|
|
hasUpstream: false,
|
|
ahead: 0,
|
|
behind: 0
|
|
})
|
|
})
|
|
})
|