fix(remote): resolve remembered explicit-port endpoints
- Resolve bare remote hosts through the remote registry when one explicit port is stored. - Preserve bare host behavior when no unique explicit-port registry match exists. - Route requested remote targets through the new registry resolver. - Add registry tests for unique and ambiguous explicit-port matches. - Bump package and extension versions to 0.16.6.
This commit is contained in:
@@ -22,6 +22,32 @@ def load_remotes() -> dict[str, dict[str, str]]:
|
||||
# Normalize keys so old entries stored as "domain:443" match current lookups.
|
||||
return {_normalize_endpoint(str(endpoint)): cfg for endpoint, cfg in data.items() if isinstance(cfg, dict)}
|
||||
|
||||
def resolve_remote_endpoint(endpoint: str | None) -> str | None:
|
||||
"""Resolve a user-supplied remote alias to a remembered endpoint.
|
||||
|
||||
Domain-like remotes without an explicit port still default to :443 when no
|
||||
matching remembered remote exists. If the user remembered exactly one
|
||||
explicit-port remote for the same host (for example
|
||||
``browser-host.example:8765``), use that endpoint so ``--remote
|
||||
browser-host.example`` targets the stored service instead of assuming HTTPS.
|
||||
"""
|
||||
if not endpoint:
|
||||
return None
|
||||
normalized = _normalize_endpoint(endpoint)
|
||||
host, sep, _port = normalized.rpartition(":")
|
||||
if sep:
|
||||
return normalized
|
||||
|
||||
remotes = load_remotes()
|
||||
explicit_matches = []
|
||||
for remote_endpoint in remotes:
|
||||
remote_host, remote_sep, remote_port = remote_endpoint.rpartition(":")
|
||||
if remote_sep and remote_host == normalized and remote_port != "443":
|
||||
explicit_matches.append(remote_endpoint)
|
||||
if len(explicit_matches) == 1:
|
||||
return explicit_matches[0]
|
||||
return normalized
|
||||
|
||||
def is_valid_key_spec(value: str) -> bool:
|
||||
"""Return True for 'agent', 'agent:<selector>', or a plausible key file path."""
|
||||
return value == "agent" or value.startswith("agent:") or (
|
||||
|
||||
Reference in New Issue
Block a user