Skip to content

fix: include outOfRange field in vehicles-for-agency response#1114

Open
3rabiii wants to merge 2 commits into
OneBusAway:mainfrom
3rabiii:fix-vehicles-for-agency-gap-5
Open

fix: include outOfRange field in vehicles-for-agency response#1114
3rabiii wants to merge 2 commits into
OneBusAway:mainfrom
3rabiii:fix-vehicles-for-agency-gap-5

Conversation

@3rabiii

@3rabiii 3rabiii commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes a spec gap where the vehicles-for-agency endpoint was missing the outOfRange boolean field in the response envelope's data object.

Problem

The spec mandates that the data object must contain an outOfRange boolean to help clients distinguish between agencies that are simply unknown and those that are outside the server's service area. The previous implementation used models.NewListResponse, which completely omitted this field from the JSON output.

Changes

  • Updated the handler to use models.NewListResponseWithRange(...).
  • Known Agencies: Now explicitly emit outOfRange: false in the success path.
  • Unknown Agencies (Extension 3a): Now explicitly emit outOfRange: false alongside the empty list when agency == nil.
  • Note: Because Maglev currently operates as a single-instance architecture (it serves all agencies present in its GTFS DB), the "out of service area" scenario (Extension 4a / outOfRange: true) is not currently applicable. The key fix is ensuring the field is consistently present in the payload.
  • Added test coverage to assert outOfRange == false for both known and non-existent agencies.

Closes #1113

Summary by CodeRabbit

  • Bug Fixes

    • Improved the vehicles-for-agency response so range information is returned consistently for both unknown and valid agencies.
    • Ensured the response correctly marks outOfRange as false in these cases.
  • Tests

    • Added and updated coverage to verify the outOfRange field in vehicles-for-agency responses.

Switched from NewListResponse to NewListResponseWithRange to ensure
the outOfRange boolean is properly emitted in the response envelope's
data object, fulfilling minimal guarantee requirements.

Since Maglev currently operates as a single-instance server covering
its entire configured database, outOfRange is hardcoded to false for
both known agencies and unknown/untracked agencies (Extension 3a).
Added corresponding test assertions.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@3rabiii, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 33 minutes and 59 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 credits.

🚦 How do rate 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 see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5d9025fe-01e8-4946-a5c6-f7adf2d29bfc

📥 Commits

Reviewing files that changed from the base of the PR and between 0744619 and 6c30827.

📒 Files selected for processing (1)
  • internal/restapi/vehicles_for_agency_handler_test.go
📝 Walkthrough

Walkthrough

The vehiclesForAgencyHandler now uses models.NewListResponseWithRange (with outOfRange=false) instead of models.NewListResponse at both the nil-agency early-exit and the final response construction. Two test assertions are added to verify OutOfRange=false for unknown and known agency requests.

Vehicles-for-agency outOfRange field

Layer / File(s) Summary
Switch response constructors to NewListResponseWithRange
internal/restapi/vehicles_for_agency_handler.go
Both the nil-agency early-exit and the final response construction now call NewListResponseWithRange with an explicit outOfRange=false flag instead of NewListResponse.
Assert outOfRange=false in handler tests
internal/restapi/vehicles_for_agency_handler_test.go
Existing non-existent-agency test gains an OutOfRange=false assertion; new test TestVehiclesForAgencyHandler_OutOfRangeFalseForKnownAgency verifies the same field for a known agency.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • OneBusAway/maglev#941: Updates the vehicles-for-agency REST handler using the typed response pattern that this PR's outOfRange assertions build on.

Suggested reviewers

  • fletcherw
  • aaronbrethorst
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds outOfRange=false coverage, but it does not implement the required outOfRange=true behavior for agencies outside the service area. Add the out-of-service-area branch that returns HTTP 200 with an empty list and data.outOfRange=true, and cover it with a test.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding outOfRange to the vehicles-for-agency response.
Out of Scope Changes check ✅ Passed All code changes and tests are directly related to emitting and verifying the outOfRange field in vehicles-for-agency responses.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

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/vehicles_for_agency_handler_test.go`:
- Around line 72-85: The current assertions in TestVehiclesForAgencyHandler and
TestVehiclesForAgencyHandler_OutOfRangeFalseForKnownAgency only check the
decoded bool, so they won’t fail if data.outOfRange is missing from the JSON.
Update these tests to inspect the raw response payload (or decode the data
object into a map/json.RawMessage) and assert that the outOfRange field is
actually present before verifying it is false; keep using the existing helpers
like callAPIHandler and the VehiclesForAgencyResponse path to locate the check.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ced07b4-e657-49c3-8d83-5fab3e257504

📥 Commits

Reviewing files that changed from the base of the PR and between 3b4447f and 0744619.

📒 Files selected for processing (2)
  • internal/restapi/vehicles_for_agency_handler.go
  • internal/restapi/vehicles_for_agency_handler_test.go

Comment thread internal/restapi/vehicles_for_agency_handler_test.go Outdated
Update tests to parse the raw JSON message instead of decoding
directly into a struct. This prevents Go's boolean zero-value from
creating false-positive assertions when the field is omitted.
@sonarqubecloud

Copy link
Copy Markdown

@3rabiii 3rabiii requested a review from burma-shave June 28, 2026 21:29
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.

[spec-gap] vehicles-for-agency: outOfRange field missing from response envelope

1 participant