@@ -43,6 +43,19 @@ def _insert_legacy_report_output(
4343 ),
4444 )
4545
46+ def _display_run_id (self , test_db , report_output_id : int ) -> str :
47+ row = test_db .query (
48+ """
49+ SELECT id FROM report_output_runs
50+ WHERE report_output_id = ?
51+ ORDER BY run_sequence DESC
52+ LIMIT 1
53+ """ ,
54+ (report_output_id ,),
55+ ).fetchone ()
56+ assert row is not None
57+ return row ["id" ]
58+
4659 def test_resolves_to_canonical_report_output_id_when_mapping_exists (self , test_db ):
4760 simulation = simulation_service .create_simulation (
4861 country_id = "us" ,
@@ -61,6 +74,9 @@ def test_resolves_to_canonical_report_output_id_when_mapping_exists(self, test_d
6174 id_map_service .set_mapping (
6275 legacy_report_output_id = 999 ,
6376 canonical_report_output_id = canonical_report ["id" ],
77+ display_report_output_run_id = self ._display_run_id (
78+ test_db , canonical_report ["id" ]
79+ ),
6480 )
6581
6682 resolved_id = id_map_service .resolve_canonical_report_output_id (999 )
@@ -109,13 +125,19 @@ def test_set_mapping_is_idempotent_for_same_canonical_report_output(self, test_d
109125 id_map_service .set_mapping (
110126 legacy_report_output_id = 1001 ,
111127 canonical_report_output_id = canonical_report ["id" ],
128+ display_report_output_run_id = self ._display_run_id (
129+ test_db , canonical_report ["id" ]
130+ ),
112131 )
113132 is True
114133 )
115134 assert (
116135 id_map_service .set_mapping (
117136 legacy_report_output_id = 1001 ,
118137 canonical_report_output_id = canonical_report ["id" ],
138+ display_report_output_run_id = self ._display_run_id (
139+ test_db , canonical_report ["id" ]
140+ ),
119141 )
120142 is True
121143 )
@@ -139,10 +161,35 @@ def test_rejects_mapping_to_missing_canonical_report_output(self, test_db):
139161 id_map_service .set_mapping (
140162 legacy_report_output_id = 1002 ,
141163 canonical_report_output_id = 999999 ,
164+ display_report_output_run_id = "missing-run" ,
142165 )
143166
144167 assert "Canonical report output #999999 not found" in str (exc_info .value )
145168
169+ def test_rejects_mapping_to_missing_display_report_output_run (self , test_db ):
170+ simulation = simulation_service .create_simulation (
171+ country_id = "us" ,
172+ population_id = "household_3b" ,
173+ population_type = "household" ,
174+ policy_id = 3 ,
175+ )
176+ canonical_report = report_output_service .create_report_output (
177+ country_id = "us" ,
178+ simulation_1_id = simulation ["id" ],
179+ simulation_2_id = None ,
180+ year = "2025" ,
181+ )
182+ self ._insert_legacy_report_output (test_db , 10020 , canonical_report )
183+
184+ with pytest .raises (ValueError ) as exc_info :
185+ id_map_service .set_mapping (
186+ legacy_report_output_id = 10020 ,
187+ canonical_report_output_id = canonical_report ["id" ],
188+ display_report_output_run_id = "missing-run" ,
189+ )
190+
191+ assert "Display report output run #missing-run not found" in str (exc_info .value )
192+
146193 def test_rejects_conflicting_mapping_remap (self , test_db ):
147194 simulation = simulation_service .create_simulation (
148195 country_id = "us" ,
@@ -166,12 +213,18 @@ def test_rejects_conflicting_mapping_remap(self, test_db):
166213 id_map_service .set_mapping (
167214 legacy_report_output_id = 1003 ,
168215 canonical_report_output_id = canonical_report ["id" ],
216+ display_report_output_run_id = self ._display_run_id (
217+ test_db , canonical_report ["id" ]
218+ ),
169219 )
170220
171221 with pytest .raises (ValueError ) as exc_info :
172222 id_map_service .set_mapping (
173223 legacy_report_output_id = 1003 ,
174224 canonical_report_output_id = other_report ["id" ],
225+ display_report_output_run_id = self ._display_run_id (
226+ test_db , other_report ["id" ]
227+ ),
175228 )
176229
177230 assert (
@@ -197,6 +250,9 @@ def test_allows_mapping_when_legacy_report_output_is_missing(self, test_db):
197250 id_map_service .set_mapping (
198251 legacy_report_output_id = 10030 ,
199252 canonical_report_output_id = canonical_report ["id" ],
253+ display_report_output_run_id = self ._display_run_id (
254+ test_db , canonical_report ["id" ]
255+ ),
200256 )
201257 is True
202258 )
@@ -205,6 +261,9 @@ def test_allows_mapping_when_legacy_report_output_is_missing(self, test_db):
205261 assert resolved == {
206262 "requested_report_output_id" : 10030 ,
207263 "canonical_report_output_id" : canonical_report ["id" ],
264+ "display_report_output_run_id" : self ._display_run_id (
265+ test_db , canonical_report ["id" ]
266+ ),
208267 "is_legacy_id" : True ,
209268 }
210269
@@ -270,6 +329,9 @@ def test_rejects_mapping_when_reports_do_not_share_canonical_identity(
270329 id_map_service .set_mapping (
271330 legacy_report_output_id = distinct_report ["id" ],
272331 canonical_report_output_id = canonical_report ["id" ],
332+ display_report_output_run_id = self ._display_run_id (
333+ test_db , canonical_report ["id" ]
334+ ),
273335 )
274336
275337 assert "must share canonical report identity" in str (exc_info .value )
@@ -307,6 +369,9 @@ def test_rejects_mapping_when_legacy_report_output_has_no_identity(self, test_db
307369 id_map_service .set_mapping (
308370 legacy_report_output_id = 10031 ,
309371 canonical_report_output_id = canonical_report ["id" ],
372+ display_report_output_run_id = self ._display_run_id (
373+ test_db , canonical_report ["id" ]
374+ ),
310375 )
311376
312377 assert "must have canonical report identity" in str (exc_info .value )
@@ -329,6 +394,9 @@ def test_rejects_mapping_when_legacy_and_canonical_ids_match(self, test_db):
329394 id_map_service .set_mapping (
330395 legacy_report_output_id = canonical_report ["id" ],
331396 canonical_report_output_id = canonical_report ["id" ],
397+ display_report_output_run_id = self ._display_run_id (
398+ test_db , canonical_report ["id" ]
399+ ),
332400 )
333401
334402 assert "must be different" in str (exc_info .value )
@@ -352,6 +420,9 @@ def test_rejects_mapping_resolution_when_canonical_report_output_is_missing(
352420 id_map_service .set_mapping (
353421 legacy_report_output_id = 1004 ,
354422 canonical_report_output_id = canonical_report ["id" ],
423+ display_report_output_run_id = self ._display_run_id (
424+ test_db , canonical_report ["id" ]
425+ ),
355426 )
356427 test_db .query (
357428 "DELETE FROM report_outputs WHERE id = ?" ,
0 commit comments