test: stop login tests from opening real browser tabs#375
Open
gtsiolis wants to merge 2 commits into
Open
Conversation
The device-flow login opens the auth URL in a real browser via browser.OpenURL. The UI and integration login tests exercise the real login flow, so running `make test`/`make test-integration` on a machine with a GUI spawned real browser tabs (invisible in CI, where the open fails silently). Add two seams: - Unit: make the opener injectable via a new auth.WithBrowserOpener option on auth.New (loginProvider.openBrowser defaults to browser.OpenURL). The UI tests inject a recorder and assert the URL that would have been opened. - Integration (real binary, no Go seam): prepend a temp dir to PATH with fake open/xdg-open scripts that record the URL to a file, then assert it. No production-code changes needed there. Generated with [Linear](https://linear.app/localstack/issue/DEVX-982/make-test-opens-real-browser-tabs#agent-session-19a20b08) Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
The device-flow tests overrode LSTK_API_ENDPOINT but the auth URL opened in the browser is built from LSTK_WEB_APP_URL, which stayed at the production default - so the recorded URL was app.localstack.cloud, not the mock server. Point the web app URL at the mock server too, making the tests fully hermetic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The device-flow login opens the auth URL in a real browser (
browser.OpenURLininternal/auth/login.go). The UI login tests and the integration login tests exercise the real login flow against anhttptest.Server, so runningmake test/make test-integrationon a machine with a GUI spawned real browser tabs (three from the unit tests, two from the integration tests). It's invisible in CI because headless runners have noopen/xdg-opentarget, so the open just fails silently.Worse than a nuisance: the auth URL is built from the web app URL, not the API endpoint, and the integration tests only overrode
LSTK_API_ENDPOINT— so the two integration-test tabs pointed at the productionhttps://app.localstack.cloud/auth/request/…with synthetic auth-request IDs.This is a test-side issue only — auto-opening the browser on a real
lstk loginis intended (DEVX-530).Changes
No change to login behavior; the only production-code change is a test seam.
internal/auth:loginProvidergains an injectableopenBrowser func(string) errorfield (defaulting to the existingbrowser.OpenURLcall, moved intodefaultOpenBrowser).auth.Newaccepts variadicOptions, withWithBrowserOpenerto override the opener.internal/ui/run_login_test.go): all three device-flow tests inject abrowserRecorderviaauth.WithBrowserOpenerand now assert the exact URL that would have been opened.test/integration/login_test.go): the real binary can't take a Go func, so a newfakeBrowserOpenerhelper prepends a temp dir toPATHwith fakeopen/xdg-open/x-www-browser/www-browserscripts that record the URL to a file instead of spawning a tab. Both device-flow tests assert the recorded URL and setLSTK_WEB_APP_URLto the mock server (alongside the existingLSTK_API_ENDPOINToverride), making them fully hermetic — nothing references production anymore.test/integration/env: newPathandWebAppURLenv keys.Both assertions fail before the fix (no URL recorded / real tab) and pass after.