Skip to content

fix(trip-details): omit status key when tracking is absent#1100

Open
3rabiii wants to merge 2 commits into
OneBusAway:mainfrom
3rabiii:fix-trip-details_issue_8
Open

fix(trip-details): omit status key when tracking is absent#1100
3rabiii wants to merge 2 commits into
OneBusAway:mainfrom
3rabiii:fix-trip-details_issue_8

Conversation

@3rabiii

@3rabiii 3rabiii commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR addresses Extension 4e of the trip-details specification, which requires the status key to be entirely absent from the response if the block has no current tracking record.

Previously, BuildTripStatus returned a default non-nil placeholder (Status="default", Predicted=false) when no vehicle was tracked, which prevented the omitempty JSON tag from dropping the field.

Changes made:

  • Explicitly set the status pointer to nil in tripDetailsHandler when the returned status is just the default placeholder.
  • Added TestTripDetailsHandlerStatusOmittedWhenNoTracking to explicitly verify compliance with Extension 4e.
  • Updated TestServiceDateTimezoneRegression_BlockTripSequence to inject a mock vehicle, ensuring the timezone calculation still has valid tracking data to test against.

Closes: #1086

Summary by CodeRabbit

  • Bug Fixes
    • Fixed trip-details API response to properly omit status information when real-time vehicle tracking data is unavailable.

@coderabbitai

coderabbitai Bot commented Jun 20, 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 24 minutes and 1 second. 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 refill rate.

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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

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: 390040f8-a8d5-4f41-b306-0bf478a98f5a

📥 Commits

Reviewing files that changed from the base of the PR and between 8ef204b and dd89155.

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

Walkthrough

The tripDetailsHandler now sets status to nil when BuildTripStatus returns a default, non-predicted placeholder, ensuring omitempty suppresses the status field in the JSON response when no real-time tracking exists. Tests are added and updated to cover both the omission path and the case where tracking data is present.

Changes

Status Omission Fix and Test Coverage

Layer / File(s) Summary
Nil out default-placeholder status in handler
internal/restapi/trip_details_handler.go
After BuildTripStatus, checks if the returned status has Status == "default" and Predicted == false; if so, forces status = nil so the omitempty tag correctly omits it from the serialized TripDetails response.
Tests for omission and status-present regression
internal/restapi/trip_details_handler_test.go, internal/restapi/servicedate_timezone_regression_test.go
Adds TestTripDetailsHandlerStatusOmittedWhenNoTracking asserting Entry.Status is nil when no tracking data exists. Updates TestServiceDateTimezoneRegression_BlockTripSequence to mock a vehicle for TripID2 and assert the status field is present before accessing blockTripSequence.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • OneBusAway/maglev#913: Updates trip_details_handler_test.go assertions around the optional entry.status field in TripDetailsResponse, directly related to this PR's status-omission behavior.
  • OneBusAway/maglev#1061: Modifies tripDetailsHandler's BuildTripStatus path (changing the vehicle passed in), touching the same code area as this fix.

Suggested reviewers

  • burma-shave
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: omitting the status key when tracking is absent, which aligns with the primary objective.
Linked Issues check ✅ Passed The code changes fully address the linked issue #1086 by setting status to nil when it is a default placeholder, ensuring the omitempty tag removes it from JSON.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the status field omission issue: handler logic fix, test updates, and new test for verification.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@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/trip_details_handler_test.go`:
- Around line 199-201: The current assertion using
`assert.Nil(model.Data.Entry.Status)` only checks if the unmarshaled Status
field is nil, but this will incorrectly pass when the JSON response contains
`"status": null`. For Extension 4e compliance, verify that the "status" key is
completely absent from the raw JSON response at the map level (the decoded
payload before unmarshaling into the model struct), not just that the field is
nil after unmarshaling. Modify the assertion to check the raw map representation
to confirm the "status" key does not exist in data.entry.
🪄 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: 3a58cec5-8ea9-4202-9503-5ae752d85c26

📥 Commits

Reviewing files that changed from the base of the PR and between 99e138d and 8ef204b.

📒 Files selected for processing (3)
  • internal/restapi/servicedate_timezone_regression_test.go
  • internal/restapi/trip_details_handler.go
  • internal/restapi/trip_details_handler_test.go

Comment thread internal/restapi/trip_details_handler_test.go
@sonarqubecloud

Copy link
Copy Markdown

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

trip-details: status key is present when block has no current tracking record

1 participant