@@ -95,6 +95,101 @@ def test_side_values(self, default_links):
9595 sides = {lk ["attrs" ]["side" ] for lk in default_links }
9696 assert sides == {"abc1" , "xyz1" }
9797
98+ def test_all_links_have_risk_groups (self , default_links ):
99+ for lk in default_links :
100+ assert "risk_groups" in lk , (
101+ f"Link { lk ['source' ]} ->{ lk ['target' ]} missing risk_groups"
102+ )
103+ assert len (lk ["risk_groups" ]) == 3
104+
105+
106+ # ---------------------------------------------------------------------------
107+ # Risk group assignments on DC-BB links
108+ # ---------------------------------------------------------------------------
109+
110+
111+ class TestDcBbRiskGroups :
112+ """Verify risk group assignments derived from BB endpoint."""
113+
114+ def test_abc1_link_has_plane_site_group (self , default_links ):
115+ """ABC1 DC-BB links include plane_P_site_abc1 from BB endpoint."""
116+ abc1 = [lk for lk in default_links if lk ["attrs" ]["side" ] == "abc1" ]
117+ for lk in abc1 :
118+ # Extract plane from target name bb/abc1/plane{P}/dev{D}
119+ parts = lk ["target" ].split ("/" )
120+ plane = int (parts [2 ].replace ("plane" , "" ))
121+ expected_rg = f"plane_{ plane } _site_abc1"
122+ assert expected_rg in lk ["risk_groups" ], (
123+ f"{ lk ['target' ]} : expected { expected_rg } in { lk ['risk_groups' ]} "
124+ )
125+
126+ def test_xyz1_link_has_plane_site_group (self , default_links ):
127+ """XYZ1 DC-BB links include plane_P_site_xyz1 from BB endpoint."""
128+ xyz1 = [lk for lk in default_links if lk ["attrs" ]["side" ] == "xyz1" ]
129+ for lk in xyz1 :
130+ parts = lk ["target" ].split ("/" )
131+ plane = int (parts [2 ].replace ("plane" , "" ))
132+ expected_rg = f"plane_{ plane } _site_xyz1"
133+ assert expected_rg in lk ["risk_groups" ], (
134+ f"{ lk ['target' ]} : expected { expected_rg } in { lk ['risk_groups' ]} "
135+ )
136+
137+ def test_abc1_link_has_plane_group (self , default_links ):
138+ """ABC1 DC-BB links include plane_group_G from BB endpoint's plane."""
139+ abc1 = [lk for lk in default_links if lk ["attrs" ]["side" ] == "abc1" ]
140+ for lk in abc1 :
141+ parts = lk ["target" ].split ("/" )
142+ plane = int (parts [2 ].replace ("plane" , "" ))
143+ pg = (plane - 1 ) // 4 + 1
144+ expected_rg = f"plane_group_{ pg } "
145+ assert expected_rg in lk ["risk_groups" ]
146+
147+ def test_abc1_link_has_device_index_group (self , default_links ):
148+ """ABC1 DC-BB links include pg_G_idx_D_abc1 from BB endpoint."""
149+ abc1 = [lk for lk in default_links if lk ["attrs" ]["side" ] == "abc1" ]
150+ for lk in abc1 :
151+ parts = lk ["target" ].split ("/" )
152+ plane = int (parts [2 ].replace ("plane" , "" ))
153+ dev = int (parts [3 ].replace ("dev" , "" ))
154+ pg = (plane - 1 ) // 4 + 1
155+ expected_rg = f"pg_{ pg } _idx_{ dev } _abc1"
156+ assert expected_rg in lk ["risk_groups" ]
157+
158+ def test_xyz1_link_has_device_index_group (self , default_links ):
159+ """XYZ1 DC-BB links include pg_G_idx_D_xyz1 from BB endpoint."""
160+ xyz1 = [lk for lk in default_links if lk ["attrs" ]["side" ] == "xyz1" ]
161+ for lk in xyz1 :
162+ parts = lk ["target" ].split ("/" )
163+ plane = int (parts [2 ].replace ("plane" , "" ))
164+ dev = int (parts [3 ].replace ("dev" , "" ))
165+ pg = (plane - 1 ) // 4 + 1
166+ expected_rg = f"pg_{ pg } _idx_{ dev } _xyz1"
167+ assert expected_rg in lk ["risk_groups" ]
168+
169+ def test_spot_check_specific_abc1_link (self , default_links ):
170+ """Spot-check: FADU->bb/abc1/plane7/dev2 should have specific risk groups."""
171+ abc1 = [lk for lk in default_links if lk ["attrs" ]["side" ] == "abc1" ]
172+ target_links = [lk for lk in abc1 if lk ["target" ] == "bb/abc1/plane7/dev2" ]
173+ assert len (target_links ) > 0 , "No links to bb/abc1/plane7/dev2"
174+ for lk in target_links :
175+ assert lk ["risk_groups" ] == [
176+ "plane_7_site_abc1" ,
177+ "plane_group_2" ,
178+ "pg_2_idx_2_abc1" ,
179+ ]
180+
181+ def test_spot_check_specific_xyz1_link (self , default_links ):
182+ """Spot-check: XSW->bb/xyz1/plane7/dev3 should have specific risk groups."""
183+ xyz1 = [lk for lk in default_links if lk ["attrs" ]["side" ] == "xyz1" ]
184+ target_links = [lk for lk in xyz1 if lk ["target" ] == "bb/xyz1/plane7/dev3" ]
185+ assert len (target_links ) > 0 , "No links to bb/xyz1/plane7/dev3"
186+ for lk in target_links :
187+ assert lk ["risk_groups" ] == [
188+ "plane_7_site_xyz1" ,
189+ "plane_group_2" ,
190+ "pg_2_idx_3_xyz1" ,
191+ ]
192+
98193
99194# ---------------------------------------------------------------------------
100195# Node name validity
0 commit comments