@@ -129,7 +129,9 @@ def test_deferred_architecture_rejects_before_source_read_or_output(self, tmp_pa
129129 reason = "independent parity is missing" ,
130130 ),
131131 ),
132- mock .patch ("mobius.integrations.gguf._runtime_package.GGUFModel" ) as read_source ,
132+ mock .patch (
133+ "mobius.integrations.gguf._runtime_package.open_gguf_model"
134+ ) as read_source ,
133135 pytest .raises (ValueError , match = r"runtime packaging.*deferred" ),
134136 ):
135137 _write_runtime (pkg , tmp_path / "m.gguf" , out )
@@ -141,8 +143,12 @@ def test_atomically_emits_graph_tokenizer_and_runtime_config(self, tmp_path):
141143 out = tmp_path / "out"
142144 with (
143145 mock .patch (
144- "mobius.integrations.gguf._runtime_package.GGUFModel" ,
145- return_value = SimpleNamespace (metadata = {}, architecture = "llama" ),
146+ "mobius.integrations.gguf._runtime_package.open_gguf_model" ,
147+ return_value = SimpleNamespace (
148+ metadata = {},
149+ architecture = "llama" ,
150+ source_matches_path = lambda : True ,
151+ ),
146152 ),
147153 mock .patch (
148154 "mobius.integrations.gguf._runtime_package.inspect_gguf_tokenizer" ,
@@ -164,11 +170,41 @@ def test_atomically_emits_graph_tokenizer_and_runtime_config(self, tmp_path):
164170 assert Path (artifacts ["inference_metadata" ]) == out / "inference_metadata.yaml"
165171 assert not list (tmp_path .glob (".out.*.tmp" ))
166172
173+ def test_failure_after_graph_save_removes_staging_and_publishes_nothing (self , tmp_path ):
174+ pkg = _FakePackage ()
175+ out = tmp_path / "out"
176+ with (
177+ mock .patch (
178+ "mobius.integrations.gguf._runtime_package.open_gguf_model" ,
179+ return_value = SimpleNamespace (
180+ metadata = {},
181+ architecture = "llama" ,
182+ source_matches_path = lambda : True ,
183+ ),
184+ ),
185+ mock .patch (
186+ "mobius.integrations.gguf._runtime_package.inspect_gguf_tokenizer" ,
187+ return_value = _materialized (),
188+ ),
189+ mock .patch (
190+ "mobius.integrations.gguf._runtime_package.materialize_gguf_tokenizer" ,
191+ side_effect = OSError ("tokenizer asset write failed" ),
192+ ),
193+ pytest .raises (OSError , match = "tokenizer asset write failed" ),
194+ ):
195+ _write_runtime (pkg , tmp_path / "m.gguf" , out )
196+
197+ assert pkg .saved_to is not None
198+ assert not out .exists ()
199+ assert not list (tmp_path .glob (".out.*.tmp" ))
200+
167201 def test_missing_pinned_tokenizer_source_rejects_before_save_or_output (self , tmp_path ):
168202 pkg = _FakePackage ()
169203 out = tmp_path / "out"
170204 with (
171- mock .patch ("mobius.integrations.gguf._runtime_package.GGUFModel" ) as read_source ,
205+ mock .patch (
206+ "mobius.integrations.gguf._runtime_package.open_gguf_model"
207+ ) as read_source ,
172208 pytest .raises (ValueError , match = "explicit tokenizer_repository" ),
173209 ):
174210 write_gguf_runtime_package (pkg , tmp_path / "m.gguf" , out )
@@ -181,8 +217,12 @@ def test_replaced_source_tokenizer_rejects_before_save_or_output(self, tmp_path)
181217 out = tmp_path / "out"
182218 with (
183219 mock .patch (
184- "mobius.integrations.gguf._runtime_package.GGUFModel" ,
185- return_value = SimpleNamespace (metadata = {}, architecture = "llama" ),
220+ "mobius.integrations.gguf._runtime_package.open_gguf_model" ,
221+ return_value = SimpleNamespace (
222+ metadata = {},
223+ architecture = "llama" ,
224+ source_matches_path = lambda : True ,
225+ ),
186226 ),
187227 mock .patch (
188228 "mobius.integrations.gguf._runtime_package.inspect_gguf_tokenizer" ,
@@ -205,7 +245,9 @@ def test_existing_output_is_never_replaced(self, tmp_path):
205245 sentinel = out / "sentinel.bin"
206246 sentinel .write_bytes (b"unchanged" )
207247 with (
208- mock .patch ("mobius.integrations.gguf._runtime_package.GGUFModel" ) as read_source ,
248+ mock .patch (
249+ "mobius.integrations.gguf._runtime_package.open_gguf_model"
250+ ) as read_source ,
209251 pytest .raises (FileExistsError , match = "non-atomic directory replacement" ),
210252 ):
211253 _write_runtime (pkg , tmp_path / "m.gguf" , out )
@@ -246,7 +288,9 @@ def test_runtime_rejects_unevidenced_mtp_before_source_read(self, tmp_path, runt
246288 pkg .mtp_head = SimpleNamespace (config = object ())
247289 out = tmp_path / "out"
248290 with (
249- mock .patch ("mobius.integrations.gguf._runtime_package.GGUFModel" ) as read_source ,
291+ mock .patch (
292+ "mobius.integrations.gguf._runtime_package.open_gguf_model"
293+ ) as read_source ,
250294 pytest .raises (ValueError , match = "runtime-evidenced GGUF MTP" ),
251295 ):
252296 _write_runtime (pkg , tmp_path / "m.gguf" , out , runtime = runtime )
@@ -261,7 +305,9 @@ def test_unknown_runtime_rejects_before_source_read(self, tmp_path):
261305
262306 def test_save_model_false_is_rejected_before_source_read (self , tmp_path ):
263307 with (
264- mock .patch ("mobius.integrations.gguf._runtime_package.GGUFModel" ) as read_source ,
308+ mock .patch (
309+ "mobius.integrations.gguf._runtime_package.open_gguf_model"
310+ ) as read_source ,
265311 pytest .raises (ValueError , match = "save_model=False is not supported" ),
266312 ):
267313 write_gguf_runtime_package (
0 commit comments