Skip to content
← Public packages

@kentcdodds/codebase-cleanup

Cursor cloud agents for legacy cleanup, docs freshness, tight tests, and prod CI fixes, plus a weekly Devin general audit.

FollowFork

Files

ci-parse.test.ts

77 lines · 1.9 KB · TypeScript
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { parseCiFailurePayload } from './ci-parse.ts'

describe('parseCiFailurePayload', () => {
	it('accepts check_suite completed failure on main', () => {
		const parsed = parseCiFailurePayload({
			event: 'check_suite',
			json: {
				action: 'completed',
				check_suite: {
					conclusion: 'failure',
					head_branch: 'main',
					head_sha: 'abc123',
					url: 'https://api.github.com/repos/acme/widgets/check-suites/1',
				},
				repository: { full_name: 'acme/widgets' },
			},
		})
		assert.equal(parsed?.repo, 'acme/widgets')
		assert.equal(parsed?.branch, 'main')
		assert.equal(parsed?.headSha, 'abc123')
		assert.equal(parsed?.conclusion, 'failure')
	})

	it('ignores successful check_suite', () => {
		const parsed = parseCiFailurePayload({
			event: 'check_suite',
			json: {
				action: 'completed',
				check_suite: {
					conclusion: 'success',
					head_branch: 'main',
					head_sha: 'abc123',
				},
				repository: { full_name: 'acme/widgets' },
			},
		})
		assert.equal(parsed, null)
	})

	it('accepts workflow_run failure', () => {
		const parsed = parseCiFailurePayload({
			event: 'workflow_run',
			json: {
				action: 'completed',
				workflow_run: {
					conclusion: 'failure',
					head_branch: 'main',
					head_sha: 'fff',
					name: 'Validate',
					html_url: 'https://github.com/acme/widgets/actions/runs/1',
				},
				repository: { full_name: 'acme/widgets' },
			},
		})
		assert.equal(parsed?.workflowName, 'Validate')
		assert.equal(parsed?.headSha, 'fff')
	})

	it('ignores non-completed actions', () => {
		const parsed = parseCiFailurePayload({
			event: 'check_run',
			json: {
				action: 'created',
				check_run: {
					conclusion: 'failure',
					head_sha: 'x',
					check_suite: { head_branch: 'main' },
					name: 'build',
				},
				repository: { full_name: 'acme/widgets' },
			},
		})
		assert.equal(parsed, null)
	})
})