@@ -31,6 +31,8 @@ const watch = (overrides: Partial<ThreadPullRequestWatch> = {}): ThreadPullReque
3131 ...overrides ,
3232} ) ;
3333
34+ const run = ( id : number ) => `https://github.com/o/r/actions/runs/${ id } ` ;
35+
3436const check = ( name : string , status : PullRequestCheck [ "status" ] ) : PullRequestCheck => ( {
3537 name,
3638 status,
@@ -79,6 +81,136 @@ const remark = (
7981const noRemarks : ReadonlyArray < PullRequestComment > = [ ] ;
8082
8183describe ( "evaluatePullRequestWatch" , ( ) => {
84+ it ( "waits for workflow approval once, through reads that miss it, until the run finishes" , ( ) => {
85+ const bot = check ( "bot" , "success" ) ;
86+ const approval = { ...check ( "CI" , "action-required" ) , url : run ( 1 ) } ;
87+ const gated = detail ( { checks : [ bot , approval ] } ) ;
88+ const first = evaluatePullRequestWatch ( watch ( ) , gated , noRemarks ) ;
89+ assert . deepEqual ( first . changes , [ { kind : "checks-awaiting-approval" , checks : [ approval ] } ] ) ;
90+
91+ // GitHub's approval read can answer empty while the rest of the checks read fine.
92+ const missing = evaluatePullRequestWatch ( first . next , detail ( { checks : [ bot ] } ) , noRemarks ) ;
93+ assert . deepEqual ( missing . changes , [ ] ) ;
94+ assert . isFalse ( missing . next . passed ) ;
95+ assert . deepEqual ( evaluatePullRequestWatch ( missing . next , gated , noRemarks ) . changes , [ ] ) ;
96+ const later = { ...check ( "Preview" , "action-required" ) , url : run ( 2 ) } ;
97+ assert . deepEqual (
98+ evaluatePullRequestWatch ( missing . next , detail ( { checks : [ bot , approval , later ] } ) , noRemarks )
99+ . changes ,
100+ [ ] ,
101+ ) ;
102+ const unnamed = { ...check ( "Docs" , "action-required" ) , url : null } ;
103+ const named = detail ( { checks : [ bot , unnamed ] } ) ;
104+ const alone = evaluatePullRequestWatch ( watch ( ) , named , noRemarks ) ;
105+ assert . deepEqual ( alone . changes , [ { kind : "checks-awaiting-approval" , checks : [ unnamed ] } ] ) ;
106+ const placeholder = { ...unnamed , name : "Workflow approval status" , placeholder : true } ;
107+ const unlisted = evaluatePullRequestWatch (
108+ alone . next ,
109+ detail ( { checks : [ bot , placeholder ] } ) ,
110+ noRemarks ,
111+ ) ;
112+ assert . deepEqual ( unlisted . changes , [ ] ) ;
113+ assert . isFalse ( unlisted . next . passed ) ;
114+ assert . deepEqual ( evaluatePullRequestWatch ( unlisted . next , named , noRemarks ) . changes , [ ] ) ;
115+ const dropped = evaluatePullRequestWatch ( alone . next , detail ( { checks : [ bot ] } ) , noRemarks ) ;
116+ assert . deepEqual ( dropped . changes , [ ] ) ;
117+ assert . isFalse ( dropped . next . passed ) ;
118+ assert . deepEqual ( dropped . next . awaitingApproval , [ unnamed . name ] ) ;
119+ assert . deepEqual ( evaluatePullRequestWatch ( dropped . next , named , noRemarks ) . changes , [ ] ) ;
120+ const namedPending = evaluatePullRequestWatch (
121+ dropped . next ,
122+ detail ( {
123+ checks : [
124+ { ...bot , required : true } ,
125+ { ...unnamed , status : "pending" } ,
126+ ] ,
127+ } ) ,
128+ noRemarks ,
129+ ) ;
130+ assert . deepEqual ( namedPending . changes , [ ] ) ;
131+ assert . isFalse ( namedPending . next . passed ) ;
132+ const namedDone = detail ( { checks : [ bot , { ...unnamed , status : "success" } ] } ) ;
133+ const namedFinished = evaluatePullRequestWatch ( namedPending . next , namedDone , noRemarks ) ;
134+ assert . deepEqual ( namedFinished . changes , [ { kind : "checks-passed" , count : 2 , required : false } ] ) ;
135+ assert . deepEqual ( namedFinished . next . awaitingApproval , [ ] ) ;
136+ assert . deepEqual (
137+ evaluatePullRequestWatch ( namedFinished . next , namedDone , noRemarks ) . changes ,
138+ [ ] ,
139+ ) ;
140+ const pushed = detail ( { headSha : "bbbbbbbbbb" , checks : [ bot ] } ) ;
141+ assert . deepEqual ( evaluatePullRequestWatch ( missing . next , pushed , noRemarks ) . changes , [
142+ { kind : "checks-passed" , count : 1 , required : false } ,
143+ ] ) ;
144+
145+ // Approved, the run's jobs carry their own names under the run's URL.
146+ const job = { ...check ( "lint" , "success" ) , url : `${ run ( 1 ) } /job/7` } ;
147+ const pending = { ...check ( "test" , "pending" ) , url : `${ run ( 1 ) } /job/8` } ;
148+ const required = { ...bot , required : true } ;
149+ const running = evaluatePullRequestWatch (
150+ missing . next ,
151+ detail ( { checks : [ required , job , pending ] } ) ,
152+ noRemarks ,
153+ ) ;
154+ assert . deepEqual ( running . changes , [ ] ) ;
155+ assert . isFalse ( running . next . passed ) ;
156+ assert . deepEqual ( running . next . awaitingApproval , [ run ( 1 ) ] ) ;
157+ const overlap = evaluatePullRequestWatch (
158+ running . next ,
159+ detail ( { checks : [ required , job , { ...pending , url : `${ run ( 2 ) } /job/9` } ] } ) ,
160+ noRemarks ,
161+ ) ;
162+ assert . deepEqual ( overlap . changes , [ ] ) ;
163+ assert . isFalse ( overlap . next . passed ) ;
164+ assert . deepEqual ( overlap . next . awaitingApproval , [ run ( 1 ) ] ) ;
165+ const unlinked = evaluatePullRequestWatch (
166+ overlap . next ,
167+ detail ( { checks : [ required , job , { ...pending , url : null } ] } ) ,
168+ noRemarks ,
169+ ) ;
170+ assert . deepEqual ( unlinked . changes , [ ] ) ;
171+ assert . isFalse ( unlinked . next . passed ) ;
172+ assert . deepEqual ( unlinked . next . awaitingApproval , [ run ( 1 ) ] ) ;
173+ const advisory = evaluatePullRequestWatch (
174+ unlinked . next ,
175+ detail ( { checks : [ required , job , { ...pending , url : "https://ci.example/test" } ] } ) ,
176+ noRemarks ,
177+ ) ;
178+ assert . deepEqual ( advisory . changes , [ { kind : "checks-passed" , count : 1 , required : true } ] ) ;
179+ assert . deepEqual ( advisory . next . awaitingApproval , [ ] ) ;
180+ const completed = detail ( { checks : [ required , job , { ...pending , status : "success" } ] } ) ;
181+ const finished = evaluatePullRequestWatch ( unlinked . next , completed , noRemarks ) ;
182+ assert . deepEqual ( finished . changes , [ { kind : "checks-passed" , count : 1 , required : true } ] ) ;
183+ assert . deepEqual ( finished . next . awaitingApproval , [ ] ) ;
184+ assert . deepEqual ( evaluatePullRequestWatch ( finished . next , completed , noRemarks ) . changes , [ ] ) ;
185+
186+ const done = evaluatePullRequestWatch ( missing . next , detail ( { checks : [ bot , job ] } ) , noRemarks ) ;
187+ assert . deepEqual ( done . changes , [ { kind : "checks-passed" , count : 2 , required : false } ] ) ;
188+ } ) ;
189+
190+ it ( "does not pass or fail while the host cannot tell whether workflows await approval" , ( ) => {
191+ const bot = check ( "bot" , "success" ) ;
192+ const unknown = {
193+ ...check ( "Workflow approval status" , "action-required" ) ,
194+ url : null ,
195+ placeholder : true ,
196+ } ;
197+ const unread = evaluatePullRequestWatch ( watch ( ) , detail ( { checks : [ bot , unknown ] } ) , noRemarks ) ;
198+ assert . deepEqual ( unread . changes , [ ] ) ;
199+ assert . isFalse ( unread . next . passed ) ;
200+ const read = evaluatePullRequestWatch ( unread . next , detail ( { checks : [ bot ] } ) , noRemarks ) ;
201+ assert . deepEqual ( read . changes , [ { kind : "checks-passed" , count : 1 , required : false } ] ) ;
202+ const blocked = evaluatePullRequestWatch (
203+ read . next ,
204+ detail ( { checks : [ { ...bot , status : "pending" } , unknown ] } ) ,
205+ noRemarks ,
206+ ) ;
207+ assert . isFalse ( blocked . next . passed ) ;
208+ assert . deepEqual (
209+ evaluatePullRequestWatch ( blocked . next , detail ( { checks : [ bot ] } ) , noRemarks ) . changes ,
210+ [ { kind : "checks-passed" , count : 1 , required : false } ] ,
211+ ) ;
212+ } ) ;
213+
82214 it ( "reports each failure at once, even while another check never finishes" , ( ) => {
83215 const bot = check ( "CodeRabbit" , "pending" ) ;
84216 const first = detail ( { checks : [ check ( "lint" , "failure" ) , check ( "test" , "pending" ) , bot ] } ) ;
@@ -95,6 +227,13 @@ describe("evaluatePullRequestWatch", () => {
95227
96228 const pushed = detail ( { ...second , headSha : "bbbbbbbbbb" } ) ;
97229 assert . equal ( evaluatePullRequestWatch ( test . next , pushed , noRemarks ) . changes . length , 1 ) ;
230+
231+ const approval = { ...check ( "CI" , "action-required" ) , url : run ( 1 ) } ;
232+ const gated = detail ( { checks : [ approval , check ( "lint" , "failure" ) ] } ) ;
233+ assert . deepEqual ( evaluatePullRequestWatch ( watch ( ) , gated , noRemarks ) . changes , [
234+ { kind : "checks-failed" , failed : [ check ( "lint" , "failure" ) ] } ,
235+ { kind : "checks-awaiting-approval" , checks : [ approval ] } ,
236+ ] ) ;
98237 } ) ;
99238
100239 it ( "reports passed once the required checks pass, whatever the others do" , ( ) => {
@@ -429,6 +568,15 @@ describe("evaluatePullRequestWatch", () => {
429568 assert . isTrue ( anHourLater ( legacy , detail ( { checks : [ ] } ) ) . every ( ( kinds ) => kinds . length === 0 ) ) ;
430569 const pushed = anHourLater ( legacy , detail ( { headSha : "bbbbbbbbbb" , checks : [ ] } ) ) ;
431570 assert . deepEqual ( pushed . flat ( ) , [ "no-checks" ] ) ;
571+ const unknown = detail ( {
572+ checks : [ { ...check ( "Workflow approval status" , "action-required" ) , placeholder : true } ] ,
573+ } ) ;
574+ assert . deepEqual ( anHourLater ( watch ( ) , unknown ) . flat ( ) , [ ] ) ;
575+ const unread = evaluate ( watch ( ) , unknown , noRemarks , 0 ) ;
576+ assert . deepEqual (
577+ evaluate ( unread . next , detail ( { checks : [ ] } ) , noRemarks , 60 * 60_000 ) . changes ,
578+ [ { kind : "no-checks" , minutes : 60 } ] ,
579+ ) ;
432580 } ) ;
433581
434582 it ( "never reports missing checks on a host where an empty list says nothing" , ( ) => {
0 commit comments