import { describe, expect, it } from 'vitest' import { rollupVerdict } from '../../scripts/lib/ci-rollup-check.mjs' const CI_PR = 'CI (PR) / ' const OWN = 'CI (PR) / checks' const status = (context: string, state: string) => ({ context, state }) describe('rollupVerdict (OPS64)', () => { it('reports ok when every workflow status is success', () => { const verdict = rollupVerdict( [ status('CI (PR) / lint (pull_request)', 'success'), status('CI (PR) / e2e (1) (pull_request)', 'success'), status('CI (PR) / e2e (2) (pull_request)', 'success'), ], { prefix: CI_PR, ownPrefix: OWN }, ) expect(verdict.ok).toBe(true) }) it('fails when a matrix shard is failure even if the parent would report green (run 604/607/610)', () => { // Forgejo reports the LAST shard's result as the matrix parent result, so // the old `all(needs...)` jq passed with e2e (1) red — the exact hole this // verdict closes. The shard's own status is the ground truth. const verdict = rollupVerdict( [ status('CI (PR) / lint (pull_request)', 'success'), status('CI (PR) / e2e (1) (pull_request)', 'failure'), status('CI (PR) / e2e (2) (pull_request)', 'success'), ], { prefix: CI_PR, ownPrefix: OWN }, ) expect(verdict.ok).toBe(false) expect(verdict.failed.map((entry) => entry.context)).toContain( 'CI (PR) / e2e (1) (pull_request)', ) }) it('fails when the failing shard is the last one (run 716)', () => { const verdict = rollupVerdict( [ status('CI (PR) / e2e (1) (pull_request)', 'success'), status('CI (PR) / e2e (2) (pull_request)', 'failure'), ], { prefix: CI_PR, ownPrefix: OWN }, ) expect(verdict.ok).toBe(false) expect(verdict.failed.map((entry) => entry.context)).toContain( 'CI (PR) / e2e (2) (pull_request)', ) }) it('ignores the rollup own pending status (posted while the job runs)', () => { const verdict = rollupVerdict( [ status('CI (PR) / checks (pull_request)', 'pending'), status('CI (PR) / e2e (1) (pull_request)', 'success'), status('CI (PR) / e2e (2) (pull_request)', 'success'), ], { prefix: CI_PR, ownPrefix: OWN }, ) expect(verdict.ok).toBe(true) }) it('ignores contexts of other workflows on the same sha (the safety net)', () => { const verdict = rollupVerdict( [ status('PR Ready + auto-merge / ready-automerge (pull_request)', 'pending'), status('CI (PR) / e2e (1) (pull_request)', 'success'), status('CI (PR) / e2e (2) (pull_request)', 'success'), ], { prefix: CI_PR, ownPrefix: OWN }, ) expect(verdict.ok).toBe(true) }) it('ignores downstream pending contexts via ignorePrefixes (ci.yml deploy)', () => { const verdict = rollupVerdict( [ status('CI / static (push)', 'success'), status('CI / e2e (1) (push)', 'success'), status('CI / deploy (push)', 'pending'), ], { prefix: 'CI / ', ownPrefix: 'CI / checks', ignorePrefixes: ['CI / deploy'] }, ) expect(verdict.ok).toBe(true) }) it('fails on pending siblings (cascade not settled — fail-closed)', () => { const verdict = rollupVerdict( [ status('CI (PR) / e2e (1) (pull_request)', 'pending'), status('CI (PR) / e2e (2) (pull_request)', 'success'), ], { prefix: CI_PR, ownPrefix: OWN }, ) expect(verdict.ok).toBe(false) expect(verdict.pending.map((entry) => entry.context)).toContain( 'CI (PR) / e2e (1) (pull_request)', ) }) it('fails on error state', () => { const verdict = rollupVerdict([status('CI (PR) / lint (pull_request)', 'error')], { prefix: CI_PR, ownPrefix: OWN, }) expect(verdict.ok).toBe(false) }) it('fails closed on an empty relevant set (no statuses for the sha)', () => { const verdict = rollupVerdict([], { prefix: CI_PR, ownPrefix: OWN }) expect(verdict.ok).toBe(false) }) it('allows an empty set only when allowEmpty (ci.yml workflow_dispatch)', () => { const verdict = rollupVerdict([], { prefix: 'CI / ', ownPrefix: 'CI / checks', allowEmpty: true, }) expect(verdict.ok).toBe(true) }) it('accepts skipped jobs as success (posted with "Has been skipped")', () => { const verdict = rollupVerdict( [ status('CI (PR) / build (pull_request)', 'success'), status('CI (PR) / int (pull_request)', 'success'), ], { prefix: CI_PR, ownPrefix: OWN }, ) expect(verdict.ok).toBe(true) }) })