@@ -500,9 +500,10 @@ function pullRequest(fixture: Fixture) {
500500}
501501
502502/** The watch every row runs unless it says otherwise. */
503- function watching ( timeoutSeconds = 60 , after : readonly string [ ] = [ ] ) : string {
503+ function watching ( timeoutSeconds : number | null = 60 , after : readonly string [ ] = [ ] ) : string {
504+ const timeout = timeoutSeconds === null ? "" : ` timeoutSeconds={${ timeoutSeconds } }` ;
504505 return [
505- `<PullRequest.Checks url=${ JSON . stringify ( URL_1 ) } watch timeoutSeconds={ ${ timeoutSeconds } } as="checkResult" />` ,
506+ `<PullRequest.Checks url=${ JSON . stringify ( URL_1 ) } watch${ timeout } as="checkResult" />` ,
506507 "" ,
507508 "<Json value={checkResult} />" ,
508509 "" ,
@@ -842,8 +843,9 @@ describe("a watch's lifetime", () => {
842843 yield * suspend ( ) ;
843844 } ;
844845 const stream = new InMemoryStream ( ) ;
845- const task = yield * started ( fixture , watching ( ) , stream ) ;
846+ const task = yield * started ( fixture , watching ( null ) , stream ) ;
846847 yield * reached . operation ;
848+ expect ( fixture . clock . waiters ) . toEqual ( [ ] ) ;
847849 yield * task . halt ( ) ;
848850 const events = yield * stream . readAll ( ) ;
849851 expect ( results ( events ) ) . toEqual ( [ ] ) ;
@@ -906,7 +908,7 @@ describe("a watch's lifetime", () => {
906908 "" ,
907909 "after {answer.choice}" ,
908910 ] ;
909- const source = watching ( 60 , question ) ;
911+ const source = watching ( null , question ) ;
910912 const first = new InMemoryStream ( ) ;
911913 const reached = withResolvers < void > ( ) ;
912914 const task = yield * started ( fixture , source , first , { holdQuestion : ( ) => reached . resolve ( ) } ) ;
@@ -915,7 +917,7 @@ describe("a watch's lifetime", () => {
915917 yield * task . halt ( ) ;
916918 expect ( results ( prefix ) ) . toHaveLength ( 1 ) ;
917919
918- const before = checkRequests ( fixture ) ;
920+ const before = fixture . store . requests . length ;
919921 fixture . ci . refuses = 500 ;
920922 const continued = yield * run ( fixture , source , new InMemoryStream ( [ ...prefix ] ) , {
921923 answer : { choice : "continue" } ,
@@ -925,7 +927,8 @@ describe("a watch's lifetime", () => {
925927 expect ( Reflect . get ( Object ( rendered ( continued . output . split ( "after" ) [ 0 ] ?? "" ) ) , "outcome" ) ) . toBe (
926928 "success" ,
927929 ) ;
928- expect ( checkRequests ( fixture ) ) . toBe ( before ) ;
930+ expect ( fixture . store . requests ) . toHaveLength ( before ) ;
931+ expect ( fixture . clock . waiters ) . toEqual ( [ ] ) ;
929932 expect ( progress ( continued . live ) ) . toEqual ( [ ] ) ;
930933 } ) ;
931934} ) ;
@@ -936,7 +939,6 @@ describe("what a watch refuses before contacting anything", () => {
936939 const element = `<PullRequest.Checks url=${ JSON . stringify ( URL_1 ) } ` ;
937940 const cases : [ string , string ] [ ] = [
938941 [ `${ element } timeoutSeconds={60} as="checks" />` , "`timeoutSeconds` bounds a watch" ] ,
939- [ `${ element } watch as="checks" />` , "a watch needs `timeoutSeconds`" ] ,
940942 [ `${ element } watch timeoutSeconds={0} as="checks" />` , "Prop validation failed" ] ,
941943 [ `${ element } watch timeoutSeconds={1.5} as="checks" />` , "Prop validation failed" ] ,
942944 [ `${ element } watch timeoutSeconds={60} />` , "must be invoked with `as`" ] ,
@@ -1143,8 +1145,9 @@ describe("the head a watch observed before its collection failed", () => {
11431145 fixture . ci . runs = [ checkRun ( 31 , "build" , "completed" , "success" ) ] ;
11441146 fixture . ci . partial = true ;
11451147 const stream = new InMemoryStream ( ) ;
1146- const task = yield * started ( fixture , watching ( ) , stream ) ;
1148+ const task = yield * started ( fixture , watching ( null ) , stream ) ;
11471149 const retry = yield * fixture . clock . waitFor ( ( at ) => at === START + CHECK_WATCH_RETRY_MS ) ;
1150+ expect ( fixture . clock . waiters . map ( ( { at } ) => at ) ) . toEqual ( [ retry ] ) ;
11481151 delete fixture . ci . partial ;
11491152 fixture . clock . advanceTo ( retry ) ;
11501153 const ran = yield * finished ( task ) ;
@@ -1166,7 +1169,7 @@ describe("the head a watch observed before its collection failed", () => {
11661169 fixture . ci . runs = [ checkRun ( 31 , "build" , "completed" , "success" ) ] ;
11671170 fixture . ci . partial = true ;
11681171 const first = new InMemoryStream ( ) ;
1169- const task = yield * started ( fixture , watching ( ) , first ) ;
1172+ const task = yield * started ( fixture , watching ( null ) , first ) ;
11701173 yield * fixture . clock . waitFor ( ( at ) => at === START + CHECK_WATCH_RETRY_MS ) ;
11711174 yield * task . halt ( ) ;
11721175 const prefix = [ ...( yield * first . readAll ( ) ) ] ;
@@ -1175,18 +1178,77 @@ describe("the head a watch observed before its collection failed", () => {
11751178 ] ) ;
11761179 expect ( results ( prefix ) ) . toEqual ( [ ] ) ;
11771180
1178- fixture . clock . now = START + 20_000 ;
1181+ fixture . clock . now = START + 86_400_000 ;
11791182 pullRequest ( fixture ) . headSha = MOVED ;
11801183 delete fixture . ci . partial ;
11811184 fixture . ci . statuses = [ commitStatus ( 42 , "green" , "success" ) ] ;
1182- const again = yield * run ( fixture , watching ( ) , new InMemoryStream ( [ ...prefix ] ) ) ;
1185+ const again = yield * run ( fixture , watching ( null ) , new InMemoryStream ( [ ...prefix ] ) ) ;
11831186 expect ( again . refusal ) . toBe ( undefined ) ;
11841187 expect ( results ( again . events ) ) . toEqual ( [
11851188 { outcome : "incomplete" , reason : "head-changed" , headSha : HEAD , checks : [ ] } ,
11861189 ] ) ;
11871190 expect ( retained ( again . events , PULL_REQUEST_CHECKS_WATCH_DEADLINE ) ) . toEqual ( [
1188- { deadline : START + 60_000 } ,
1191+ { deadline : null } ,
11891192 ] ) ;
11901193 expect ( pagedAt ( fixture , MOVED ) ) . toBe ( false ) ;
11911194 } ) ;
11921195} ) ;
1196+
1197+ describe ( "read failures without a deadline" , ( ) => {
1198+ it ( "W23: a terminal error before pinning binds read-error without a retry" , function * ( ) {
1199+ const fixture = yield * useFixture ( ) ;
1200+ fixture . ci . pullRefuses = 401 ;
1201+ let requests = 0 ;
1202+ // deno-lint-ignore require-yield
1203+ fixture . ci . before = function * ( ) {
1204+ requests += 1 ;
1205+ } ;
1206+ const task = yield * started ( fixture , watching ( null ) , new InMemoryStream ( ) ) ;
1207+ const ran = yield * finished ( task ) ;
1208+ expect ( results ( ran . events ) ) . toEqual ( [
1209+ { outcome : "incomplete" , reason : "read-error" , headSha : null , checks : [ ] } ,
1210+ ] ) ;
1211+ expect ( requests ) . toBe ( 1 ) ;
1212+ expect ( progress ( ran . live ) ) . toEqual ( [ ] ) ;
1213+ } ) ;
1214+
1215+ it ( "W24: invalid evidence stops an unbounded watch with its last accepted checks" , function * ( ) {
1216+ const fixture = yield * useFixture ( ) ;
1217+ fixture . ci . runs = [ checkRun ( 31 , "build" , "in_progress" , null ) ] ;
1218+ const task = yield * started ( fixture , watching ( null ) , new InMemoryStream ( ) ) ;
1219+ const poll = yield * pollAt ( fixture ) ;
1220+ fixture . ci . runs = [ { ...checkRun ( 32 , "other" , "completed" , "success" ) , head_sha : MOVED } ] ;
1221+ fixture . clock . advanceTo ( poll ) ;
1222+ const ran = yield * finished ( task ) ;
1223+ expect ( results ( ran . events ) ) . toEqual ( [
1224+ {
1225+ outcome : "incomplete" ,
1226+ reason : "read-error" ,
1227+ headSha : HEAD ,
1228+ checks : [ runRecord ( 31 , "build" , "in_progress" , null ) ] ,
1229+ } ,
1230+ ] ) ;
1231+ expect ( progress ( ran . live ) ) . toEqual ( [ "Checks at aaaaaaa: 0 passed, 0 failed, 1 pending" ] ) ;
1232+ } ) ;
1233+
1234+ it ( "W25: a long explicit timeout keeps polling across a maximum timer arm" , function * ( ) {
1235+ const fixture = yield * useFixture ( ) ;
1236+ fixture . ci . statuses = [ commitStatus ( 42 , "green" , "pending" ) ] ;
1237+ const seconds = Number . MAX_SAFE_INTEGER ;
1238+ const task = yield * started ( fixture , watching ( seconds ) , new InMemoryStream ( ) ) ;
1239+ const arm = yield * fixture . clock . waitFor ( ( at ) => at === START + 2_147_483_647 ) ;
1240+ yield * pollAt ( fixture ) ;
1241+ fixture . clock . advanceTo ( arm ) ;
1242+ yield * fixture . clock . waitFor ( ( at ) => at === arm + 2_147_483_647 ) ;
1243+ const next = yield * fixture . clock . waitFor ( ( at ) => at === arm + CHECK_WATCH_POLL_MS ) ;
1244+ fixture . ci . statuses = [ commitStatus ( 42 , "green" , "success" ) ] ;
1245+ fixture . clock . advanceTo ( next ) ;
1246+ const ran = yield * finished ( task ) ;
1247+ expect ( results ( ran . events ) ) . toEqual ( [
1248+ { outcome : "success" , headSha : HEAD , checks : [ statusRecord ( 42 , "green" , "success" ) ] } ,
1249+ ] ) ;
1250+ expect ( retained ( ran . events , PULL_REQUEST_CHECKS_WATCH_DEADLINE ) ) . toEqual ( [
1251+ { deadline : String ( BigInt ( START ) + BigInt ( seconds ) * 1000n ) } ,
1252+ ] ) ;
1253+ } ) ;
1254+ } ) ;
0 commit comments