Skip to content

Add structured IP-derived location metadata to CLI reports - #165

Open
billmcilhargey wants to merge 7 commits into
librespeed:masterfrom
blackoutsecure:billmcilhargey-new-session
Open

billmcilhargey wants to merge 7 commits into
librespeed:masterfrom
blackoutsecure:billmcilhargey-new-session

Conversation

@billmcilhargey

@billmcilhargey billmcilhargey commented Nov 25, 2026 •

Copy link
Copy Markdown

Summary

  • Parse optional top-level getIP location metadata.
  • Preserve legacy processedString, rawIspInfo, and IP fallbacks.
  • Display approximate city/region/country and validated coordinates in human, CSV, and JSON output.

Verification

  • go test ./...
  • go vet ./...
  • git diff --check

Context

Tracked by librespeed/speedtest#881: which covers ISP and approximate IP-derived location metadata.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 21:45

Copilot AI 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.

🟡 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.

2 open issues
What changed in this PR

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.

Review effort: Balanced

Comment thread defs/defs.go Resolved
Comment thread defs/defs.go Resolved
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>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 22:03
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

🟡 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.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread defs/defs.go Resolved
Copilot AI balanced review requested due to automatic review settings November 25, 2026 22:06

Copilot AI 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.

🔵 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.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity 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.

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 22:35

Copilot AI 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.

🟢 Approval recommended

No active review issues are recorded for the IP-derived location reporting changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@maddie maddie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review of 93e2418

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:

if merged.Country == "" {
    merged.Country = fallback.Country
}
effectiveCountry := strings.TrimSpace(merged.Country)

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:

merged={"latitude":1,"longitude":2,"city":"Berlin","country":"DE","countryName":"United States"}

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.

@billmcilhargey

Copy link
Copy Markdown
Author

Ready for maintainer review.

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.

@billmcilhargey

Copy link
Copy Markdown
Author

Final follow-up fixes are complete and all unresolved review threads are resolved.

Please re-review the latest head; the PR remains open and mergeable.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 02:20
@billmcilhargey

Copy link
Copy Markdown
Author

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.

Copilot AI 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.

🟡 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.

2 open issues

Review effort: Balanced

Comment thread defs/defs.go Resolved
Comment thread defs/defs.go Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 02:30
@billmcilhargey

Copy link
Copy Markdown
Author

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.

@billmcilhargey

Copy link
Copy Markdown
Author

Follow-up commit 6f6c0f7 addresses Maddie's remaining merge-compatibility finding and the nearby country-name/code edge cases.

  • Country-name-only primary locations now preserve their identity and reject unrelated fallback geography.
  • Explicit conflicting country codes are rejected before fallback place/coordinate merging.
  • Country-name/code equivalence covers names and codes outside the original alias table.
  • Coordinate mixing is prevented, extra variadic structured locations are rejected, and CSV/JSON/telemetry behavior is documented.

Validation passed: gofmt -l ., go build ./..., go vet ./..., go test -count=1 ./..., go test -count=1 -race ./..., and git diff --check.

All review threads are resolved. Please re-review the latest head (6f6c0f7); PR #165 remains open and mergeable.

@billmcilhargey

Copy link
Copy Markdown
Author

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.

Copilot AI 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.

🔵 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.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 03:39
@billmcilhargey

Copy link
Copy Markdown
Author

@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.

Copilot AI 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.

🟢 Approval recommended

The IP-derived location reporting changes have no active review issues.

No open issues 🎉

Review effort: Balanced

@billmcilhargey

Copy link
Copy Markdown
Author

@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.

@billmcilhargey

Copy link
Copy Markdown
Author

@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
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.

3 participants