Skip to content

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

Open
3rabiii wants to merge 4 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 4 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 the trip-details API to omit the status field entirely when no vehicle tracking data is available (instead of returning an untracked placeholder).
    • Added/updated coverage to ensure the endpoint doesn’t include status in the raw JSON response when tracking is missing, and added unit tests for the untracked status detection logic.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 80be301d-76f2-484d-9708-b2bcad69b60d

📥 Commits

Reviewing files that changed from the base of the PR and between ba314e7 and 72b51d4.

📒 Files selected for processing (2)
  • internal/models/trip_details.go
  • internal/models/trip_details_test.go
📝 Walkthrough

Walkthrough

Trip-details now omits status when BuildTripStatus returns the default untracked placeholder. The model adds a predicate for that state, the handler uses it to clear the field, and tests cover both omission and presence cases.

Changes

Status omission fix and coverage

Layer / File(s) Summary
Add untracked status predicate
internal/models/trip_details.go, internal/models/trip_details_test.go
TripStatus gains IsUntracked(), and unit tests cover default, predicted, non-default, and active tracking cases.
Omit placeholder status in tripDetailsHandler
internal/restapi/trip_details_handler.go
tripDetailsHandler sets status = nil when BuildTripStatus returns the default untracked placeholder.
Assert omission and presence in endpoint tests
internal/restapi/trip_details_handler_test.go, internal/restapi/servicedate_timezone_regression_test.go
Adds an end-to-end test for absent entry.status with no tracking, and updates the block-trip-sequence regression to ensure status is present before reading blockTripSequence.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • OneBusAway/maglev#913: Related trip_details_handler_test.go assertions around the optional entry.status field and exact JSON absence.
  • OneBusAway/maglev#1061: Touches the same tripDetailsHandler/BuildTripStatus path.

Suggested reviewers: burma-shave, Ahmedhossamdev

🚥 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 clearly summarizes the main change: omitting the trip-details status key when tracking is absent.
Linked Issues check ✅ Passed The handler now nulls untracked TripStatus, and tests verify the status key is omitted when no tracking exists.
Out of Scope Changes check ✅ Passed The extra regression test update is supporting the fix, and the rest of the changes stay within the linked issue's scope.
✨ 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/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
@3rabiii 3rabiii requested a review from burma-shave June 21, 2026 19:21
Comment thread internal/restapi/trip_details_handler.go Outdated
Extracts the inline condition for untracked vehicles into a
dedicated TripStatus method per PR review. This improves handler
readability and includes tests to verify the logic.

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

🧹 Nitpick comments (1)
internal/models/trip_details.go (1)

69-74: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting the "default" sentinel into a shared constant.

IsUntracked() couples to the placeholder marker via a magic string literal that must also be set verbatim in BuildTripStatus (per PR description). If either side's literal drifts (typo, refactor), the omission logic silently breaks and status reappears in responses without any compile-time signal.

♻️ Proposed refactor
+const defaultTripStatusValue = "default"
+
+func (ts *TripStatus) IsUntracked() bool {
+	return ts.Status == defaultTripStatusValue && !ts.Predicted
+}
-func (ts *TripStatus) IsUntracked() bool {
-	return ts.Status == "default" && !ts.Predicted
-}

And use defaultTripStatusValue wherever BuildTripStatus sets the placeholder Status.

🤖 Prompt for 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.

In `@internal/models/trip_details.go` around lines 69 - 74, Extract the "default"
placeholder value into a shared constant and use it in both
TripStatus.IsUntracked and BuildTripStatus so the sentinel stays consistent.
Update IsUntracked() to compare against that constant instead of a magic string,
and make BuildTripStatus assign the same shared value when creating the
placeholder status.
🤖 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.

Nitpick comments:
In `@internal/models/trip_details.go`:
- Around line 69-74: Extract the "default" placeholder value into a shared
constant and use it in both TripStatus.IsUntracked and BuildTripStatus so the
sentinel stays consistent. Update IsUntracked() to compare against that constant
instead of a magic string, and make BuildTripStatus assign the same shared value
when creating the placeholder status.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c135262b-6061-4647-949f-f61f25f98089

📥 Commits

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

📒 Files selected for processing (4)
  • internal/models/trip_details.go
  • internal/models/trip_details_test.go
  • internal/restapi/trip_details_handler.go
  • internal/restapi/trip_details_handler_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/restapi/trip_details_handler.go
  • internal/restapi/trip_details_handler_test.go

Replaces the magic string 'default' with a shared constant to prevent silent breakage from typos across IsUntracked and BuildTripStatus.
@sonarqubecloud

sonarqubecloud Bot commented Jul 2, 2026

Copy link
Copy Markdown

@3rabiii 3rabiii requested a review from burma-shave July 2, 2026 20:59
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

2 participants