Uh oh!
There was an error while loading. Please reload this page.
feat(cli): location auto-detect for client create (#84) - #93
Merged
Conversation
The deferred fast-follow from cli#92: pre-fill `client create`'s location prompt with a detected electricityMaps zone (backend ZONE_CHOICES), so a cloud-hosted client doesn't have to look up its own zone. - internal/geo: Detect() probes cloud instance metadata first (AWS IMDSv2/v1, GCP, Azure — concurrently under one short deadline, first wins → high confidence), then Cloudflare IP geolocation (low confidence, flagged). Returns an ISO country code, always a valid top-level zone; cloud regions map via a curated AWS/GCP/Azure table, and an unmapped region falls through to GeoIP for a valid zone rather than suggest something the backend would reject. - client create: the detected zone pre-fills the prompt default (the user confirms with Enter or overrides) — still never silent, never empty. A detectZone seam keeps the command tests hermetic. - Best-effort: offline / egress-restricted / bare metal → empty default (the prior behavior). Only runs interactively when --location is omitted. Tests: geo per-provider + GeoIP fallback + unmapped-region fallthrough + nothing-detected + region→country table; cli accepts-detected-zone end-to-end. go build/vet/test green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
saadqbalforce-pushed
the
feat/84-location-autodetect
branch
from
July 6, 2026 14:27
7efdd9c to
edb8dedComparesaadqbal
marked this pull request as ready for review
July 6, 2026 14:27
probeCloud returns on the first probe to report a region and leaves the losing goroutines running to their deadline. They read the package-level endpoint vars (awsIMDSBase/gcpMetaBase/azureIMDSBase) directly, so a test's t.Cleanup — which restores those vars — races the still-running goroutines under `go test -race` (TestDetect_* flaked in CI). Snapshot the bases into locals synchronously, before spawning the goroutines, and pass each into its detectX; the probes now touch only captured locals, never the mutable globals. First-wins latency is unchanged. `go test -race -count=30 ./internal/geo/...` clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
saadqbal
approved these changes
Jul 6, 2026
Uh oh!
There was an error while loading. Please reload this page.
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 freeto 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.
Summary
The deferred fast-follow from #92:
client createnow pre-fills its location prompt with an auto-detected electricityMaps zone (the backend'sZONE_CHOICES), so a cloud-hosted client doesn't have to look up its own zone.Stacked on #92 (
feat/84-client-commands) — it wires into that PR'sclient create. Retarget todeveloponce #92 merges.How detection works (
internal/geo)Detect(ctx)returns a best-effortZone{Code, Source, Confidence}or nil:cdn-cgi/traceloc=(HTTPS, no API key) → ISO country.The output is always an ISO alpha-2 country code, which is always a valid top-level
ZONE_CHOICESvalue. An unmapped cloud region falls through to GeoIP rather than suggest a string the backend would reject.UX
--locationis omitted;--location Xskips it entirely.Tests
internal/geo: each provider, GeoIP fallback, unmapped-region fallthrough, nothing-detected, region→country table — endpoints mocked viahttptest(the metadata/GeoIP URLs are overridable package vars).internal/cli: detected zone accepted as the default, end-to-end. AdetectZoneseam keeps the command tests hermetic (no real probes). Fullgo build/vet/test ./...green.Follow-up noticed (separate)
locationisCharField(choices=ZONE_CHOICES)— the backendChoiceFieldrejects any value not in the list. cli#92's free-text--location(and a user override here) can still send an invalid zone that only fails at create time as a raw 400. Worth vendoringZONE_CHOICESinto the CLI to validate / offer a picker — happy to file that.🤖 Generated with Claude Code