You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add structured IP-derived location metadata to CLI reports - #165
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Private coordinate-presence flags prevent callers from preserving explicit zero coordinates, and fallback country names can contradict the structured country and produce misleading output.
Adds structured, approximate IP-derived location metadata to CLI reports, supporting the backend work described in librespeed/speedtest#881 while preserving legacy ISP and IP fallbacks.
Changes:
Parses and merges optional location metadata with legacy fields, validating coordinates.
Adds location details to human-readable, CSV, and JSON output.
Adds tests for parsing, malformed values, fallback behavior, and output formatting.
File
Description
speedtest/speedtest_test.go
Tests location summaries and coordinate handling.
speedtest/helper.go
Includes location details in CLI and report output.
report/json.go
Adds structured location to JSON clients.
report/json_test.go
Tests structured and legacy JSON location data.
report/csv.go
Adds place and coordinate columns.
report/csv_test.go
Checks location headers and values.
defs/server.go
Preserves location metadata during fallback parsing.
defs/server_test.go
Tests structured and malformed getIP location responses.
defs/defs.go
Defines location parsing, validation, serialization, and merging.
defs/defs_test.go
Tests location normalization and legacy fallbacks.
Preserve explicit zero coordinates and only merge fallback country names that match the effective country.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Latitude-presence inference mistakes an omitted latitude for explicit zero, causing incorrect serialization, blocking merges from filling it, and preventing invalid latitude updates from clearing its presence.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Latitude inference fabricates zero coordinates and blocks valid fallback values, while merging geographic fields from a different country produces contradictory location metadata.
Skip geographic fallback fields when country codes conflict
defs/defs.go:368
The country compatibility check only protects CountryName; this block still copies city, region, and coordinates from a fallback that names a different country. For example, structured {"country":"DE"} plus legacy {"city":"Boydton","region":"Virginia","country":"US","loc":"36.6676,-78.3875"} produces Boydton, Virginia, DE (36.6676, -78.3875) in human output and the same contradictory metadata in CSV/JSON. Skip geographic fallback fields when both country codes are present and disagree.
Build, vet, gofmt, unit tests and -race are clean, and the two hard parts of the parsing are right: explicit zero coordinates survive, and a missing latitude is no longer inferred from a longitude. One merge case still produces contradictory metadata.
❌ error — a country name from structured data is overridden by an unrelated fallback country
defs/defs.go:360-372 copies the fallback country before it checks compatibility:
When the structured location carries a country name but no code ({"countryName":"United States"}) and rawIspInfo carries a different country ({"country":"DE","city":"Berlin","latitude":1,"longitude":2}), the fallback code wins and the primary name is kept. Probe on this head:
The CSV row and the human line then say United States next to Berlin coordinates; JSON has country:"DE" next to countryName:"United States". The same happens for a primary city without a country: Berlin plus US coordinates from the fallback. This is the remaining half of the contradictory-country finding.
Concrete fix: treat a non-empty primary.CountryName as a country identity. If primary.Country == "" && primary.CountryName != "", do not copy fallback.Country, and merge fallback place/coordinates only when fallback.Country == "" (or reconcile the name to a code first). Add a regression test with a country-name-only primary and a fallback in a different country; it should keep countryName:"United States" and copy neither DE nor Berlin's coordinates. TestMergeLocationsDoesNotCopyCountryNameForDifferentCountry (defs/defs_test.go:226) only covers the code-vs-code case.
💡 nitpicks (optional)
defs/defs.go:389-396 fills one missing coordinate from the fallback and keeps the other from the primary, so a point can pair coordinates from two sources (the existing test expects (36.6676, 10)). Either document that or do not mix sources.
report/json.go:45-49 adds a Location *LocationInfo field next to the embedded IPInfoResponse.Location (json:"loc"). The JSON keeps both, but Go callers of report.Client now get a different type for Client.Location. A distinct name would avoid the shadowing.
report/json.go:65-67 accepts variadic structured locations but silently uses only the first; drop the variadic or reject extras.
speedtest/helper.go:401 now sends the new location object inside the telemetry ispinfo payload. That changes a payload sent to third-party servers; it is untested and undocumented.
The CSV header grows from 9 to 15 columns and the JSON gains client.location, but README/CHANGELOG do not describe either, and there is no flag to opt out. Header-based CSV parsers are fine; scripts that require exactly 9 fields are not.
client.city / client.region / client.country still come from rawIspInfo while client.location prefers the structured object, so the two can disagree in one response. Worth a note if that is intentional.
Verification
go build ./..., go vet ./..., gofmt -l .: pass/clean.
go test -count=1 ./...: pass (root 5.9s, defs 9.3s, report 0.005s, speedtest 6.8s).
go test -count=1 -race ./...: pass.
Merge probe above: reproduced on this head; temporary test removed afterwards.
Not verified: end-to-end CLI against a fake getIP endpoint for the CSV, JSON and human outputs; telemetry payload; terminal output with hostile location strings (the human path does run through output.Sanitize, so this looks safe).
No CI checks are configured for this branch, so the checks above are the only evidence. Once the merge case is fixed I can re-run them and approve.
All identified review findings are resolved, including explicit coordinate presence, country-name fallback consistency, omitted-latitude handling, and conflicting-country merges. go test ./..., go vet ./..., and git diff --check pass. The PR remains open, mergeable, and linked to librespeed/speedtest#881.
Follow-up commit d49ad74 addresses Maddie’s country-name-only merge finding and the coordinate-mixing nitpick. Country-name-only primaries now keep their identity and reject incompatible fallback geography/country/coordinates; compatible US/United States fallbacks remain eligible, identity-absent fallbacks remain eligible, and place-only primaries do not absorb identified fallback countries. Extra variadic structured-location arguments are rejected, and README notes now cover CSV/JSON fields and telemetry's optional location object.\n\nValidation: gofmt clean, go test -count=1 ./..., go test -count=1 -race ./..., go build ./..., go vet ./..., and git diff --check all pass. The PR remains open and mergeable; please re-review the latest head.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Country matching can discard compatible fallback data for unmapped countries and merge locations with conflicting explicit country codes, producing incomplete or inconsistent reports.
Latest follow-up 6f6c0f7 resolves the remaining country-identity threads: explicit differing country codes are authoritative even when names are shared, and country name/code equivalence now uses CLDR English region coverage from golang.org/x/text with common alpha-3 aliases. Regressions cover differing DE/US explicit codes and Finland/FI equivalence.\n\nVerification passes: gofmt clean, go test -count=1 ./..., go test -count=1 -race ./..., go build ./..., go vet ./..., and git diff --check. The PR remains open and mergeable; please re-review the latest head.
Latest head 6f6c0f7 is ready for Maddie’s re-review.
It fixes the remaining country-identity edge cases: explicit conflicting country codes are rejected, and equivalent country names/codes outside the alias table are preserved. It also addresses Maddie’s coordinate-mixing, variadic location, telemetry, and CSV/JSON documentation nitpicks.
Validation passed: gofmt -l ., go build ./..., go vet ./..., go test -count=1 ./..., go test -count=1 -race ./..., and git diff --check. All PR review threads are resolved and the PR remains open and mergeable.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because an unpublished finding indicates that whitespace-only location fields can suppress valid fallback data in summaries and exports.
@maddie Latest head b73d7c7 is ready for re-review. The follow-up fixes the remaining whitespace/invisible-text fallback case, preserves partial place and country-only fallbacks, rejects invalid/non-finite coordinates, keeps JSON/JSON-stream reports in parity, and verifies telemetry preserves legacy and location payloads. It also documents CSV/JSON/telemetry behavior and retains processedString/rawIspInfo compatibility. Cross-repo reconciliation reviewed the coordinated LibreSpeed getIP implementation PR set: PHP core 882, Go backend 96, Rust backend 53, Rust CLI 50, desktop 11, and Android 60. All currently unresolved Go CLI review threads are resolved. Validation passed: gofmt clean, go test -count=1 ./..., go test -count=1 -race ./..., go build ./..., go vet ./..., and git diff --check. No JavaScript sources exist in this repository. The PR remains open and mergeable; please re-review the latest head.
@maddie@billmcilhargey Latest head b73d7c7 is ready for maintainer re-review. The Go CLI location/merge, explicit zero, CSV/JSON/telemetry, and country-identity fixes pass gofmt/build/vet/test/race/diff checks, and no unresolved inline threads remain. PR remains open and mergeable.
@maddie Fresh latest-head audit complete at b73d7c7. I re-read every inline thread, top-level comment, formal review, maintainer/user status, and CI state. Zero review threads are unresolved and no new concrete code finding was found on this head. Validation passes: gofmt clean, go test -count=1 ./..., go test -count=1 -race ./..., go build ./..., go vet ./..., and git diff --check. Maddies formal CHANGES_REQUESTED remains attached to the older 93e2418 review; it needs explicit re-review against b73d7c7. PR #165 remains open and mergeable.
This branch has not been deployed
No deployments
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
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
locationmetadata.processedString,rawIspInfo, and IP fallbacks.Verification
go test ./...go vet ./...git diff --checkContext
Tracked by librespeed/speedtest#881: which covers ISP and approximate IP-derived location metadata.