teqo-backup/tests/unit/agentPromoteTarget.unit.spec.ts
Francisco Ignácio Fontoura Solla b533139eb2 feat(ops): promote último commit ci-stage green sem exigir head verde
agent:promote passa a escolher o SHA mais novo à frente de main com
ci-stage success e usa promote/last-green quando o head de stage está
vermelho, destravando o bootstrap manual para main.
2026-07-30 21:56:50 -03:00

38 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
findLastGreenPromoteSha,
greenCiStageHeadShas,
} from '../../scripts/lib/agent-promote-target.mjs'
describe('greenCiStageHeadShas', () => {
it('collects only completed successes', () => {
const green = greenCiStageHeadShas([
{ headSha: 'aaa', status: 'completed', conclusion: 'success' },
{ headSha: 'bbb', status: 'completed', conclusion: 'failure' },
{ headSha: 'ccc', status: 'in_progress', conclusion: null },
])
expect([...green]).toEqual(['aaa'])
})
})
describe('findLastGreenPromoteSha', () => {
it('returns the newest green commit ahead of main', () => {
const green = new Set(['bbb', 'ddd'])
expect(findLastGreenPromoteSha(['ccc', 'bbb', 'aaa'], green)).toBe('bbb')
})
it('returns stage head when it is green', () => {
const green = new Set(['ccc'])
expect(findLastGreenPromoteSha(['ccc', 'bbb'], green)).toBe('ccc')
})
it('returns null when nothing ahead is green', () => {
const green = new Set(['zzz'])
expect(findLastGreenPromoteSha(['ccc', 'bbb'], green)).toBeNull()
})
it('returns null when there is nothing ahead of main', () => {
expect(findLastGreenPromoteSha([], new Set(['aaa']))).toBeNull()
})
})