fix(auth): preserve saved values on re-authentication
Summary
Interactive glab auth login prompts for container_registry_domains, api_host, and ssh_host pre-filled from hostname-derived defaults, so a re-authentication (or a login after glab config set) silently overwrote the saved value when the user pressed Enter through the prompt.
This MR pre-fills each prompt from the value previously saved for the host, falling back to the derived default only when nothing is saved. The --api-host flag still wins over the saved value.
The pre-fill logic is extracted into initialAPIHostname, initialSSHHostname, and initialContainerRegistryDomains so it can be unit tested without driving the huh prompts.
Closes #8389 (closed).
Test plan
-
go test ./internal/commands/auth/login/...passes (including new unit tests for the three helpers). -
golangci-lint run ./internal/commands/auth/login/...clean. -
lefthook run pre-push(build, lint, test-changed, generated-docs) passes. - Manual verification of the reported scenario:
glab auth login --hostname gitlab.com --web --git-protocol ssh.glab config set container_registry_domains "my.custom.registry" --host gitlab.com.- Re-run
glab auth login, confirm re-authentication, pick a sign-in method. - The container-registry-domains prompt is now pre-filled with
my.custom.registryinstead of the derived default.
Follow-ups
The same pattern applies to git_protocol and api_protocol prompts (login.go:585-622). They aren't fixed here because both keys have Fallback: true in KeySchema, so cfg.Get can't distinguish "user set" from "schema default" without a new host-level accessor. Worth a separate MR.