@@ -58,6 +58,15 @@ def fake_is_executable_candidate(path):
5858 return checked
5959
6060
61+ def _patch_winreg (mocker ):
62+ winreg = mocker .MagicMock ()
63+ winreg .HKEY_LOCAL_MACHINE = object ()
64+ winreg .KEY_READ = 0x20019
65+ winreg .KEY_WOW64_64KEY = 0x0100
66+ mocker .patch .object (binary_finder_module .importlib , "import_module" , return_value = winreg )
67+ return winreg
68+
69+
6170@pytest .mark .usefixtures ("clear_find_binary_cache" )
6271def test_find_binary_search_path_includes_site_packages_conda_cuda (monkeypatch , mocker ):
6372 conda_prefix = os .path .join (os .sep , "conda" )
@@ -425,13 +434,9 @@ def test_windows_installed_nsight_root_reads_64_bit_registry(mocker):
425434 product_context .__enter__ .return_value = product_key
426435 version_context = mocker .MagicMock ()
427436 version_context .__enter__ .return_value = version_key
428- winreg = mocker .MagicMock ()
429- winreg .HKEY_LOCAL_MACHINE = object ()
430- winreg .KEY_READ = 0x20019
431- winreg .KEY_WOW64_64KEY = 0x0100
437+ winreg = _patch_winreg (mocker )
432438 winreg .OpenKey .side_effect = (product_context , version_context )
433439 winreg .QueryValueEx .side_effect = (("2026.1.3" , 1 ), (install_root , 1 ))
434- mocker .patch .object (binary_finder_module .importlib , "import_module" , return_value = winreg )
435440
436441 assert binary_finder_module ._windows_installed_nsight_root ("Systems" ) == install_root
437442 access = winreg .KEY_READ | winreg .KEY_WOW64_64KEY
@@ -448,6 +453,99 @@ def test_windows_installed_nsight_root_reads_64_bit_registry(mocker):
448453 )
449454
450455
456+ @pytest .mark .agent_authored (model = "gpt-5.6" )
457+ def test_windows_installed_nsight_root_returns_none_when_product_key_is_absent (mocker ):
458+ winreg = _patch_winreg (mocker )
459+ winreg .OpenKey .side_effect = FileNotFoundError ("Nsight Systems is not installed" )
460+
461+ assert binary_finder_module ._windows_installed_nsight_root ("Systems" ) is None
462+
463+
464+ @pytest .mark .agent_authored (model = "gpt-5.6" )
465+ def test_windows_installed_nsight_root_rejects_missing_current_version (mocker ):
466+ product_context = mocker .MagicMock ()
467+ product_context .__enter__ .return_value = mocker .MagicMock ()
468+ winreg = _patch_winreg (mocker )
469+ winreg .OpenKey .return_value = product_context
470+ winreg .QueryValueEx .side_effect = FileNotFoundError ("CurrentVersion is missing" )
471+
472+ with pytest .raises (RuntimeError , match = r"Incomplete Nsight 'Systems' registry registration" ) as exc_info :
473+ binary_finder_module ._windows_installed_nsight_root ("Systems" )
474+
475+ assert isinstance (exc_info .value .__cause__ , FileNotFoundError )
476+
477+
478+ @pytest .mark .parametrize ("current_version" , (None , "" , " " , 2026 ))
479+ @pytest .mark .agent_authored (model = "gpt-5.6" )
480+ def test_windows_installed_nsight_root_rejects_invalid_current_version (mocker , current_version ):
481+ product_context = mocker .MagicMock ()
482+ product_context .__enter__ .return_value = mocker .MagicMock ()
483+ winreg = _patch_winreg (mocker )
484+ winreg .OpenKey .return_value = product_context
485+ winreg .QueryValueEx .return_value = (current_version , 1 )
486+
487+ with pytest .raises (RuntimeError , match = r"Invalid CurrentVersion value .*Nsight 'Systems' registry registration" ):
488+ binary_finder_module ._windows_installed_nsight_root ("Systems" )
489+
490+
491+ @pytest .mark .agent_authored (model = "gpt-5.6" )
492+ def test_windows_installed_nsight_root_rejects_missing_version_key (mocker ):
493+ product_key = mocker .MagicMock ()
494+ product_context = mocker .MagicMock ()
495+ product_context .__enter__ .return_value = product_key
496+ winreg = _patch_winreg (mocker )
497+ winreg .OpenKey .side_effect = (product_context , FileNotFoundError ("Version key is missing" ))
498+ winreg .QueryValueEx .return_value = ("2026.1.3" , 1 )
499+
500+ with pytest .raises (RuntimeError , match = r"Incomplete Nsight 'Systems' registry registration" ) as exc_info :
501+ binary_finder_module ._windows_installed_nsight_root ("Systems" )
502+
503+ assert isinstance (exc_info .value .__cause__ , FileNotFoundError )
504+
505+
506+ @pytest .mark .agent_authored (model = "gpt-5.6" )
507+ def test_windows_installed_nsight_root_rejects_missing_installation_directory (mocker ):
508+ product_context = mocker .MagicMock ()
509+ product_context .__enter__ .return_value = mocker .MagicMock ()
510+ version_context = mocker .MagicMock ()
511+ version_context .__enter__ .return_value = mocker .MagicMock ()
512+ winreg = _patch_winreg (mocker )
513+ winreg .OpenKey .side_effect = (product_context , version_context )
514+ winreg .QueryValueEx .side_effect = (("2026.1.3" , 1 ), FileNotFoundError ("Installation directory is missing" ))
515+
516+ with pytest .raises (RuntimeError , match = r"Incomplete Nsight 'Systems' registry registration" ) as exc_info :
517+ binary_finder_module ._windows_installed_nsight_root ("Systems" )
518+
519+ assert isinstance (exc_info .value .__cause__ , FileNotFoundError )
520+
521+
522+ @pytest .mark .parametrize ("install_root" , (None , "" , " " , 2026 ))
523+ @pytest .mark .agent_authored (model = "gpt-5.6" )
524+ def test_windows_installed_nsight_root_rejects_invalid_installation_directory (mocker , install_root ):
525+ product_context = mocker .MagicMock ()
526+ product_context .__enter__ .return_value = mocker .MagicMock ()
527+ version_context = mocker .MagicMock ()
528+ version_context .__enter__ .return_value = mocker .MagicMock ()
529+ winreg = _patch_winreg (mocker )
530+ winreg .OpenKey .side_effect = (product_context , version_context )
531+ winreg .QueryValueEx .side_effect = (("2026.1.3" , 1 ), (install_root , 1 ))
532+
533+ with pytest .raises (
534+ RuntimeError ,
535+ match = r"Invalid installation directory .*Nsight 'Systems' registry registration.*version '2026.1.3'" ,
536+ ):
537+ binary_finder_module ._windows_installed_nsight_root ("Systems" )
538+
539+
540+ @pytest .mark .agent_authored (model = "gpt-5.6" )
541+ def test_windows_installed_nsight_root_propagates_access_errors (mocker ):
542+ winreg = _patch_winreg (mocker )
543+ winreg .OpenKey .side_effect = PermissionError ("Registry access denied" )
544+
545+ with pytest .raises (PermissionError , match = "Registry access denied" ):
546+ binary_finder_module ._windows_installed_nsight_root ("Systems" )
547+
548+
451549@pytest .mark .usefixtures ("clear_find_binary_cache" )
452550def test_find_binary_first_matching_dir_wins (monkeypatch , mocker ):
453551 conda_prefix = os .path .join (os .sep , "conda" )
0 commit comments