fix(#812 follow-up): normalize detect-platform.sh host-match port comparison by scheme
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful

gitea_url_matches_host compared every remote authority's port directly
against the configured HTTP(S) API URL's port, which conflated two
unrelated things and normalized default web ports asymmetrically:

- An SSH remote's transport port (e.g. ssh://git@host:2222/...) was
  compared against the configured HTTP(S) port, even though the SSH
  daemon port has nothing to do with the Gitea HTTP(S) API port.
- An explicit default port on the remote (https://host:443/...) failed
  to match an implicit (portless) configured URL, while the inverse
  (implicit remote vs. explicit configured) already matched -- the
  default-port equivalence was only applied on one side.

Fix get_remote_host() to strip an SSH transport port before it ever
reaches host-match, and make gitea_url_matches_host's default-port
normalization symmetric (":443" https / ":80" http is equivalent to
the implicit form on BOTH sides).

Adds red-first regressions for both repros to
test-pr-review-gitea-comment.sh (extending the #812 harness) and wires
that harness into packages/mosaic's test:framework-shell chain so it
runs under `pnpm test`.

Closes #850
This commit is contained in:
Hermes Agent
2026-07-20 04:42:51 -05:00
parent acd7d380f6
commit 9c26278c67
3 changed files with 38 additions and 11 deletions

View File

@@ -91,13 +91,19 @@ remote = urlparse(f"//{remote_host}")
if configured.scheme not in {"http", "https"} or configured.hostname != remote.hostname:
raise SystemExit(1)
configured_port = configured.port
remote_port = remote.port
if remote_port is None:
default_port = 80 if configured.scheme == "http" else 443
if configured_port not in {None, default_port}:
raise SystemExit(1)
elif configured_port != remote_port:
# Normalize by scheme: an implicit (portless) HTTP(S) URL and its explicit
# default-port form (":80" for http, ":443" for https) name the same
# provider endpoint. Apply that equivalence symmetrically -- whichever side
# omits the port is treated as carrying the scheme's default port -- so
# "configured implicit vs. remote explicit" and "configured explicit vs.
# remote implicit" both match. (The remote side here is always an HTTP(S)
# authority; an SSH remote's transport port is stripped by get_remote_host
# before reaching this comparison, since it identifies an unrelated
# service on the same host, not the HTTP(S) provider port.)
default_port = 80 if configured.scheme == "http" else 443
normalized_configured = configured.port if configured.port is not None else default_port
normalized_remote = remote.port if remote.port is not None else default_port
if normalized_configured != normalized_remote:
raise SystemExit(1)
raise SystemExit(0)
PY
@@ -432,7 +438,11 @@ get_remote_host() {
fi
if [[ "$remote_url" =~ ^ssh://([^/]+)/ ]]; then
local host="${BASH_REMATCH[1]}"
echo "${host##*@}"
host="${host##*@}"
# Strip an SSH transport port (e.g. "git.example:2222"): it names the
# SSH daemon port, not the HTTP(S) provider API port, and must not
# feed gitea_url_matches_host's port comparison (#850).
echo "${host%%:*}"
return 0
fi
if [[ "$remote_url" =~ ^git@([^:]+): ]]; then