77from typing import Any , Callable
88
99from ..contract import scan_public_boundary
10- from .planner import REPO_ROOT
10+ from .planner import REPO_ROOT , resolve_canary_catalog_path
1111from .runner import build_canary_smoke_suite_run
1212
1313
@@ -172,8 +172,8 @@ def _public_boundary_changed_files_run(
172172 except ValueError :
173173 display_paths .append (str (path ))
174174 display_argv = ["loopx" , "check" ]
175- for path in display_paths :
176- display_argv .extend (["--scan-path" , path ])
175+ for display_path in display_paths :
176+ display_argv .extend (["--scan-path" , display_path ])
177177 check : dict [str , Any ] = {
178178 "source" : "premerge_public_boundary" ,
179179 "tier" : "default" ,
@@ -621,11 +621,8 @@ def _gate_status(
621621
622622
623623def _check_command (check : dict [str , Any ]) -> str :
624- normalized = (
625- check .get ("normalized" )
626- if isinstance (check .get ("normalized" ), dict )
627- else {}
628- )
624+ normalized_value = check .get ('normalized' )
625+ normalized = normalized_value if isinstance (normalized_value , dict ) else {}
629626 display_argv = normalized .get ("display_argv" )
630627 if isinstance (display_argv , list ) and display_argv :
631628 return " " .join (str (part ) for part in display_argv )
@@ -717,12 +714,10 @@ def apply_change_quality_verification(
717714 verification .get ("enforcement_applied" )
718715 and verification .get ("ok" ) is False
719716 )
720- gate = payload .get ("gate" ) if isinstance (payload .get ("gate" ), dict ) else {}
721- summary = (
722- payload .get ("validation_summary" )
723- if isinstance (payload .get ("validation_summary" ), dict )
724- else {}
725- )
717+ gate_value = payload .get ('gate' )
718+ gate = gate_value if isinstance (gate_value , dict ) else {}
719+ summary_value = payload .get ('validation_summary' )
720+ summary = summary_value if isinstance (summary_value , dict ) else {}
726721 gate ["quality_receipt_failure_count" ] = 1 if enforced_failure else 0
727722 summary ["policy_failure_count" ] = 1 if enforced_failure else 0
728723 if enforced_failure :
@@ -830,9 +825,12 @@ def build_premerge_validation_gate(
830825 include_deep_checks : bool | None = None ,
831826 progress_callback : ProgressCallback | None = None ,
832827 repo_root : Path | None = None ,
828+ catalog_path : Path | None = None ,
833829) -> dict [str , Any ]:
834830 target_repo_root = (repo_root or REPO_ROOT ).resolve ()
835831 files = _dedupe (list (changed_files or []))
832+ if files :
833+ catalog_path = resolve_canary_catalog_path (catalog_path , repo_root = target_repo_root )
836834 classification = classify_premerge_surfaces (files , repo_root = target_repo_root )
837835 limits = _tier_limits (tier )
838836 include_deep = bool (limits ["deep" ] if include_deep_checks is None else include_deep_checks )
@@ -874,6 +872,7 @@ def build_premerge_validation_gate(
874872 if module_colocation is not None :
875873 direct_checks .append (module_colocation )
876874
875+ catalog_run : dict [str , Any ]
877876 if files :
878877 catalog_progress = _section_progress_callback (
879878 progress_callback ,
@@ -886,6 +885,8 @@ def build_premerge_validation_gate(
886885 )
887886 catalog_run = build_canary_smoke_suite_run (
888887 suite = "catalog-plan" ,
888+ repo_root = target_repo_root ,
889+ catalog_path = catalog_path ,
889890 changed_files = files ,
890891 include_deep_checks = include_deep ,
891892 max_checks_per_family = 3 ,
@@ -905,10 +906,12 @@ def build_premerge_validation_gate(
905906 executed_check_count = catalog_run .get ("executed_check_count" ),
906907 failure_count = catalog_run .get ("failure_count" ),
907908 )
908- catalog_run = downgrade_inherited_baseline_failures (
909+ adjusted_catalog_run = downgrade_inherited_baseline_failures (
909910 catalog_run ,
910911 changed_files = files ,
911912 )
913+ assert adjusted_catalog_run is not None # A dictionary input retains a result.
914+ catalog_run = adjusted_catalog_run
912915 else :
913916 catalog_run = _empty_smoke_suite_run (
914917 suite = "catalog-plan" ,
@@ -940,6 +943,8 @@ def build_premerge_validation_gate(
940943 )
941944 risk_profile_run = build_canary_smoke_suite_run (
942945 suite = "default-public" ,
946+ repo_root = target_repo_root ,
947+ catalog_path = catalog_path ,
943948 profiles = risk_profiles ,
944949 include_deep_checks = include_deep ,
945950 limit = profile_limit ,
@@ -1094,12 +1099,10 @@ def _emit_section_progress(
10941099
10951100
10961101def render_premerge_validation_gate_markdown (payload : dict [str , Any ]) -> str :
1097- gate = payload .get ("gate" ) if isinstance (payload .get ("gate" ), dict ) else {}
1098- classification = (
1099- payload .get ("classification" )
1100- if isinstance (payload .get ("classification" ), dict )
1101- else {}
1102- )
1102+ gate_value = payload .get ('gate' )
1103+ gate = gate_value if isinstance (gate_value , dict ) else {}
1104+ classification_value = payload .get ('classification' )
1105+ classification = classification_value if isinstance (classification_value , dict ) else {}
11031106 lines = [
11041107 "# Pre-Merge Validation Gate" ,
11051108 "" ,
@@ -1152,11 +1155,8 @@ def append_run(title: str, run: Any) -> None:
11521155 for check in run .get ("selected_checks" , [])[:12 ]:
11531156 if not isinstance (check , dict ):
11541157 continue
1155- normalized = (
1156- check .get ("normalized" )
1157- if isinstance (check .get ("normalized" ), dict )
1158- else {}
1159- )
1158+ normalized_value = check .get ('normalized' )
1159+ normalized = normalized_value if isinstance (normalized_value , dict ) else {}
11601160 command = " " .join (str (part ) for part in normalized .get ("display_argv" ) or [])
11611161 lines .append (f"- `{ check .get ('status' ) or 'ready' } ` { command or check .get ('command' )} " )
11621162 if check .get ("advisory_reason" ):
@@ -1172,11 +1172,8 @@ def append_run(title: str, run: Any) -> None:
11721172 else None
11731173 )
11741174 if quality is not None :
1175- evidence = (
1176- quality .get ("pr_evidence" )
1177- if isinstance (quality .get ("pr_evidence" ), dict )
1178- else {}
1179- )
1175+ evidence_value = quality .get ('pr_evidence' )
1176+ evidence = evidence_value if isinstance (evidence_value , dict ) else {}
11801177 lines .extend (
11811178 [
11821179 "" ,
0 commit comments