import { describe, expect, it } from 'vitest' import { generateActions } from '../execute.js' import type { BranchInfo, Comparison, WorkingTreeStatus } from '../types.js' const cleanTree: WorkingTreeStatus = { isDirty: false, isRebasing: false, isMerging: false, isCherryPicking: false, unstagedCount: 0, stagedCount: 0, } const noBranches: BranchInfo[] = [] const developVsCurrent = (toBranch: string, behindCount: number): Comparison => ({ branches: ['develop', toBranch], fromBranch: 'develop', toBranch, aheadCount: 0, behindCount, }) describe('generateActions — base-staleness surfacing (feature behind develop)', () => { it('suggests /gitflow update when develop is ahead of the current branch', () => { const actions = generateActions('feature/x', noBranches, cleanTree, [developVsCurrent('feature/x', 2)]) const update = actions.find((a) => a.action.includes('/gitflow update')) expect(update).toBeDefined() expect(update?.priority).toBe('medium') expect(update?.action).toContain("Update 'feature/x' from develop") expect(update?.reason).toContain('ahead by 2 commit(s)') }) it('stays silent when the current branch is up to date with develop', () => { const actions = generateActions('feature/x', noBranches, cleanTree, [developVsCurrent('feature/x', 0)]) expect(actions.some((a) => a.action.includes('/gitflow update'))).toBe(false) }) it('ignores comparisons whose toBranch is not the current branch (main vs develop)', () => { const mainVsDevelop: Comparison = { branches: ['main', 'develop'], fromBranch: 'main', toBranch: 'develop', aheadCount: 0, behindCount: 5, } const actions = generateActions('feature/x', noBranches, cleanTree, [mainVsDevelop]) expect(actions.some((a) => a.action.includes('/gitflow update'))).toBe(false) }) it('sorts an in-progress (critical) action before the update suggestion', () => { const rebasingTree: WorkingTreeStatus = { ...cleanTree, isRebasing: true } const actions = generateActions('feature/x', noBranches, rebasingTree, [developVsCurrent('feature/x', 1)]) expect(actions[0].priority).toBe('critical') expect(actions.some((a) => a.action.includes('/gitflow update'))).toBe(true) }) it('keeps the legacy behavior unchanged with no comparisons', () => { const dirtyTree: WorkingTreeStatus = { ...cleanTree, isDirty: true } const actions = generateActions('feature/x', noBranches, dirtyTree, []) expect(actions).toHaveLength(1) expect(actions[0].action).toBe('Commit or stash changes') }) })