test(desktop): the source hand-off fixture installs its loopback transport once

baab4808d0 routed the stable lookup's GitHub reads through
source_check._request, so hermes_cli/source_check.py is now imported twice in
the probe (the CLI entry, then the module source_releases reads through). The
fixture's transport.py runs on every import of that file, so the second copy
wrapped the first and saw the already-rewritten 127.0.0.1 URL:
`assert parsed.hostname in ('hermes-assets.nousresearch.com', 'api.github.com')`
failed and the stable leg returned release-unavailable. main's JS & TS checks
have been red on this since 66605471e9.

transport.py now installs the redirect once (a marker on urllib.request). No
assertion changed. Locally: 1 failed on main, 1 passed with this.
This commit is contained in:
Teknium
2026-10-10 13:31:56 -07:00
parent 1c9135d5c2
commit 1f711b275f

View File

@@ -306,25 +306,32 @@ sys.path.append(${JSON.stringify(repository)})
assert not os.environ.get('HERMES_RUNTIME_DIR')
import urllib.request
from urllib.parse import urlsplit
original_build = urllib.request.build_opener
passthrough = original_build().open
def local(request, *args, **kwargs):
parsed = urlsplit(request.full_url if isinstance(request, urllib.request.Request) else request)
assert parsed.hostname in ('hermes-assets.nousresearch.com', 'api.github.com')
url = 'http://127.0.0.1:${address.port}' + parsed.path + ('?' + parsed.query if parsed.query else '')
# ChannelReader compares response.geturl() against the ORIGINAL request url:
# wrap so the redirect detector still sees the un-rewritten authority.
response = passthrough(url, *args, **kwargs)
original_url = request.full_url if isinstance(request, urllib.request.Request) else request
response.geturl = lambda: original_url
return response
urllib.request.urlopen = local
def local_build(*args, **kwargs):
# ChannelReader resolves through build_opener().open, not module urlopen.
opener = original_build(*args, **kwargs)
opener.open = local
return opener
urllib.request.build_opener = local_build
# source_check.py runs this on import, and is imported twice (the CLI entry, then the module
# source_releases reads GitHub through): install the redirect once, or the second copy wraps the
# first and sees the already-rewritten loopback URL.
def install():
original_build = urllib.request.build_opener
passthrough = original_build().open
def local(request, *args, **kwargs):
parsed = urlsplit(request.full_url if isinstance(request, urllib.request.Request) else request)
assert parsed.hostname in ('hermes-assets.nousresearch.com', 'api.github.com')
url = 'http://127.0.0.1:${address.port}' + parsed.path + ('?' + parsed.query if parsed.query else '')
# ChannelReader compares response.geturl() against the ORIGINAL request url:
# wrap so the redirect detector still sees the un-rewritten authority.
response = passthrough(url, *args, **kwargs)
original_url = request.full_url if isinstance(request, urllib.request.Request) else request
response.geturl = lambda: original_url
return response
urllib.request.urlopen = local
def local_build(*args, **kwargs):
# ChannelReader resolves through build_opener().open, not module urlopen.
opener = original_build(*args, **kwargs)
opener.open = local
return opener
urllib.request.build_opener = local_build
if not getattr(urllib.request, '_hermes_loopback', False):
urllib.request._hermes_loopback = True
install()
`
)
vi.stubEnv('HERMES_MANAGED', '')