search-route: complete test coverage and spec verification - #1284
search-route: complete test coverage and spec verification#1284ARCoder181105 wants to merge 4 commits into
Conversation
routeSearchHandler hand-rolled six sql.NullString unwraps instead of using internal/nulls, the pattern every other route-building handler follows (routes_for_agency_handler.go, routes_for_location_handler.go, etc). No behavior change.
Covers gaps against the search-route wiki spec: maxCount validation (0, non-numeric, missing input entirely all return 400), limitExceeded=false, response envelope fields (version, currentTime, empty references.routes), and a search-route row in the shared context-cancellation table. Folds the now-redundant TestRouteSearchHandlerMaxCountBoundaries into the new table-driven maxCount test. A no-match query returning 200 with an empty list is intentional and left untouched: the wiki spec documents this as maglev's deliberate deviation from the legacy 404 behavior, matching search/stop.
📝 WalkthroughWalkthroughThe route-search handler now uses ChangesRoute search validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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/context_cancellation_test.go`:
- Around line 84-95: Add a route-search-specific test using an already-canceled
request context, and configure the test request or API setup to bypass the rate
limiter. Invoke routeSearchHandler directly and assert its deterministic
cancellation response status instead of accepting generic 200, 429, or 500
outcomes in the existing test.
🪄 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: e3fcfc6f-1635-4a42-939d-d71719c86d7d
📒 Files selected for processing (3)
internal/restapi/context_cancellation_test.gointernal/restapi/route_search_handler.gointernal/restapi/route_search_handler_test.go
The shared context-cancellation table used a 1ns timeout and a loose multi-status assertion, and adding a search-route row to it meant weakening that shared assertion to accept 429 just to cover the rate-limiter budget spent by five earlier rows in the same test. Revert that addition and instead give search-route its own cancellation test using a past deadline, matching the existing TestBlockHandlerContextCancellation pattern: deterministic DeadlineExceeded with no timer-resolution race, exact 504 assertion, own rate-limit budget.
data.outOfRange is hardcoded false for search-route per spec (no geographic bounding), but no test checked it. Also the handler's doc comment claimed optional lat/lon/radius filtering that the handler never implemented — leftover from a copy-paste, corrected to describe what the handler actually does.
|



Summary
Completes the search-route endpoint review against the wiki spec. The endpoint's behavior was already correct — this fills in the missing test coverage and cleans up two small inconsistencies found along the way.
Tests added
maxCountvalidation:0, non-numeric, and missinginputentirely all return 400limitExceededasserted in both directionsversion,currentTime, emptyreferences.routes,outOfRangeCleanup
routeSearchHandlernow usesnulls.StringOrEmptyinstead of hand-rolledsql.NullStringunwrapping, matching every other route-building handlerTestRouteSearchHandlerMaxCountBoundariesinto the new table-drivenmaxCounttestNo behavior changes.
Notes
The "404 on no results" case from #1202 is deliberately skipped. #1197 closed by updating the spec: returning 200 with an empty list is maglev's intended deviation from legacy, matching
search/stop. Adding the 404 would be a regression.Two things left for the reviewer to decide, both out of scope here:
routes_ftsindexesid, agency_id, short_name, long_name, desc, while the legacy Java index only coversroute_long_name(falling back to the combined id when null) — so maglev matches a superset, e.g. routes hit only viaroute_desc.searchStopsHandlerhas the same incorrect geo-filtering doc comment; it belongs to the search-stop card.Closes #1202.
Test plan
go vet -tags "sqlite_fts5 sqlite_math_functions" ./...go vet -tags "purego" ./...make testgo fmt ./...Summary by CodeRabbit
Bug Fixes
Tests