[codex] fix: preserve localhost preview hosts#3499
Conversation
Co-authored-by: Codex <codex@openai.com>
…-host-preservation [codex] fix: preserve localhost preview hosts
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved Straightforward bug fix that preserves localhost preview URLs when the environment is also running on localhost. The change is small, self-contained, includes a test, and has clear intent with limited scope. You can customize Macroscope's approvability policy. Learn more. |
Summary
localhostdiscovered preview URLs when the prepared connection itself is local loopback.0.0.0.0flowing through the existing environment-port normalization path.Root cause
resolveDiscoveredServerUrl(...)treated every loopback discovered URL as an environment-port target. When the prepared connection base washttp://127.0.0.1:<port>, that remappedlocalhost:<port>onto127.0.0.1:<port>, even though the normalized user-visible URL should stay onlocalhost.Impact
Users opening a discovered
localhostdev server from a local prepared environment keep thelocalhosthost, which preserves host-specific API allowlists. Wildcard local hosts such as0.0.0.0still normalize to a concrete reachable host, and private remote environments still remap discovered loopback ports onto the private environment host.Validation
PATH="$HOME/.vite-plus/bin:$PATH" vp test apps/web/src/browser/browserTargetResolver.test.tspassed: 1 file passed, 7 tests passed.PATH="$HOME/.vite-plus/bin:$PATH" vp checkpassed: 0 errors; 20 existing unrelated warnings.PATH="$HOME/.vite-plus/bin:$PATH" vp run typecheckpassed: completed successfully.Closes #3124
Note
Low Risk
Small, targeted change to preview URL resolution in the web app with clear tests and no auth or data-path impact.
Overview
resolveDiscoveredServerUrlno longer remaps discoveredlocalhostURLs onto127.0.0.1when the prepared environment connection is itself a local loopback host (localhost,127.0.0.1, or::1). In that case it returns the normalized URL unchanged so host-specific API allowlists stay onlocalhost.Discovered
0.0.0.0URLs still go through environment-port normalization, and loopback discoveries against private remote prepared bases still remap ports onto the environment host as before. A newisLocalLoopbackHosthelper drives the early-return branch, with a unit test covering127.0.0.1prepared base +localhostpicker input including path, query, and hash.Reviewed by Cursor Bugbot for commit e581f07. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Preserve localhost preview hosts in
resolveDiscoveredServerUrlPreviously,
resolveDiscoveredServerUrlwould rewrite loopback URLs through environment-port resolution even when both the discovered host and the prepared connection base host were local loopbacks. This adds a newisLocalLoopbackHosthelper and an early-return path inresolveDiscoveredServerUrlthat returns the normalized URL unchanged when both sides are loopback (localhost/127.0.0.1/::1) and the discovered host is not0.0.0.0. If no prepared connection exists, the function now returns the raw input instead of attempting port mapping.Macroscope summarized e581f07.