@@ -85,8 +85,7 @@ def test_locate_bitcode_lib(info_summary_append, libname):
8585 _located_bitcode_lib_asserts (located_lib )
8686 assert Path (lib_path ).is_file ()
8787 assert lib_path == located_lib .abs_path
88- expected_filename = located_lib .filename
89- assert Path (lib_path ).name == expected_filename
88+ assert located_lib .filename == _bitcode_lib_filename (libname )
9089
9190
9291@pytest .mark .usefixtures ("clear_find_bitcode_lib_cache" )
@@ -135,6 +134,90 @@ def find_expected_sub_dir(sub_dir):
135134 assert located_lib .found_via == "CUDA_PATH"
136135
137136
137+ @pytest .mark .usefixtures ("clear_find_bitcode_lib_cache" )
138+ @pytest .mark .parametrize ("source" , ("site-packages" , "conda" , "CUDA_PATH" ))
139+ @pytest .mark .agent_authored (model = "gpt-6" )
140+ def test_locate_bitcode_lib_returns_resolved_path_for_relative_root (monkeypatch , tmp_path , source ):
141+ monkeypatch .chdir (tmp_path )
142+ monkeypatch .delenv ("CONDA_PREFIX" , raising = False )
143+ monkeypatch .delenv ("CUDA_HOME" , raising = False )
144+ monkeypatch .delenv ("CUDA_PATH" , raising = False )
145+
146+ info = _bitcode_lib_info ("device" )
147+ root = Path ("relative-root" )
148+ if source == "site-packages" :
149+ lib_dir = root / Path (info ["site_packages_dirs" ][0 ])
150+ monkeypatch .setattr (find_bitcode_lib_module , "find_sub_dirs_all_sitepackages" , lambda _sub_dir : [str (lib_dir )])
151+ else :
152+ monkeypatch .setattr (find_bitcode_lib_module , "find_sub_dirs_all_sitepackages" , lambda _sub_dir : [])
153+ if source == "conda" :
154+ monkeypatch .setenv ("CONDA_PREFIX" , str (root ))
155+ lib_dir = _conda_anchor (root ) / Path (info ["rel_path" ])
156+ else :
157+ monkeypatch .setenv ("CUDA_HOME" , str (root ))
158+ lib_dir = root / Path (info ["rel_path" ])
159+
160+ expected = (tmp_path / lib_dir / info ["filename" ]).resolve ()
161+ expected .parent .mkdir (parents = True )
162+ expected .touch ()
163+ located = locate_bitcode_lib ("device" )
164+ assert located .found_via == source
165+ assert located .abs_path == str (expected )
166+ assert find_bitcode_lib ("device" ) == str (expected )
167+
168+ monkeypatch .chdir (tmp_path .parent )
169+ assert Path (located .abs_path ).is_file ()
170+ assert Path (find_bitcode_lib ("device" )).is_file ()
171+
172+
173+ @pytest .mark .skipif (os .name == "nt" , reason = "POSIX symlink parent traversal" )
174+ @pytest .mark .usefixtures ("clear_find_bitcode_lib_cache" )
175+ @pytest .mark .agent_authored (model = "gpt-6" )
176+ def test_locate_bitcode_lib_preserves_symlink_parent (monkeypatch , tmp_path ):
177+ monkeypatch .chdir (tmp_path )
178+ monkeypatch .delenv ("CONDA_PREFIX" , raising = False )
179+ monkeypatch .delenv ("CUDA_PATH" , raising = False )
180+ monkeypatch .setenv ("CUDA_HOME" , "alias/.." )
181+ monkeypatch .setattr (find_bitcode_lib_module , "find_sub_dirs_all_sitepackages" , lambda _sub_dir : [])
182+
183+ real_root = tmp_path / "real"
184+ (real_root / "child" ).mkdir (parents = True )
185+ (tmp_path / "alias" ).symlink_to (real_root / "child" , target_is_directory = True )
186+ info = _bitcode_lib_info ("device" )
187+ expected = real_root / info ["rel_path" ] / info ["filename" ]
188+ expected .parent .mkdir (parents = True )
189+ expected .touch ()
190+
191+ located = locate_bitcode_lib ("device" )
192+ assert located .abs_path == str (expected .resolve ())
193+ cached = find_bitcode_lib ("device" )
194+ monkeypatch .chdir (tmp_path .parent )
195+ assert cached == str (expected .resolve ())
196+ assert find_bitcode_lib ("device" ) == cached
197+
198+
199+ @pytest .mark .skipif (os .name == "nt" , reason = "Symlink creation requires privileges on Windows" )
200+ @pytest .mark .usefixtures ("clear_find_bitcode_lib_cache" )
201+ @pytest .mark .agent_authored (model = "gpt-6" )
202+ def test_locate_bitcode_lib_resolves_symlinked_file (monkeypatch , tmp_path ):
203+ monkeypatch .delenv ("CONDA_PREFIX" , raising = False )
204+ monkeypatch .delenv ("CUDA_PATH" , raising = False )
205+ monkeypatch .setattr (find_bitcode_lib_module , "find_sub_dirs_all_sitepackages" , lambda _sub_dir : [])
206+ root = tmp_path / "toolkit"
207+ monkeypatch .setenv ("CUDA_HOME" , str (root ))
208+ info = _bitcode_lib_info ("device" )
209+ target = tmp_path / "actual-library"
210+ target .touch ()
211+ candidate = root / info ["rel_path" ] / info ["filename" ]
212+ candidate .parent .mkdir (parents = True )
213+ candidate .symlink_to (target )
214+
215+ located = locate_bitcode_lib ("device" )
216+ assert located .abs_path == str (target .resolve ())
217+ assert located .filename == info ["filename" ]
218+ assert find_bitcode_lib ("device" ) == located .abs_path
219+
220+
138221@pytest .mark .usefixtures ("clear_find_bitcode_lib_cache" )
139222def test_find_bitcode_lib_not_found_error_includes_cuda_home_directory_listing (monkeypatch , tmp_path ):
140223 cuda_home = tmp_path / "cuda-home"
0 commit comments