@@ -251,13 +251,110 @@ def test_changed_coverage_forces_rebuild(self, stamp):
251251 build_hooks ._check_build_config ("gnu" , False , True )
252252 assert build_hooks .force_build_ext is True
253253
254- @pytest .mark .agent_authored (model = "glm -5.2 " )
254+ @pytest .mark .agent_authored (model = "gpt -5.6-sol " )
255255 def test_record_writes_stamp (self , stamp ):
256- # record_build_config re-derives from env; pass debug=False to match.
257- # Platform default toolchain: msvc on Windows, gnu on Linux.
256+ build_hooks .record_build_config ("cu13-gnu-debug" )
257+ assert stamp .read_text ().strip () == "cu13-gnu-debug"
258+
259+
260+ class TestBuildHookStamping :
261+ @pytest .mark .agent_authored (model = "gpt-5.6-sol" )
262+ def test_wheel_records_exact_prepared_config_after_success (self , monkeypatch ):
263+ events = []
264+
265+ def prepare (debug ):
266+ events .append (("prepare" , debug ))
267+ return "cu13-gnu-debug"
268+
269+ def build (wheel_directory , config_settings , metadata_directory ):
270+ events .append ("build" )
271+ return "cuda_core.whl"
272+
273+ monkeypatch .setattr (build_hooks , "_build_cuda_core" , prepare )
274+ monkeypatch .setattr (build_hooks ._build_meta , "build_wheel" , build )
275+ monkeypatch .setattr (build_hooks , "record_build_config" , lambda key : events .append (("record" , key )))
276+
277+ wheel_name = build_hooks .build_wheel ("dist" , {"debug" : True }, "metadata" )
278+
279+ assert wheel_name == "cuda_core.whl"
280+ assert events == [("prepare" , True ), "build" , ("record" , "cu13-gnu-debug" )]
281+
282+ @pytest .mark .agent_authored (model = "gpt-5.6-sol" )
283+ def test_editable_records_default_config_after_patch (self , monkeypatch ):
284+ events = []
285+ expected_debug = sys .platform != "win32"
258286 toolchain = "msvc" if sys .platform == "win32" else "gnu"
259- build_hooks .record_build_config (False )
260- assert stamp .read_text ().strip () == f"cu13-{ toolchain } -opt"
287+ expected_key = f"cu13-{ toolchain } -{ 'debug' if expected_debug else 'opt' } "
288+
289+ def prepare (debug ):
290+ events .append (("prepare" , debug ))
291+ return expected_key
292+
293+ monkeypatch .setattr (build_hooks , "_build_cuda_core" , prepare )
294+ monkeypatch .setattr (
295+ build_hooks ._build_meta ,
296+ "build_editable" ,
297+ lambda * _args : events .append ("build" ) or "cuda_core.whl" ,
298+ )
299+ monkeypatch .setattr (
300+ build_hooks ,
301+ "_add_cython_include_paths_to_pth" ,
302+ lambda wheel_path : events .append (("patch" , wheel_path )),
303+ )
304+ monkeypatch .setattr (build_hooks , "record_build_config" , lambda key : events .append (("record" , key )))
305+
306+ wheel_name = build_hooks .build_editable ("dist" )
307+
308+ assert wheel_name == "cuda_core.whl"
309+ assert events == [
310+ ("prepare" , expected_debug ),
311+ "build" ,
312+ ("patch" , os .path .join ("dist" , "cuda_core.whl" )),
313+ ("record" , expected_key ),
314+ ]
315+
316+ @pytest .mark .agent_authored (model = "gpt-5.6-sol" )
317+ def test_failed_wheel_build_does_not_record_config (self , monkeypatch ):
318+ monkeypatch .setattr (
319+ build_hooks ,
320+ "_build_cuda_core" ,
321+ lambda debug : f"cu13-gnu-{ 'debug' if debug else 'opt' } " ,
322+ )
323+
324+ def fail (* args ):
325+ raise RuntimeError ("wheel build failed" )
326+
327+ monkeypatch .setattr (build_hooks ._build_meta , "build_wheel" , fail )
328+ monkeypatch .setattr (
329+ build_hooks ,
330+ "record_build_config" ,
331+ lambda _key : pytest .fail ("failed build must not be stamped" ),
332+ )
333+
334+ with pytest .raises (RuntimeError , match = "wheel build failed" ):
335+ build_hooks .build_wheel ("dist" , {"debug" : True }, "metadata" )
336+
337+ @pytest .mark .agent_authored (model = "gpt-5.6-sol" )
338+ def test_failed_editable_patch_does_not_record_config (self , monkeypatch ):
339+ monkeypatch .setattr (
340+ build_hooks ,
341+ "_build_cuda_core" ,
342+ lambda debug : f"cu13-gnu-{ 'debug' if debug else 'opt' } " ,
343+ )
344+ monkeypatch .setattr (build_hooks ._build_meta , "build_editable" , lambda * _args : "cuda_core.whl" )
345+
346+ def fail (wheel_path ):
347+ raise RuntimeError ("editable patch failed" )
348+
349+ monkeypatch .setattr (build_hooks , "_add_cython_include_paths_to_pth" , fail )
350+ monkeypatch .setattr (
351+ build_hooks ,
352+ "record_build_config" ,
353+ lambda _key : pytest .fail ("unpatched editable build must not be stamped" ),
354+ )
355+
356+ with pytest .raises (RuntimeError , match = "editable patch failed" ):
357+ build_hooks .build_editable ("dist" , {"debug" : True }, "metadata" )
261358
262359
263360def _capture_cythonize_build_dir (monkeypatch , cuda_major ):
0 commit comments