4949REVIEW_STATUS_CODES = {403 , 408 , 425 , 429 }
5050RETRY_STATUS_CODES = {408 , 425 , 429 , 500 , 502 , 503 , 504 }
5151REDIRECT_STATUS_CODES = {301 , 302 , 303 , 307 , 308 }
52+ REPORT_STATUSES = ("working" , "redirect" , "review" , "broken" , "blocked" , "error" )
53+ ACTIONABLE_STATUSES = ("review" , "broken" , "blocked" , "error" )
5254MAX_REDIRECTS = 5
5355MAX_BACKOFF_SECONDS = 5.0
5456KNOWN_METADATA_HOSTS = {
@@ -610,8 +612,10 @@ def select_links(
610612def build_report (
611613 * , catalog : Path , mode : str , results : list [LinkResult ]
612614) -> dict [str , Any ]:
613- statuses = ("working" , "redirect" , "review" , "broken" , "blocked" , "error" )
614- counts = {status : sum (item .status == status for item in results ) for status in statuses }
615+ counts = {
616+ status : sum (item .status == status for item in results )
617+ for status in REPORT_STATUSES
618+ }
615619 counts ["total" ] = len (results )
616620 return {
617621 "schema_version" : 1 ,
@@ -624,13 +628,30 @@ def build_report(
624628
625629
626630def exit_code_for_report (report : Mapping [str , Any ]) -> int :
631+ if not isinstance (report , Mapping ):
632+ return 2
627633 counts = report .get ("counts" , {})
628634 if not isinstance (counts , Mapping ):
629635 return 2
630- actionable_statuses = ("review" , "broken" , "blocked" , "error" )
631- if any (counts .get (status , 0 ) for status in actionable_statuses ):
636+ expected_keys = {* REPORT_STATUSES , "total" }
637+ if set (counts ) != expected_keys :
638+ return 2
639+ values = [counts [status ] for status in REPORT_STATUSES ]
640+ total = counts ["total" ]
641+ if (
642+ not isinstance (total , int )
643+ or isinstance (total , bool )
644+ or total <= 0
645+ or any (
646+ not isinstance (value , int ) or isinstance (value , bool ) or value < 0
647+ for value in values
648+ )
649+ or sum (values ) != total
650+ ):
651+ return 2
652+ if any (counts [status ] for status in ACTIONABLE_STATUSES ):
632653 return 1
633- return 1 if counts . get ( "total" ) == 0 else 0
654+ return 0
634655
635656
636657def _positive_float (value : str ) -> float :
0 commit comments