@@ -166,6 +166,29 @@ def test__given_explicit_uri__then_managed_resolution_requires_opt_in(self):
166166 == dataset
167167 )
168168
169+ def test__given_local_dataset_path__then_managed_resolution_requires_opt_in (
170+ self ,
171+ tmp_path ,
172+ ):
173+ dataset_path = tmp_path / "local_2100.h5"
174+ dataset_path .write_bytes (b"not a real h5; resolution only" )
175+
176+ try :
177+ resolve_managed_dataset_reference ("us" , str (dataset_path ))
178+ except ValueError as error :
179+ assert (
180+ "Local dataset paths bypass the policyengine.py release bundle"
181+ in str (error )
182+ )
183+ else :
184+ raise AssertionError ("Expected local dataset path to be rejected" )
185+
186+ assert resolve_managed_dataset_reference (
187+ "us" ,
188+ str (dataset_path ),
189+ allow_unmanaged = True ,
190+ ) == str (dataset_path .resolve ())
191+
169192 def test__given_versioned_dataset_url__then_logical_name_drops_version (self ):
170193 dataset = "hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5@1.73.0"
171194
@@ -633,6 +656,25 @@ def test__given_us_unmanaged_dataset_uri__then_source_is_not_rewritten(self):
633656 assert microsim .policyengine_bundle ["runtime_dataset_uri" ] == dataset
634657 assert microsim .policyengine_bundle ["runtime_dataset_source" ] == dataset
635658
659+ def test__given_us_unmanaged_local_dataset__then_source_is_local_path (
660+ self ,
661+ tmp_path ,
662+ ):
663+ dataset_path = tmp_path / "local_2100.h5"
664+ dataset_path .write_bytes (b"not a real h5; source plumbing only" )
665+
666+ with patch ("policyengine_us.Microsimulation" ) as mock_microsimulation :
667+ microsim = managed_us_microsimulation (
668+ dataset = str (dataset_path ),
669+ allow_unmanaged = True ,
670+ )
671+
672+ resolved_path = str (dataset_path .resolve ())
673+ assert mock_microsimulation .call_args .kwargs ["dataset" ] == resolved_path
674+ assert microsim .policyengine_bundle ["runtime_dataset" ] == "local_2100"
675+ assert microsim .policyengine_bundle ["runtime_dataset_uri" ] == resolved_path
676+ assert microsim .policyengine_bundle ["runtime_dataset_source" ] == resolved_path
677+
636678 def test__given_uk_managed_dataset_name__then_resolves_within_bundle (self ):
637679 with patch ("policyengine_uk.Microsimulation" ) as mock_microsimulation :
638680 microsim = managed_uk_microsimulation (dataset = "enhanced_frs_2023_24" )
0 commit comments