Skip to content

fix(cli): remove the local target; unset WEGO_TARGET=local before upgrading - #51

Merged
sunny-wego merged 3 commits into
mainfrom
remove-local-target
Sep 15, 2026
Merged

sunny-wego merged 3 commits into
mainfrom
remove-local-target

Conversation

@sunny-wego

@sunny-wego sunny-wego commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Part of wego/foundations#127, Phase 4, step 2 (wego/foundations#136) — the local half of it.

Release note

Upgrading: if you have WEGO_TARGET=local exported, unset it before you upgrade. local is no longer a target, an unknown target is refused at startup, and so every command — wego update included — would exit 2 until you unset it. Point at a local API with WEGO_API_URL instead.

The PR title is written to carry that warning because it is the release note: this repo squash-merges, the squash subject becomes the changelog line release-please puts in the GitHub Release, and a PR with more than one commit takes that subject from the title. The fuller version lives in the README's configuration section, next to the variable it concerns.

What

--target local is gone. TARGETS is prod | staging.

The target existed so a developer could point the CLI at an apps/api on their own machine. WEGO_API_URL already does that on the default prod target, so the target was a second way to say the same thing — and the only one of the three that could throw from inside targetEndpointOverrides.

The one thing that is not a deletion

The replacement path had a gap, and this closes it rather than leaving it.

config.ts's plaintext-http exception knew three literals: localhost, 127.0.0.1, [::1]. The departing isLocalApiUrl also accepted the reserved .localhost suffix — which is exactly what portless serves the local apps/api at (api.localhost), and what a linked worktree gets a branch-prefixed name under. Without carrying that over, removing local would have broken every developer whose setup is portless.

isLoopbackHost carries it over, and no further:

URL Before After
http://localhost:3001 ok ok
http://127.0.0.1:4321 ok ok
http://api.localhost refused ok
http://rung2-api.localhost refused ok
http://localhost.evil.com refused refused
http://api.wego.com refused refused

RFC 6761 reserves the whole .localhost suffix for loopback, so nothing routable can claim it. A remote plaintext endpoint stays a configuration error — the access token travels to whatever that URL names. The message now says "loopback" rather than "localhost", which api.localhost is not.

Does this endanger wego update?

No, and the specific paths were checked rather than assumed.

  • update.ts imports exactly one symbol from anything this PR touches: assertSecureUrl. Ring following, manifest fetch, checksum verification, Sigstore identity checks and binary replacement are untouched.
  • That contact point (update.ts:390) is a widening, so it cannot turn away a URL that previously passed.
  • The brick would have been the config directory moving — install.json records the ring, and an install with no recorded ring refuses to update rather than guess. It cannot move: the old targetEndpointOverrides read apiUrlEnvValue only inside case "local", so for prod and staging the returned bundle is identical and targetConfigScope(...) output is byte-identical. installScope and legacyScopeDir are untouched.
  • The install record schema (ring-follow.ts:40) holds ring and installUrl only — no target field, so there is no persisted "local" on disk for a new binary to reject.
  • Reaching this release is safe regardless: the old binary performs the update and still knows local.

Also

  • targetEndpointOverrides loses its apiUrlEnvValue parameter along with the branch that read it.
  • Comments and help strings that spelled the axis prod|staging|local now spell it prod|staging, including the build-release.ts error a stale caller sees and two comments in release-cli.yml.
  • README and .env.local.example say to set WEGO_API_URL for a local API, and WEGO_API_URL joins the README's runtime-variable table, which had not listed it.

Behaviour change

$ wego info target --target local
--target must be one of prod|staging; got "local"

Exit 2 — the ordinary unknown-value usage error. That is the axis behaving as designed: a mistyped target has always been loud rather than a silent fall back to prod. Nothing else changes — prod still imposes nothing, staging still imposes its whole bundle, credentials are still keyed by the auth host that issued them.

Checks

  • bun test — 1473 pass, 0 fail, offline. Same count as main: two tests retired with the target, two added for the replacement path.
  • bun run lint — exit 0 (7 pre-existing warnings, none in the touched files).
  • bun run typecheck — exit 0.
  • Ran against the real source CLI: --target local exits 2; WEGO_API_URL=http://localhost:3001 wego info target resolves prod (default) with api http://localhost:3001; WEGO_API_URL=http://api.localhost wego whoami gets past the transport check, http://api.wego.com does not; WEGO_TARGET=local wego update exits 2 with the message quoted in the release note.

Not in this PR

wego/foundations#136 also retires the flavor axis. That half touches installScope and legacyScopeDir — the code that decides where an existing install's config directory and binary live — so it is a migration surface rather than a deletion, and gets its own change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QqBtLcUgxavCqnmSv5rPyd

The `local` target existed so a developer could point the CLI at an
apps/api on their own machine. `WEGO_API_URL` already does that on the
default `prod` target — the endpoint override path accepts a plaintext
`http` URL for loopback — so the target was a second way to say the same
thing, and the only one of the three that could throw from inside
`targetEndpointOverrides`.

Deletions, plus one widening that keeps the replacement whole: the
plaintext exception in `config.ts` knew only `localhost`, `127.0.0.1` and
`[::1]`, while the departing `isLocalApiUrl` also accepted the reserved
`.localhost` suffix — which is what portless serves the local apps/api at
(`api.localhost`), and what a linked worktree gets a branch-prefixed name
under. `isLoopbackHost` carries that suffix over, so every shape a
developer actually has still works over `http`, and nothing else does:
RFC 6761 reserves the suffix for loopback, so no routable host can claim
it. A remote plaintext endpoint is still refused, because the access
token travels to whatever that URL names.

`targetEndpointOverrides` loses its `apiUrlEnvValue` parameter with the
branch that read it, and its message now says "loopback" rather than
"localhost", which `api.localhost` is not.

`--target local` is now the ordinary unknown-value usage error, exit 2,
naming the list it must be one of. That is the axis behaving as designed
— a mistyped target has always been loud rather than a silent fall back
to prod.

Part of wego/foundations#127, Phase 4, step 2 (wego/foundations#136).
That issue also retires the flavor axis; this is the `local` half only.
The flavor half touches `installScope` and `legacyScopeDir`, which decide
where an existing install's config and binary live, so it is a migration
surface rather than a deletion and gets its own change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QqBtLcUgxavCqnmSv5rPyd
sunny-wego and others added 2 commits September 15, 2026 15:52
Two comments in release-cli.yml name a target this branch removes. They
are comments, so nothing runs differently; left alone they would describe
the axis wrongly from the moment this merges.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QqBtLcUgxavCqnmSv5rPyd
An exported WEGO_TARGET=local becomes an unknown target the moment this
release lands, and an unknown target is refused at startup — so every
command, `wego update` included, exits 2 until it is unset. Getting to
the release is safe (the old binary does the update and still knows the
value), and recovery is one `unset`, but nothing told the person that.

The README's configuration section is where someone looks for what the
variable takes, so the note lives beside the row rather than in a
changelog they have already scrolled past.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QqBtLcUgxavCqnmSv5rPyd
@sunny-wego sunny-wego changed the title fix(cli): remove the local target fix(cli): remove the local target; unset WEGO_TARGET=local before upgrading Sep 15, 2026
@sunny-wego
sunny-wego merged commit 8d0d0d7 into main Sep 15, 2026
1 check passed
@sunny-wego
sunny-wego deleted the remove-local-target branch September 15, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant