import { describe, expect, it } from 'vitest'
import { decideAlignment } from '../worktree.js'

describe('decideAlignment (local develop ↔ origin before a feature PR/merge)', () => {
  it('no remote ref yet → nothing to do (never block on a missing origin)', () => {
    expect(decideAlignment({ ahead: 0, behind: 0, remoteExists: false })).toEqual({ action: 'none' })
    expect(decideAlignment({ ahead: 3, behind: 5, remoteExists: false })).toEqual({ action: 'none' })
  })

  it('aligned (0 / 0) → nothing to do', () => {
    expect(decideAlignment({ ahead: 0, behind: 0, remoteExists: true })).toEqual({ action: 'none' })
  })

  it('behind only → fast-forward to origin (the stale-local-develop case)', () => {
    expect(decideAlignment({ ahead: 0, behind: 2, remoteExists: true })).toEqual({ action: 'ff' })
  })

  it('ahead only → nothing to do (local has unpushed commits, not stale)', () => {
    expect(decideAlignment({ ahead: 4, behind: 0, remoteExists: true })).toEqual({ action: 'none' })
  })

  it('diverged (ahead AND behind) → refuse, needs a human', () => {
    expect(decideAlignment({ ahead: 1, behind: 2, remoteExists: true })).toEqual({ action: 'diverged' })
  })
})
