@@ -148,6 +148,63 @@ def test_not_found_appends_error(self, mocker, tmp_path):
148148 assert result is None
149149 assert any ("No such file" in m for m in ctx .error_messages )
150150
151+ # The next three tests cover the Linux glob fallback in
152+ # cuda.pathfinder._dynamic_libs.search_platform._find_so_in_rel_dirs.
153+ # The fallback triggers when the unversioned libfoo.so is absent but
154+ # versioned libfoo.so.<major> files exist (e.g. some conda layouts).
155+ # Issue #1732 tracks the decision to return the newest-sorting match
156+ # deterministically; these tests lock in that policy at the
157+ # site-packages call site.
158+
159+ def test_glob_fallback_returns_single_versioned_match (self , mocker , tmp_path ):
160+ lib_dir = tmp_path / "nvidia" / "cuda_runtime" / "lib"
161+ lib_dir .mkdir (parents = True )
162+ versioned = lib_dir / "libcudart.so.13"
163+ versioned .touch ()
164+
165+ mocker .patch (
166+ f"{ _PLAT_MOD } .find_sub_dirs_all_sitepackages" ,
167+ return_value = [str (lib_dir )],
168+ )
169+
170+ result = find_in_site_packages (_ctx (platform = LinuxSearchPlatform ()))
171+ assert result is not None
172+ assert result .abs_path == str (versioned )
173+ assert result .found_via == "site-packages"
174+
175+ def test_glob_fallback_returns_newest_of_multiple_matches (self , mocker , tmp_path ):
176+ lib_dir = tmp_path / "nvidia" / "cuda_runtime" / "lib"
177+ lib_dir .mkdir (parents = True )
178+ older = lib_dir / "libcudart.so.12"
179+ newer = lib_dir / "libcudart.so.13"
180+ older .touch ()
181+ newer .touch ()
182+
183+ mocker .patch (
184+ f"{ _PLAT_MOD } .find_sub_dirs_all_sitepackages" ,
185+ return_value = [str (lib_dir )],
186+ )
187+
188+ result = find_in_site_packages (_ctx (platform = LinuxSearchPlatform ()))
189+ assert result is not None
190+ assert result .abs_path == str (newer )
191+ assert result .found_via == "site-packages"
192+
193+ def test_glob_fallback_zero_matches_returns_none (self , mocker , tmp_path ):
194+ lib_dir = tmp_path / "nvidia" / "cuda_runtime" / "lib"
195+ lib_dir .mkdir (parents = True )
196+ (lib_dir / "unrelated.txt" ).touch ()
197+
198+ mocker .patch (
199+ f"{ _PLAT_MOD } .find_sub_dirs_all_sitepackages" ,
200+ return_value = [str (lib_dir )],
201+ )
202+
203+ ctx = _ctx (platform = LinuxSearchPlatform ())
204+ result = find_in_site_packages (ctx )
205+ assert result is None
206+ assert any ("No such file" in m and "libcudart.so" in m for m in ctx .error_messages )
207+
151208
152209# ---------------------------------------------------------------------------
153210# find_in_conda
@@ -189,6 +246,54 @@ def test_found_windows(self, mocker, tmp_path):
189246 assert result .abs_path == str (dll )
190247 assert result .found_via == "conda"
191248
249+ # The next three tests cover the Linux glob fallback in
250+ # cuda.pathfinder._dynamic_libs.search_platform.LinuxSearchPlatform.find_in_lib_dir,
251+ # which is exercised by find_in_conda (and find_in_cuda_path) when the
252+ # resolved lib dir contains only versioned libfoo.so.<major> files.
253+ # Issue #1732 tracks the decision to return the newest-sorting match
254+ # deterministically; these tests lock in that policy at the conda /
255+ # CUDA_PATH call site.
256+
257+ def test_glob_fallback_returns_single_versioned_match (self , mocker , tmp_path ):
258+ lib_dir = tmp_path / "lib"
259+ lib_dir .mkdir ()
260+ versioned = lib_dir / "libcudart.so.13"
261+ versioned .touch ()
262+
263+ mocker .patch .dict (os .environ , {"CONDA_PREFIX" : str (tmp_path )})
264+
265+ result = find_in_conda (_ctx (platform = LinuxSearchPlatform ()))
266+ assert result is not None
267+ assert result .abs_path == str (versioned )
268+ assert result .found_via == "conda"
269+
270+ def test_glob_fallback_returns_newest_of_multiple_matches (self , mocker , tmp_path ):
271+ lib_dir = tmp_path / "lib"
272+ lib_dir .mkdir ()
273+ older = lib_dir / "libcudart.so.12"
274+ newer = lib_dir / "libcudart.so.13"
275+ older .touch ()
276+ newer .touch ()
277+
278+ mocker .patch .dict (os .environ , {"CONDA_PREFIX" : str (tmp_path )})
279+
280+ result = find_in_conda (_ctx (platform = LinuxSearchPlatform ()))
281+ assert result is not None
282+ assert result .abs_path == str (newer )
283+ assert result .found_via == "conda"
284+
285+ def test_glob_fallback_zero_matches_returns_none (self , mocker , tmp_path ):
286+ lib_dir = tmp_path / "lib"
287+ lib_dir .mkdir ()
288+ (lib_dir / "unrelated.txt" ).touch ()
289+
290+ mocker .patch .dict (os .environ , {"CONDA_PREFIX" : str (tmp_path )})
291+
292+ ctx = _ctx (platform = LinuxSearchPlatform ())
293+ result = find_in_conda (ctx )
294+ assert result is None
295+ assert any ("No such file" in m and "libcudart.so" in m for m in ctx .error_messages )
296+
192297
193298# ---------------------------------------------------------------------------
194299# find_in_cuda_path
0 commit comments