git proxy: print socat/Parallels listen status on run and status.
Make guest-forward health obvious so Windows VM timeouts are diagnosable without guessing.
This commit is contained in:
@@ -108,10 +108,53 @@ def _port_listening_on(host: str, port: int) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _report_proxy_listen(port: int, ips: list[str] | None = None) -> None:
|
||||
"""Print loopback + Parallels listen state and guest proxy URLs."""
|
||||
loop_ok = _port_listening_on("127.0.0.1", port)
|
||||
click.secho("\nProxy listen check:", fg="cyan")
|
||||
click.echo(
|
||||
f" 127.0.0.1:{port} {'OK' if loop_ok else 'DOWN'} (Mac / git http.proxy)"
|
||||
)
|
||||
if ips is None:
|
||||
ips = _parallels_host_ips()
|
||||
if not ips:
|
||||
click.secho(
|
||||
" (no Parallels Shared/Host-Only IPs auto-detected — "
|
||||
"guest VMs cannot use this proxy via host IP; "
|
||||
"override with XIAOHE_CI_PARALLELS_HOST_IP)",
|
||||
fg="yellow",
|
||||
)
|
||||
return
|
||||
click.echo(" Parallels guest → Mac (socat):")
|
||||
for ip in ips:
|
||||
ok = _port_listening_on(ip, port)
|
||||
mark = "OK" if ok else "DOWN"
|
||||
click.echo(f" {ip}:{port} {mark} → guest use http://{ip}:{port}")
|
||||
down = [ip for ip in ips if not _port_listening_on(ip, port)]
|
||||
if down:
|
||||
click.secho(
|
||||
" WARN: some Parallels forwards are DOWN — Windows/Linux VMs "
|
||||
"will time out reaching GitHub via the host proxy.",
|
||||
fg="yellow",
|
||||
err=True,
|
||||
)
|
||||
else:
|
||||
click.secho(
|
||||
" Guest tip: curl -I -x http://<ip>:%d https://api.github.com" % port,
|
||||
fg="cyan",
|
||||
)
|
||||
|
||||
|
||||
def _start_parallels_forwards(port: int) -> list[subprocess.Popen]:
|
||||
"""Forward Parallels host IPs:port → 127.0.0.1:port via socat (Mac only)."""
|
||||
ips = _parallels_host_ips()
|
||||
if not ips:
|
||||
click.secho(
|
||||
"WARN: no Parallels host IPs detected (ifconfig). "
|
||||
"Set XIAOHE_CI_PARALLELS_HOST_IP if a VM needs the proxy.",
|
||||
fg="yellow",
|
||||
err=True,
|
||||
)
|
||||
return []
|
||||
socat = shutil.which("socat")
|
||||
if not socat:
|
||||
@@ -122,10 +165,12 @@ def _start_parallels_forwards(port: int) -> list[subprocess.Popen]:
|
||||
err=True,
|
||||
)
|
||||
return []
|
||||
click.echo(f"socat: {socat}")
|
||||
click.echo(f"Parallels host IPs (auto): {', '.join(ips)}")
|
||||
procs: list[subprocess.Popen] = []
|
||||
for ip in ips:
|
||||
if _port_listening_on(ip, port):
|
||||
click.echo(f"Parallels forward already up: {ip}:{port}")
|
||||
click.secho(f"Parallels forward already up: {ip}:{port}", fg="green")
|
||||
continue
|
||||
proc = subprocess.Popen(
|
||||
[
|
||||
@@ -226,6 +271,14 @@ def proxy_status() -> None:
|
||||
click.echo(f" http.proxy: {http_proxy}")
|
||||
click.echo(f" https.proxy: {https_proxy}")
|
||||
|
||||
port = (
|
||||
_proxy_loopback_port(http_proxy)
|
||||
if http_proxy != "(not set)"
|
||||
else None
|
||||
)
|
||||
if port is not None:
|
||||
_report_proxy_listen(port)
|
||||
else:
|
||||
ips = _parallels_host_ips()
|
||||
if ips:
|
||||
click.secho("\nParallels host IPs (auto):", fg="cyan")
|
||||
@@ -347,6 +400,7 @@ def proxy_run(name: str, command: tuple[str, ...]) -> None:
|
||||
sys.exit(1)
|
||||
|
||||
forward_procs = _start_parallels_forwards(port)
|
||||
_report_proxy_listen(port)
|
||||
click.secho(
|
||||
"Press Ctrl-C to stop and auto-unset proxy\n", fg="cyan"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user