align reference stop IDs with schedule combined IDs - #1240
Conversation
|
Warning Review limit reached
Next review available in: 7 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe trips-for-route handler now preserves combined stop IDs when collecting schedule stops and constructing response references. Tests verify combined reference IDs and the updated stop-ID mapping behavior. ChangesStop reference consistency
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/restapi/trips_for_route_handler_test.go`:
- Around line 194-197: Update the assertions in the route reference stops test
to compare the deduplicated refs.Stops ID set exactly with the deduplicated
schedule stop ID set from data.list[].schedule.stopTimes[].stopId. Remove the
underscore-only validation and assert equality in both contents and cardinality
so incorrect combined IDs cannot pass.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8aa67315-261b-4143-a969-74d13987dd51
📒 Files selected for processing (2)
internal/restapi/trips_for_route_handler.gointernal/restapi/trips_for_route_handler_test.go
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
aaronbrethorst
left a comment
There was a problem hiding this comment.
Approved on the merits. This is a real bug and the fix is well-chosen.
The spec says data.list[].schedule.stopTimes[].stopId is a combined stop ID and that full detail for it appears in data.references.stops — which only works if the two strings match. They didn't: the schedule emitted utils.FormCombinedID(agencyID, stopTime.StopID) while references.stops[].id carried the bare feed ID straight off the DB row. So a client doing the lookup the spec describes found nothing.
What I like about the approach: you carry the exact combined string the schedule already produced through the map, rather than re-deriving it. stopID = combinedID is a plain assignment, not a re-wrap, so there's no way to double-prefix — which is the obvious failure mode for a change like this. And keeping the DB lookup keyed on bare IDs is right; GetStopsByIDs needs the feed ID.
I also checked this leaves the endpoint consistent with its siblings — stops_for_route_handler.go, reference_utils.go, and trips_for_location_handler.go all emit utils.FormCombinedID(agencyID, stop.ID) for reference stop IDs, so this brings trips-for-route in line rather than inventing a local convention. And references.stops[].routeIds were already combined via the SQL, so there's no residual mismatch left inside the stop object.
Tightening the integration test to exact set equality between references.stops[].id and the deduped schedule stop IDs is the right assertion — much better than checking for the presence of an underscore.
Blocked only on the merge conflict. main has since wrapped both buildTripReferences call sites in an includeReferences guard (from #1216), which shifts them. The resolution is mechanical and doesn't change behavior, so no re-review needed — merge main in, resolve, and I'll merge this.
Two small notes for later, neither blocking:
collectStopIDsFromScheduleis first-wins per bare stop ID. If two trips in the same result set belong to different agencies and share a stop, only one combined ID lands in references and the other agency'sstopTimes[].stopIdstill won't resolve. Blocks are agency-scoped in practice so this is rare, and it's strictly better than the status quo where neither resolved.- The
stopID := stop.IDfallback is unreachable —stopscomes solely fromGetStopsByIDs(bareIDs)wherebareIDsare exactly the map's keys, so theokbranch always fires. Harmless, but it's dead.
Also: the PR description still describes the older assertion (checking for the presence of _) rather than the exact-set-equality one you actually landed in f694603c. Worth updating so the commit history reads accurately.
Update collectStopIDsFromSchedule to retain the full combined stop ID in the translation map rather than stripping the agency prefix. Modify buildTripReferences to use this map, ensuring that stops fetched from the database (using bare IDs) are correctly serialized with their combined IDs in the references envelope. This guarantees that client-side lookups using schedule stopTimes will successfully match the entries in data.references.stops, strictly adhering to the OBA specification.
f694603 to
49e25c6
Compare
|



Description
This PR resolves a data inconsistency in the
trips-for-routeresponse where the Stop IDs provided indata.references.stopsdid not match the combined ID format (AgencyID_StopID) used within the trip schedules. This mismatch prevented successful client-side lookups.Changes Made
collectStopIDsFromScheduleto build amap[string]stringacting as a translation dictionary, mapping bare database IDs to their fully combined schedule IDs.buildTripReferencesto accept this translation map, applying the combined IDs when constructing themodels.Stopreferences.GetStopsByIDsqueries continue to use bare IDs, maintaining compatibility with the database schema.nilfor the new map parameter to satisfy the Go compiler.collectStopIDsFromScheduleunit tests to reflect the new map type. Enhanced the integration test (TestTripsForRouteHandler_DifferentRoutes) to strictly assert that reference stop IDs are generated in the combined format (verifying the presence of_).Closes: #1237
Summary by CodeRabbit