Fix/stop routes missing from reference routes in trips-for-route-handler - #1360
Conversation
Add a test to ensure that routes referenced by stops but which are not referenced by returned trips are correctly resolved in references.routes and route agencies correctly resolve in reference.agencies
Populate sets.routes with stop routes before calling api.fillRoutesAndAgencies in order to ensusre that routes serving stops but which are not associated with any returned trips resolve in references.Routes
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan includes up to 1 review per rolling hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe trips-for-route handler now includes routes and agencies referenced by stops, even when those routes have no active returned trip. Tests cover reference resolution and exclude the inactive trip from results. ChangesTrips-for-route references
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This localized change adds stop-served routes and their agencies to trip references, with a regression test covering the behavior. No actionable merge-blocking risk remains beyond normal checks and review. 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 |
Code reviewFound 1 issue:
maglev/internal/restapi/trips_for_route_handler.go Lines 748 to 760 in e026efb 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
aaronbrethorst
left a comment
There was a problem hiding this comment.
Good fix, and the test fixture is the part I want to call out.
orphanStopRouteFiles builds a stop served by a route from a second agency
that no returned trip runs on, on a different block, at a different time — which
is precisely the case where the old code emitted a routeIds entry with nothing
behind it. Constructing that scenario deliberately is more work than asserting
against the RABA fixture and worth much more, because it fails pre-fix for the
right reason rather than by coincidence. The assert.Contains(stop.RouteIDs, combinedOrphanRouteID) self-guard on the fixture is a nice touch too — it means
the test can't silently stop testing anything if the fixture drifts.
Correctness checks that hold up:
- Moving
stopReferencesabovefillRoutesAndAgenciesand seedingsets.routes
from the stops' route IDs is the right ordering — the routes have to be known
before the batch fetch runs, not after. - No N+1 introduced: the new loop is pure in-memory over the map
stopReferencesalready returns, and route resolution still goes through the
single batchedGetRoutesByIDs. - Agencies come along via
addAgencyReference, so the second agency resolves too
— which is the half of #1339 that's easy to miss.
One follow-up, not blocking: the stop-route registration loop is close to a
verbatim copy of buildStopList in trips_for_location_handler.go, and per
CONTRIBUTING.md's Code Reuse section that belongs in reference_utils.go
alongside stopReferences — commit c00a305 consolidated the sibling function
there for the same reason. I'd rather land the correctness fix now and do that
consolidation once, covering this and #1353 together, than block a 19-line bug
fix on it. If you want to take that follow-up PR, I'd welcome it.
Merging.
…-includeSchedule-false Resolve buildTripReferences restructure in trips-for-route-handler.go which was restructured in OneBusAway#1360



Fix dangling stop route references in trips-for-route
Closes #1339
Problem
In the
trips-for-routeresponse,references.routeswas built exclusively fromthe routes of the returned trips:
buildTripReferencesseededsets.routesfromtrip.RouteID(collectPreFetchedTrips) and then resolved routes and agencies infillRoutesAndAgencies. A stop served by a route that no returned trip runs onemits a
routeIdthat resolves to nothing inreferences.routes.Fix
internal/restapi/trips_for_route_handler.go—buildTripReferences:api.stopReferencesbeforefillRoutesAndAgenciesand keep the returnedroute-IDs-by-stop map.
sets.routesbefore route/agency resolution runs.fillRoutesAndAgenciesthen resolves both the full route objects and theiragencies (
addAgencyReference), so routes and agencies are filled in by the oneexisting mechanism.
Testing
Added a regression test
TestTripsForRouteHandler_StopRoutesResolveInReferenceswith asynthetic fixture,
orphanStopRouteFiles(). The test asserts that routes serving stops whichare not associated with any returned trips are correctly resolved in
references.routesalongside the route agencies in
references.agencies. It fails in the pre-fix code and passespost-fix
Summary by CodeRabbit