Skip to content

Refactor coordinate parsing, prevent panic on malformed ID, use url.JoinPath, and expand test coverage - #9

Merged
bamnet merged 1 commit into
masterfrom
improve-code-quality-and-tests
Jun 24, 2026
Merged

Refactor coordinate parsing, prevent panic on malformed ID, use url.JoinPath, and expand test coverage#9
bamnet merged 1 commit into
masterfrom
improve-code-quality-and-tests

Conversation

@bamnet-bot

Copy link
Copy Markdown
Collaborator

This Pull Request implements several improvements and bug fixes outlined in the codebase review:

  1. URL Construction: Refactored client.go to use standard library url.JoinPath instead of manual path string concatenation, which was fragile if the base URL lacked a trailing slash.
  2. Panic Prevention & Skips: Added guards against nil match results when extracting numbers from train IDs using regex in VehicleData in vehicle_data.go. This skips the entry cleanly rather than triggering a runtime panic.
  3. Unified Coordinate Parsing: Consolidated all longitude/latitude parsing to a single parseLatLng helper in util.go. This helper returns nil when coordinates are missing or whitespace-only (preventing incorrect {0.0, 0.0} coordinate mappings).
  4. Enhanced Test Coverage: Added direct unit tests for coordinate parsing (TestParseDegrees and TestParseLatLng) in util_test.go.

All tests pass successfully with race detection and statement coverage has increased to 87.6%. These changes improve stability and prepare the API for further active development.

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.24%. Comparing base (c7f33d0) to head (dd0fc72).

Files with missing lines Patch % Lines
vehicle_data.go 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master       #9      +/-   ##
==========================================
+ Coverage   84.22%   84.24%   +0.01%     
==========================================
  Files           5        5              
  Lines         279      273       -6     
==========================================
- Hits          235      230       -5     
+ Misses         27       26       -1     
  Partials       17       17              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors latitude and longitude parsing by centralizing the logic into a new parseLatLng utility function, replacing duplicate inline parsing across multiple files, and adding comprehensive unit tests. Additionally, it updates VehicleData to safely handle regex match failures on train IDs and optimizes slice construction. The review feedback highlights that the removeDupTrains function introduces non-determinism due to randomized map iteration in Go, which can cause flaky tests, and suggests refactoring it to preserve insertion order.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread vehicle_data.go
t.ScheduledDepartureTime, _ = parseTime(d.ScheduledDepartureTime)
trains = append(trains, t)
}
return removeDupTrains(trains), nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The removeDupTrains function returns a slice with non-deterministic order when duplicates are present. This is because it iterates over a map (for _, t := range ts) to construct the final slice, and Go map iteration order is randomized at runtime.\n\nThis non-determinism can lead to flaky tests and unstable API responses for clients expecting a consistent order.\n\nConsider refactoring removeDupTrains to preserve the original insertion order. For example, you can maintain a slice of IDs in the order they were first seen, and use that slice to construct the final output:\n\ngo\nfunc removeDupTrains(trains []Train) []Train {\n\tts := map[int]Train{}\n\tvar order []int\n\n\tfor _, t := range trains {\n\t\tif _, ok := ts[t.ID]; !ok {\n\t\t\torder = append(order, t.ID)\n\t\t\tts[t.ID] = t\n\t\t} else if ts[t.ID].LastModified.Before(t.LastModified) {\n\t\t\tts[t.ID] = t\n\t\t}\n\t}\n\n\tif len(ts) == len(trains) {\n\t\treturn trains\n\t}\n\n\tunique := make([]Train, 0, len(ts))\n\tfor _, id := range order {\n\t\tunique = append(unique, ts[id])\n\t}\n\treturn unique\n}\n

@bamnet
bamnet merged commit 6abf558 into master Jun 24, 2026
3 checks passed
@bamnet
bamnet deleted the improve-code-quality-and-tests branch June 29, 2026 04:43
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.

2 participants