Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

skip.test.ts

142 lines3.7 KB

1import { describe, expect, it } from 'vitest'
2import { config } from '../../scripts/maintainer/fixtures.ts'
3import { shouldSkip } from './skip'
4​
5const SHA = 'abc123def456'
6const MACHINE = 'tanstack-ai-bot'
7​
8function reviewSkip(
9 overrides: {
10 mode?: 'auto' | 'manual'
11 isDraft?: boolean
12 authorLogin?: string | null
13 headCommitAuthorLogin?: string | null
14 headSha?: string
15 alreadyReviewedSha?: string | null
16 machineUserLogin?: string
17 } = {},
18) {
19 return shouldSkip({
20 mode: 'auto',
21 isDraft: false,
22 authorLogin: 'alice',
23 headCommitAuthorLogin: 'alice',
24 headSha: SHA,
25 alreadyReviewedSha: null,
26 machineUserLogin: MACHINE,
27 config,
28 ...overrides,
29 })
31​
32describe('shouldSkip', () => {
33 describe('auto', () => {
34 it('does not skip an open human PR with a new head SHA', () => {
35 expect(reviewSkip()).toEqual({ skip: false, reason: null })
36 })
37​
38 it('skips a draft', () => {
39 expect(reviewSkip({ isDraft: true })).toEqual({
40 skip: true,
41 reason: 'draft',
42 })
43 })
44​
45 it('skips a bot PR author', () => {
46 expect(reviewSkip({ authorLogin: 'renovate' })).toEqual({
47 skip: true,
48 reason: 'bot-author',
49 })
50 })
51​
52 it('skips a roster maintainer PR author', () => {
53 expect(reviewSkip({ authorLogin: 'alem' })).toEqual({
54 skip: true,
55 reason: 'maintainer-author',
56 })
57 })
58​
59 it('skips when the head commit is from the machine user', () => {
60 expect(reviewSkip({ headCommitAuthorLogin: 'TanStack-AI-Bot' })).toEqual({
61 skip: true,
62 reason: 'bot-head-commit',
63 })
64 })
65​
66 it('skips when this head SHA was already reviewed', () => {
67 expect(reviewSkip({ alreadyReviewedSha: SHA })).toEqual({
68 skip: true,
69 reason: 'same-sha',
70 })
71 })
72​
73 it('does not skip a different already-reviewed SHA', () => {
74 expect(reviewSkip({ alreadyReviewedSha: 'oldsha' })).toEqual({
75 skip: false,
76 reason: null,
77 })
78 })
79​
80 it('does not treat a null author as a bot', () => {
81 expect(reviewSkip({ authorLogin: null })).toEqual({
82 skip: false,
83 reason: null,
84 })
85 })
86​
87 it('does not treat a null head-commit author as the machine user', () => {
88 expect(reviewSkip({ headCommitAuthorLogin: null })).toEqual({
89 skip: false,
90 reason: null,
91 })
92 })
93​
94 it('prefers draft over bot-author', () => {
95 expect(reviewSkip({ isDraft: true, authorLogin: 'renovate' })).toEqual({
96 skip: true,
97 reason: 'draft',
98 })
99 })
100​
101 it('prefers bot-author over bot-head-commit', () => {
102 expect(
103 reviewSkip({
104 authorLogin: 'renovate',
105 headCommitAuthorLogin: MACHINE,
106 }),
107 ).toEqual({ skip: true, reason: 'bot-author' })
108 })
109​
110 it('prefers maintainer-author over bot-head-commit', () => {
111 expect(
112 reviewSkip({
113 authorLogin: 'alem',
114 headCommitAuthorLogin: MACHINE,
115 }),
116 ).toEqual({ skip: true, reason: 'maintainer-author' })
117 })
118​
119 it('prefers bot-head-commit over same-sha', () => {
120 expect(
121 reviewSkip({
122 headCommitAuthorLogin: MACHINE,
123 alreadyReviewedSha: SHA,
124 }),
125 ).toEqual({ skip: true, reason: 'bot-head-commit' })
126 })
127 })
128​
129 describe('manual', () => {
130 it('never skips for draft, bot author, maintainer author, bot head commit, or same SHA', () => {
131 expect(
132 reviewSkip({
133 mode: 'manual',
134 isDraft: true,
135 authorLogin: 'alem',
136 headCommitAuthorLogin: MACHINE,
137 alreadyReviewedSha: SHA,
138 }),
139 ).toEqual({ skip: false, reason: null })
140 })
141 })
142})