@@ -11,7 +11,7 @@ const STARTED = "2026-10-02T12:00:00.000Z";
1111
1212const watch = ( overrides : Partial < ThreadPullRequestWatch > = { } ) : ThreadPullRequestWatch => ( {
1313 startedAt : STARTED ,
14- headSha : null ,
14+ headSha : "aaaaaaaaaa" ,
1515 failedChecks : [ ] ,
1616 passed : false ,
1717 passedChecks : [ ] ,
@@ -58,6 +58,103 @@ const remark = (
5858const noRemarks : ReadonlyArray < PullRequestComment > = [ ] ;
5959
6060describe ( "evaluatePullRequestWatch" , ( ) => {
61+ it . each ( [ false , true ] ) ( "baselines already-passed checks (required: %s)" , ( required ) => {
62+ const green = detail ( { checks : [ { ...check ( "test" , "success" ) , required } ] } ) ;
63+ const baseline = evaluatePullRequestWatch ( watch ( { headSha : null } ) , green , noRemarks ) ;
64+ assert . deepEqual ( baseline . changes , [ ] ) ;
65+ assert . equal ( baseline . next . headSha , green . headSha ) ;
66+ assert . isTrue ( baseline . next . passed ) ;
67+ assert . deepEqual ( baseline . next . passedChecks , [ "test" ] ) ;
68+ assert . isFalse ( baseline . exhausted ) ;
69+ assert . deepEqual ( evaluatePullRequestWatch ( baseline . next , green , noRemarks ) . changes , [ ] ) ;
70+
71+ const pending = evaluatePullRequestWatch (
72+ baseline . next ,
73+ detail ( { checks : [ { ...check ( "test" , "pending" ) , required } ] } ) ,
74+ noRemarks ,
75+ ) ;
76+ assert . deepEqual ( pending . changes , [ ] ) ;
77+ const failed = evaluatePullRequestWatch (
78+ pending . next ,
79+ detail ( { checks : [ { ...check ( "test" , "failure" ) , required } ] } ) ,
80+ noRemarks ,
81+ ) ;
82+ assert . equal ( failed . changes [ 0 ] ?. kind , "checks-failed" ) ;
83+ const passed = evaluatePullRequestWatch ( failed . next , green , noRemarks ) ;
84+ assert . deepEqual ( passed . changes , [ { kind : "checks-passed" , count : 1 , required } ] ) ;
85+ assert . deepEqual (
86+ evaluatePullRequestWatch ( passed . next , { ...green , headSha : "bbbbbbbbbb" } , noRemarks ) . changes ,
87+ [ { kind : "checks-passed" , count : 1 , required } ] ,
88+ ) ;
89+ } ) ;
90+
91+ it ( "baselines existing failures and conflicts, then reports new ones" , ( ) => {
92+ const broken = detail ( {
93+ checks : [ check ( "lint" , "failure" ) , check ( "test" , "pending" ) ] ,
94+ mergeability : "conflicting" ,
95+ } ) ;
96+ const baseline = evaluatePullRequestWatch ( watch ( { headSha : null } ) , broken , noRemarks ) ;
97+ assert . deepEqual ( baseline . changes , [ ] ) ;
98+ assert . deepEqual ( baseline . next . failedChecks , [ "lint" ] ) ;
99+ assert . isFalse ( baseline . next . passed ) ;
100+ assert . isTrue ( baseline . next . conflicting ) ;
101+ assert . deepEqual ( evaluatePullRequestWatch ( baseline . next , broken , noRemarks ) . changes , [ ] ) ;
102+
103+ const failed = evaluatePullRequestWatch (
104+ baseline . next ,
105+ { ...broken , checks : [ check ( "lint" , "failure" ) , check ( "test" , "failure" ) ] } ,
106+ noRemarks ,
107+ ) ;
108+ assert . deepEqual ( failed . changes , [
109+ { kind : "checks-failed" , failed : [ check ( "test" , "failure" ) ] } ,
110+ ] ) ;
111+ const clean = evaluatePullRequestWatch ( failed . next , detail ( ) , noRemarks ) ;
112+ assert . deepEqual ( clean . changes , [ ] ) ;
113+ assert . deepEqual ( evaluatePullRequestWatch ( clean . next , broken , noRemarks ) . changes , [
114+ { kind : "checks-failed" , failed : [ check ( "lint" , "failure" ) ] } ,
115+ { kind : "conflicting" } ,
116+ ] ) ;
117+ } ) ;
118+
119+ it ( "reports remarks after the watch started while baselining checks and conflicts" , ( ) => {
120+ const green = detail ( {
121+ checks : [ check ( "test" , "success" ) ] ,
122+ mergeability : "conflicting" ,
123+ } ) ;
124+ const comments = [
125+ remark ( "reviewer" , "2026-10-02T11:00:00Z" ) ,
126+ remark ( "reviewer" , "2026-10-02T12:06:00Z" ) ,
127+ ] ;
128+ const baseline = evaluatePullRequestWatch ( watch ( { headSha : null } ) , green , comments ) ;
129+ assert . deepEqual ( baseline . changes , [ { kind : "remarks" , remarks : [ comments [ 1 ] ! ] } ] ) ;
130+ assert . isTrue ( baseline . next . passed ) ;
131+ assert . isTrue ( baseline . next . conflicting ) ;
132+ assert . equal ( baseline . next . wakes , 1 ) ;
133+ assert . deepEqual ( evaluatePullRequestWatch ( baseline . next , green , comments ) . changes , [ ] ) ;
134+ } ) ;
135+
136+ it ( "keeps reporting check changes when the host omits the head SHA" , ( ) => {
137+ const pending = detail ( { headSha : undefined , checks : [ check ( "test" , "pending" ) ] } ) ;
138+ const waiting = evaluatePullRequestWatch ( watch ( { headSha : null } ) , pending , noRemarks ) ;
139+ assert . deepEqual ( waiting . changes , [ ] ) ;
140+ const failed = evaluatePullRequestWatch (
141+ waiting . next ,
142+ { ...pending , checks : [ check ( "test" , "failure" ) ] } ,
143+ noRemarks ,
144+ ) ;
145+ assert . deepEqual ( failed . changes , [
146+ { kind : "checks-failed" , failed : [ check ( "test" , "failure" ) ] } ,
147+ ] ) ;
148+ assert . deepEqual (
149+ evaluatePullRequestWatch (
150+ failed . next ,
151+ { ...pending , checks : [ check ( "test" , "success" ) ] } ,
152+ noRemarks ,
153+ ) . changes ,
154+ [ { kind : "checks-passed" , count : 1 , required : false } ] ,
155+ ) ;
156+ } ) ;
157+
61158 it ( "reports each failure at once, even while another check never finishes" , ( ) => {
62159 const bot = check ( "CodeRabbit" , "pending" ) ;
63160 const first = detail ( { checks : [ check ( "lint" , "failure" ) , check ( "test" , "pending" ) , bot ] } ) ;
0 commit comments