Skip to content

fix(cli): keep a path prefix in the login URLs - #6793

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/cli-login-path-prefix
Aug 17, 2026
Merged

fix(cli): keep a path prefix in the login URLs#6793
waleedlatif1 merged 2 commits into
stagingfrom
fix/cli-login-path-prefix

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • sim login built both of its URLs with new URL('/path', endpoint). A leading-slash path is absolute, so it resolves against the endpoint's origin and drops any path the endpoint carries. A self-hosted deployment served at https://host/sim — a proxy fronting several apps — sent the browser to https://host/cli/auth and polled https://host/api/cli/auth/poll, neither of which exists there.
  • Every other command builds its URL by concatenation and was unaffected, so the endpoint looked correct and login alone failed, which is a confusing way to fail.
  • Both URLs now go through the HTTP client's buildUrl, exported for this rather than duplicated. One URL builder for the whole CLI is the point — two of them is how the halves drifted apart in the first place. Its TSDoc now names the trap so the next caller does not reintroduce it.

Pre-existing; found while fixing the adjacent redirect handling in #6788/#6791. Deployments at a domain root, including sim.ai, were never affected.

Type of Change

  • Bug fix

Testing

Tested manually. sim login --no-browser against a normal endpoint prints the same approval URL as before. Added a test asserting both the approval URL and the poll URL keep a /sim prefix, proven red against the previous implementation (expected 'https://host.test/cli/auth?…' to match /^https:\/\/host\.test\/sim\/cli\/auth…/). Also covered that an absent workspace is omitted rather than sent blank, which the rewrite had to preserve.

Suite is 345 passed / 1 skipped. lint, type-check, build, and all 29 audits in check:audits pass.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

`sim login` built both of its URLs with `new URL('/path', endpoint)`. A
leading-slash path is absolute, so it resolves against the endpoint's origin
and drops any path the endpoint carries: a deployment served at
`https://host/sim` sent the browser to `https://host/cli/auth` and polled
`https://host/api/cli/auth/poll`, neither of which exists there.

Every other command builds its URL by concatenation and was unaffected, so
the endpoint looked correct and login alone failed.

Both now go through the client's `buildUrl`, which is exported for it rather
than duplicated — one URL builder for the whole CLI is the point, since two
of them is how the halves drifted apart. Its TSDoc now names the trap.
@vercel

vercel Bot commented Aug 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 17, 2026 11:51pm

Request Review

@cursor

cursor Bot commented Aug 17, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Localized CLI URL construction fix with tests; no auth logic or server changes; root-hosted endpoints unchanged.

Overview
sim login was the only CLI path that built URLs with new URL('/path', endpoint). That treats a leading-slash path as absolute against the endpoint origin, so an endpoint like https://host/sim produced https://host/cli/auth and https://host/api/cli/auth/poll instead of keeping the /sim prefix. Other commands already concatenated endpoint + path and worked, which made login alone fail on prefixed deployments.

Approval and poll URLs now go through the shared buildUrl helper (exported from the HTTP client with TSDoc describing the trap). Optional query values—including workspace—are skipped when absent so they are not sent as blank strings.

Tests assert prefixed approval and poll URLs and workspace omission.

Reviewed by Cursor Bugbot for commit 3885a15. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR routes both device-login URLs through the shared URL builder so self-hosted endpoint path prefixes are preserved.

  • Exports and documents the CLI HTTP client’s shared buildUrl helper.
  • Uses that helper for the browser approval URL and authentication polling endpoint.
  • Adds coverage for prefixed endpoints and omitted workspace parameters.
  • Replaces the previously leaking global fetch stub with a spy restored by existing teardown.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/sim-cli/src/auth/device-flow.test.ts Adds prefixed-endpoint and optional-workspace coverage; the fetch spy is correctly restored by the existing teardown.
packages/sim-cli/src/auth/device-flow.ts Builds approval and polling URLs through the shared prefix-preserving URL helper.
packages/sim-cli/src/http/client.ts Exports and documents the existing shared URL builder for reuse by device login.

Reviews (2): Last reviewed commit: "test(cli): restore fetch with spyOn so t..." | Re-trigger Greptile

Comment thread packages/sim-cli/src/auth/device-flow.test.ts Outdated
Comment thread packages/sim-cli/src/auth/device-flow.test.ts Outdated
vi.stubGlobal is not undone by restoreAllMocks, so the completed-auth
response would have leaked into whatever ran next. The rest of this file
already spies on globalThis.fetch, which the existing teardown restores.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3885a15. Configure here.

@waleedlatif1
waleedlatif1 merged commit fe4480d into staging Aug 17, 2026
24 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/cli-login-path-prefix branch August 17, 2026 23:55
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