@@ -343,3 +343,57 @@ def test_configure_nexus_loads_correctly(tmp_path):
343343 # Switch back to nexus
344344 new_manager .switch_profile ("nexus" )
345345 assert str (new_manager .web .api_endpoint ) == "http://my-nexus.example.com/tidy3d-api"
346+
347+
348+ def test_nexus_url_derivation ():
349+ """Test that nexus URL derivation handles edge cases correctly."""
350+ from urllib .parse import urlparse , urlunparse
351+
352+ test_cases = [
353+ # (input_url, expected_api, expected_website, expected_s3)
354+ (
355+ "http://localhost" ,
356+ "http://localhost/tidy3d-api" ,
357+ "http://localhost/tidy3d" ,
358+ "http://localhost:9000" ,
359+ ),
360+ (
361+ "http://localhost/" ,
362+ "http://localhost/tidy3d-api" ,
363+ "http://localhost/tidy3d" ,
364+ "http://localhost:9000" ,
365+ ),
366+ (
367+ "http://localhost:8080" ,
368+ "http://localhost:8080/tidy3d-api" ,
369+ "http://localhost:8080/tidy3d" ,
370+ "http://localhost:9000" ,
371+ ),
372+ (
373+ "http://nexus.company.com" ,
374+ "http://nexus.company.com/tidy3d-api" ,
375+ "http://nexus.company.com/tidy3d" ,
376+ "http://nexus.company.com:9000" ,
377+ ),
378+ (
379+ "https://nexus.company.com/" ,
380+ "https://nexus.company.com/tidy3d-api" ,
381+ "https://nexus.company.com/tidy3d" ,
382+ "https://nexus.company.com:9000" ,
383+ ),
384+ ]
385+
386+ for nexus_url , expected_api , expected_website , expected_s3 in test_cases :
387+ # Replicate the logic from configure_fn
388+ base_url = nexus_url .rstrip ("/" )
389+ api_endpoint = f"{ base_url } /tidy3d-api"
390+ website_endpoint = f"{ base_url } /tidy3d"
391+
392+ parsed = urlparse (nexus_url )
393+ hostname = parsed .hostname or parsed .netloc .split (":" )[0 ]
394+ s3_netloc = f"{ hostname } :9000"
395+ s3_endpoint = urlunparse ((parsed .scheme , s3_netloc , "" , "" , "" , "" ))
396+
397+ assert api_endpoint == expected_api , f"Failed for { nexus_url } : api_endpoint"
398+ assert website_endpoint == expected_website , f"Failed for { nexus_url } : website_endpoint"
399+ assert s3_endpoint == expected_s3 , f"Failed for { nexus_url } : s3_endpoint"
0 commit comments