mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 18:47:40 +00:00
* [comment audit] Shorten daemon, hook, and emulator comments [skip ci] * [comment audit] Shorten VM, conversation, SQLite, and theme-import comments [skip ci] * [comment audit] Tighten Git execution and source-control comment contracts [skip ci] * [comment audit] Clarify repository probes and maintenance comments [skip ci] * [comment audit] Shorten status, diff-cache, and checkout comments [skip ci] * [comment audit] Clarify worktree lifecycle and WSL routing comments [skip ci] * [comment audit] Shorten forge identity and review-refresh comments [skip ci] * [comment audit] Tighten hosted-review client comment contracts [skip ci] * [comment audit] Clarify GitLab compatibility and review comments [skip ci] * [comment audit] Tighten hook ownership and watchdog rationale [skip ci] * [comment audit] Condense host and integration compatibility comments [skip ci] * [comment audit] Clarify IPC authority and remote-routing rationale [skip ci] * [comment audit] Finalize file-import and containment comment cleanup * [comment audit] Fix stale Jira type imports blocking full CI --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
168 lines
5.7 KiB
TypeScript
168 lines
5.7 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { getPullRequestPushTargetMock } = vi.hoisted(() => ({
|
|
getPullRequestPushTargetMock: vi.fn()
|
|
}))
|
|
|
|
vi.mock('./client', () => ({
|
|
getPullRequestPushTarget: getPullRequestPushTargetMock,
|
|
getWorkItem: vi.fn()
|
|
}))
|
|
|
|
import { resolveGitHubPrStartPoint } from './pr-start-point'
|
|
import { reviewHeadRemoteRefComponent } from '../../shared/review-head-tracking-ref'
|
|
|
|
const ORIGIN_URL = 'git@github.com:acme/orca.git'
|
|
const durablePrLocalRef = `refs/orca/pull/${reviewHeadRemoteRefComponent('origin', ORIGIN_URL)}/42`
|
|
const durablePrRev = `${durablePrLocalRef}^{commit}`
|
|
|
|
describe('resolveGitHubPrStartPoint compare base', () => {
|
|
beforeEach(() => {
|
|
getPullRequestPushTargetMock.mockReset()
|
|
getPullRequestPushTargetMock.mockResolvedValue(null)
|
|
vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
})
|
|
afterEach(() => vi.restoreAllMocks())
|
|
|
|
it('drops the compare base for a fork PR when its base ref is missing locally too', async () => {
|
|
const fetchRemoteTrackingRef = vi.fn(async () => {
|
|
throw new Error("fatal: couldn't find remote ref refs/heads/main")
|
|
})
|
|
const fetchPullRequestHeadRef = vi.fn(async () => durablePrLocalRef)
|
|
const gitExec = vi.fn(async (args: string[]) => {
|
|
if (args[2] === durablePrRev) {
|
|
return { stdout: 'fork-head-sha\n', stderr: '' }
|
|
}
|
|
throw new Error('fatal: Needed a single revision')
|
|
})
|
|
|
|
const result = await resolveGitHubPrStartPoint({
|
|
repoPath: '/repo-root',
|
|
prNumber: 42,
|
|
headRefName: 'contributor/fix',
|
|
baseRefName: 'main',
|
|
isCrossRepository: true,
|
|
gitExec,
|
|
fetchRemoteTrackingRef,
|
|
fetchPullRequestHeadRef,
|
|
resolveRemote: async () => 'origin'
|
|
})
|
|
|
|
expect(gitExec).toHaveBeenCalledWith(['rev-parse', '--verify', durablePrRev])
|
|
expect(result).toEqual({
|
|
baseBranch: 'fork-head-sha',
|
|
headSha: 'fork-head-sha',
|
|
branchNameOverride: 'contributor/fix'
|
|
})
|
|
expect(console.warn).toHaveBeenCalledWith(
|
|
'[github:resolvePrStartPoint] optional compare-base fetch failed',
|
|
expect.objectContaining({ baseRefName: 'main', prNumber: 42, localBaseResolved: false })
|
|
)
|
|
})
|
|
|
|
it('keeps the compare base for a fork PR when the local tracking ref still resolves', async () => {
|
|
const fetchRemoteTrackingRef = vi.fn(async () => {
|
|
throw new Error('fatal: unable to access repo: Could not resolve host: github.com')
|
|
})
|
|
const fetchPullRequestHeadRef = vi.fn(async () => durablePrLocalRef)
|
|
const gitExec = vi.fn(async (args: string[]) => {
|
|
if (args[2] === durablePrRev) {
|
|
return { stdout: 'fork-head-sha\n', stderr: '' }
|
|
}
|
|
if (args[2] === 'refs/remotes/origin/main^{commit}') {
|
|
return { stdout: 'base-commit-sha\n', stderr: '' }
|
|
}
|
|
throw new Error(`unexpected git call: ${args.join(' ')}`)
|
|
})
|
|
|
|
const result = await resolveGitHubPrStartPoint({
|
|
repoPath: '/repo-root',
|
|
prNumber: 42,
|
|
headRefName: 'contributor/fix',
|
|
baseRefName: 'main',
|
|
isCrossRepository: true,
|
|
gitExec,
|
|
fetchRemoteTrackingRef,
|
|
fetchPullRequestHeadRef,
|
|
resolveRemote: async () => 'origin'
|
|
})
|
|
|
|
expect(result).toEqual({
|
|
baseBranch: 'fork-head-sha',
|
|
compareBaseRef: 'refs/remotes/origin/main',
|
|
headSha: 'fork-head-sha',
|
|
branchNameOverride: 'contributor/fix'
|
|
})
|
|
expect(gitExec).toHaveBeenCalledWith([
|
|
'rev-parse',
|
|
'--verify',
|
|
'refs/remotes/origin/main^{commit}'
|
|
])
|
|
})
|
|
|
|
it('keeps a same-repo PR compare base when the fetch fails but the local ref resolves', async () => {
|
|
const fetchRemoteTrackingRef = vi.fn(async (_remote: string, branch: string) => {
|
|
if (branch === 'main') {
|
|
throw new Error('network unavailable')
|
|
}
|
|
})
|
|
const gitExec = vi.fn(async (args: string[]) => {
|
|
if (args[2] === 'refs/remotes/origin/main^{commit}') {
|
|
return { stdout: 'base-commit-sha\n', stderr: '' }
|
|
}
|
|
return { stdout: 'same-repo-head-sha\n', stderr: '' }
|
|
})
|
|
|
|
const result = await resolveGitHubPrStartPoint({
|
|
repoPath: '/repo-root',
|
|
prNumber: 43,
|
|
headRefName: 'feature/fix',
|
|
baseRefName: 'main',
|
|
gitExec,
|
|
fetchRemoteTrackingRef,
|
|
fetchPullRequestHeadRef: async () => durablePrLocalRef,
|
|
resolveRemote: async () => 'origin'
|
|
})
|
|
|
|
expect(result).toEqual({
|
|
baseBranch: 'same-repo-head-sha',
|
|
compareBaseRef: 'refs/remotes/origin/main',
|
|
headSha: 'same-repo-head-sha',
|
|
branchNameOverride: 'feature/fix',
|
|
pushTarget: { remoteName: 'origin', branchName: 'feature/fix' }
|
|
})
|
|
})
|
|
|
|
it('drops a same-repo PR compare base when neither fetch nor local ref resolves', async () => {
|
|
const fetchRemoteTrackingRef = vi.fn(async (_remote: string, branch: string) => {
|
|
if (branch === 'main') {
|
|
throw new Error('network unavailable')
|
|
}
|
|
})
|
|
const gitExec = vi.fn(async (args: string[]) => {
|
|
if (args[2] === 'refs/remotes/origin/main^{commit}') {
|
|
throw new Error('fatal: Needed a single revision')
|
|
}
|
|
return { stdout: 'same-repo-head-sha\n', stderr: '' }
|
|
})
|
|
|
|
const result = await resolveGitHubPrStartPoint({
|
|
repoPath: '/repo-root',
|
|
prNumber: 44,
|
|
headRefName: 'feature/fix',
|
|
baseRefName: 'main',
|
|
gitExec,
|
|
fetchRemoteTrackingRef,
|
|
fetchPullRequestHeadRef: async () => durablePrLocalRef,
|
|
resolveRemote: async () => 'origin'
|
|
})
|
|
|
|
expect(result).toEqual({
|
|
baseBranch: 'same-repo-head-sha',
|
|
headSha: 'same-repo-head-sha',
|
|
branchNameOverride: 'feature/fix',
|
|
pushTarget: { remoteName: 'origin', branchName: 'feature/fix' }
|
|
})
|
|
})
|
|
})
|