@@ -132,12 +132,14 @@ def _source_model():
132132
133133
134134def _write_runtime (pkg , source , output , ** kwargs ):
135+ tokenizer_repository = kwargs .pop ("tokenizer_repository" , _TOKENIZER_REPOSITORY )
136+ tokenizer_revision = kwargs .pop ("tokenizer_revision" , _TOKENIZER_REVISION )
135137 return write_gguf_runtime_package (
136138 pkg ,
137139 source ,
138140 output ,
139- tokenizer_repository = _TOKENIZER_REPOSITORY ,
140- tokenizer_revision = _TOKENIZER_REVISION ,
141+ tokenizer_repository = tokenizer_repository ,
142+ tokenizer_revision = tokenizer_revision ,
141143 ** kwargs ,
142144 )
143145
@@ -476,7 +478,15 @@ def test_atomically_emits_graph_tokenizer_and_runtime_config(self, tmp_path):
476478 assert (out / "export_report.json" ).is_file ()
477479 assert not list (tmp_path .glob (".out.*.tmp" ))
478480
479- def test_exact_runtime_evidence_marks_package_validated (self , tmp_path ):
481+ @pytest .mark .parametrize (
482+ "tokenizer_kwargs" ,
483+ (
484+ {},
485+ {"tokenizer_repository" : None , "tokenizer_revision" : None },
486+ ),
487+ ids = ("matching-explicit-tokenizer" , "evidence-pinned-tokenizer" ),
488+ )
489+ def test_exact_runtime_evidence_marks_package_validated (self , tmp_path , tokenizer_kwargs ):
480490 pkg = _FakePackage ()
481491 blocker = GGUFTokenizerVerdict (
482492 route = "deferred" ,
@@ -533,7 +543,13 @@ def test_exact_runtime_evidence_marks_package_validated(self, tmp_path):
533543 ),
534544 ) as package_identity ,
535545 ):
536- _write_runtime (pkg , tmp_path / "m.gguf" , out , runtime_version = "0.15.2" )
546+ _write_runtime (
547+ pkg ,
548+ tmp_path / "m.gguf" ,
549+ out ,
550+ runtime_version = "0.15.2" ,
551+ ** tokenizer_kwargs ,
552+ )
537553
538554 assert package_identity .call_args_list [0 ].kwargs ["files" ] == ("model.onnx" ,)
539555 assert pkg .export_report is not None
@@ -549,6 +565,24 @@ def test_exact_runtime_evidence_marks_package_validated(self, tmp_path):
549565 assert compatibility ["runtime_validation_status" ] == "validated"
550566 assert compatibility ["runtime_evidence_id" ] == "test-evidence"
551567
568+ def test_explicit_tokenizer_conflict_rejects_before_package_save (self , tmp_path ):
569+ pkg = _FakePackage ()
570+ with (
571+ _successful_runtime_dependencies (),
572+ pytest .raises (ValueError , match = "conflicts with exact runtime evidence" ),
573+ ):
574+ _write_runtime (
575+ pkg ,
576+ tmp_path / "m.gguf" ,
577+ tmp_path / "out" ,
578+ runtime_version = "0.15.2" ,
579+ tokenizer_repository = "attacker/replacement" ,
580+ tokenizer_revision = "d" * 40 ,
581+ )
582+
583+ assert pkg .saved_to is None
584+ assert not (tmp_path / "out" ).exists ()
585+
552586 def test_missing_evidence_runtime_version_does_not_block_export (self , tmp_path ):
553587 pkg = _FakePackage ()
554588 out = tmp_path / "out"
@@ -686,14 +720,24 @@ def test_tokenizer_blocker_omits_only_tokenizer_assets(self, tmp_path, caplog):
686720 with (
687721 caplog .at_level ("WARNING" ),
688722 _successful_runtime_dependencies (),
723+ mock .patch (
724+ "mobius.integrations.gguf._runtime_package.matching_runtime_evidence" ,
725+ return_value = None ,
726+ ),
689727 mock .patch (
690728 "mobius.integrations.gguf._runtime_package.inspect_gguf_tokenizer" ,
691729 return_value = blocker ,
692730 ),
693731 ):
694732 pkg .gguf_tokenizer_verdict = blocker
695733 attach_tokenizer_export_report (pkg , blocker , model_route = "llama" )
696- artifacts = _write_runtime (pkg , tmp_path / "m.gguf" , out )
734+ artifacts = _write_runtime (
735+ pkg ,
736+ tmp_path / "m.gguf" ,
737+ out ,
738+ tokenizer_repository = None ,
739+ tokenizer_revision = None ,
740+ )
697741
698742 assert (out / "model.onnx" ).is_file ()
699743 assert Path (artifacts ["export_report" ]).is_file ()
0 commit comments