Add maxCount validation to trips-for-route - #1223
Conversation
|
Warning Review limit reached
Next review available in: 37 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. 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 validates non-empty ChangesTrips-for-route maxCount validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 268-292: Add a table-driven test case alongside the existing
maxCount cases for the documented upper boundary, using maxCount "250" and
expecting http.StatusOK. Keep the existing "300" rejection case to verify values
above the limit remain invalid.
🪄 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: c3bb0135-e8ee-47c2-9491-ab54ab88b379
📒 Files selected for processing (2)
internal/restapi/trips_for_route_handler.gointernal/restapi/trips_for_route_handler_test.go
Code reviewFound 1 issue:
maglev/internal/restapi/trips_for_route_handler.go Lines 32 to 39 in 48b14ef 🤖 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.
You got the hard part exactly right, and I want to call it out before the criticism: you discarded the parsed value with _ so maxCount never truncates the result list, and left limitExceeded hard-coded false. That's the central spec point for this endpoint and it's counterintuitive — the obvious "fix" would have been to apply the limit, which would have been wrong. The spec is explicit that TripStatusBeanServiceImpl.getTripsForRoute never reads query.getMaxCount(), so all matching trips are always returned. You matched that.
The problem is the validation half.
Returning 400 for maxCount <= 0 or maxCount > 250 isn't upstream behavior for this endpoint.
utils.ParseMaxCount produces a maxCount field error for values <= 0 and rejects values above the cap. But TripsForRouteAction has no range validation at all: _maxCount is a bare new MaxCountSupport(), whose no-arg constructor sets both the default and the absolute max to Integer.MAX_VALUE, and setMaxCount(int) carries no validator annotation. So upstream returns 200 OK for maxCount=0, -1, and 300 alike.
The wiki backs this up from the other direction. The Minimal Guarantees say the response is always 200 OK, and the Extensions section enumerates exactly one 400 case for this endpoint — a missing id path parameter. There is no maxCount error listed. The parameter's own schema entry reads simply "Accepted but ignored — has no effect on result count."
It's worth contrasting routes-for-location, where a ceiling does exist: even there the spec notes the server "silently clamps maxCount … No error is returned", and the <= 0 → 400 behavior comes from explicit code in RoutesForLocationAction.index that TripsForRouteAction simply doesn't have. Neither ParseMaxCount nor ParseMaxCountClamped matches an action with no ceiling whatsoever.
So as written, this converts requests that currently succeed into 400s. What I'd like instead: keep rejecting non-numeric input (maxCount=abc genuinely is a 400 upstream, via Struts2 type conversion) and accept any integer value silently.
I should flag the root cause so it doesn't bite again: linked issue #1210 states "Java returns 400 for maxCount <= 0 or maxCount > 250". That's accurate for some endpoints but not for trips-for-route, and it's what sent this PR in the wrong direction. Worth correcting the issue too — that's not on you to have caught.
One more thing while you're in here: since the whole point is that maxCount must not truncate, the test should assert that. Right now the 200 cases only check the status code, so if someone later wires the limit in, these tests still pass. Asserting that the result count is identical with maxCount absent and with maxCount=1 would lock in the behavior you're deliberately preserving.
This also has merge conflicts — its base predates the includeReferences := ShouldIncludeReferences(r) addition on main. The inserted block itself stays correct after a rebase since it sits before the GetAgency call, so that part is mechanical.
Drop the range validation, keep the non-numeric check, add the count-unchanged assertion, and rebase — then I'll merge it.
48b14ef to
c18027b
Compare
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 534-553: Add a second concurrently active trip in a different
block to the fixture setup used by
TestTripsForRouteHandler_MaxCountDoesNotTruncate, ensuring the baseline response
contains more than one trip. Keep the existing requests and assert that the
maxCount=1 response count equals the full baseline count, making parameter
truncation observable.
🪄 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: 15fcd50f-6174-40ce-a056-f9a225cb21af
📒 Files selected for processing (2)
internal/restapi/trips_for_route_handler.gointernal/restapi/trips_for_route_handler_test.go
The maxCount parameter is now parsed and validated using the shared utils.ParseMaxCount helper. Invalid values (<= 0, > 250, or non-numeric) correctly return a 400 Bad Request with a fieldError. Valid values are parsed but intentionally discarded. This preserves the upstream Java defect documented in the spec, where the parameter is validated but never applied to the result count. Comprehensive test coverage is added for missing, valid, negative, zero, out-of-bounds, and non-numeric inputs.
Remove strict range checks for the maxCount parameter, as the upstream Java implementation does not enforce a ceiling or floor for this action. Reject only non-numeric inputs with a 400 Bad Request. Update existing tests to expect a 200 OK for values like 0, -1, and 300. Add a new assertion to guarantee that providing maxCount does not alter the returned result count, preserving the documented upstream defect.
Update the test fixture to include multiple concurrently active trips on the same route. Assert that the baseline response contains at least two entries, proving conclusively that requesting maxCount=1 does not truncate the returned list.
c18027b to
d49cee8
Compare
|
|
Closing this one out without merging — the validation logic and tests are good, this is about whether
So the "Suspected Defect" framing in the spec is probably wrong for this endpoint — Java isn't failing to apply I'll update spec accordingly. |



Summary
Adds
maxCountquery parameter validation to thetrips-for-routeendpoint. The parameter is validated to strictly match the legacy Java OBA behavior: it silently accepts any integer (including 0, negative values, and large numbers) and only rejects non-numeric inputs. The parsed value is intentionally not applied to the result list, preserving the documented upstream defect.Changes
internal/restapi/trips_for_route_handler.go: Added a simplestrconv.Atoicheck to reject non-numeric inputs (which cause a400 Bad Requestupstream via Struts2 type conversion). Any valid integer is parsed but intentionally discarded via the blank identifier_so it does not truncate the result set.internal/restapi/trips_for_route_handler_test.go:TestTripsForRouteHandler_MaxCountValidationto expect200 OKfor default/omitted, valid value, zero, negative, and out-of-bounds inputs. Only non-numeric inputs (abc) expect a400 Bad Request.TestTripsForRouteHandler_MaxCountDoesNotTruncateusing a fixture with multiple concurrently active trips to explicitly assert that passingmaxCount=1returns the exact same baseline count as a request withoutmaxCount, proving the parameter is correctly ignored.Closes: #1210
Summary by CodeRabbit
maxCountquery parameter when retrieving trips for a route.