Skip to content

Commit 928e482

Browse files
a
1 parent 3cb73c1 commit 928e482

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

tests/config/test_nexus_migration.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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"

tidy3d/web/cli/app.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import shutil
99
import ssl
1010
from typing import Any
11+
from urllib.parse import urlparse, urlunparse
1112

1213
import click
1314
import requests
@@ -165,9 +166,17 @@ def configure_fn(
165166

166167
# If nexus_url is provided, derive endpoints from it automatically
167168
if nexus_url:
168-
api_endpoint = f"{nexus_url}/tidy3d-api"
169-
website_endpoint = f"{nexus_url}/tidy3d"
170-
s3_endpoint = f"{nexus_url}:9000"
169+
# Strip trailing slashes for clean URLs
170+
base_url = nexus_url.rstrip("/")
171+
api_endpoint = f"{base_url}/tidy3d-api"
172+
website_endpoint = f"{base_url}/tidy3d"
173+
174+
# For S3 endpoint, replace any existing port with 9000
175+
parsed = urlparse(nexus_url)
176+
# Reconstruct netloc with port 9000 (remove any existing port)
177+
hostname = parsed.hostname or parsed.netloc.split(":")[0]
178+
s3_netloc = f"{hostname}:9000"
179+
s3_endpoint = urlunparse((parsed.scheme, s3_netloc, "", "", "", ""))
171180

172181
# Check if any Nexus options are provided
173182
has_nexus_config = any(

0 commit comments

Comments
 (0)