Skip to content

Fix trip references when includeTrip is false#1101

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

Fix trip references when includeTrip is false#1101
3rabiii wants to merge 2 commits into
OneBusAway:mainfrom
3rabiii:fix-trip-details_issue_9

Conversation

@3rabiii

@3rabiii 3rabiii commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the trip-details endpoint so that includeTrip=false correctly
omits the main trip from references.trips while preserving the
preceding and following block trips (when includeSchedule=true), as
required by OneBusAway spec Extension 4c.

Problem

In tripDetailsHandler, the logic to resolve preceding/following
block trips was nested entirely inside the if params.IncludeTrip
block. As a result, requesting includeTrip=false skipped the whole
reference-resolution path and produced an empty references.trips
array, even when includeSchedule=true.

Changes

  • Add the main trip ID to tripsToInclude only when includeTrip=true.
  • Always append next/previous trips (when includeSchedule=true) and
    the active trip (when includeStatus=true), regardless of the
    includeTrip value.
  • Update TestTripDetailsHandlerWithIncludeTrip to assert the main
    trip is excluded rather than expecting an empty list.
  • Add TestTripDetailsHandlerIncludeTripFalseKeepsBlockTrips to verify
    block trips are still referenced when includeTrip=false.

Closes: #1087

Summary by CodeRabbit

  • Bug Fixes
    • Trip references from schedule and status data are now correctly included in responses, even when the main trip is excluded. This ensures more consistent and complete trip information availability based on your query parameters and available data.

Per the OneBusAway spec (Extension 4c), setting includeTrip=false
should omit only the main trip record from references.trips, while
still including the preceding and following block trips when
includeSchedule=true.

Previously the entire reference-resolution block was nested inside
the if params.IncludeTrip condition, so disabling includeTrip
skipped block-trip resolution entirely and returned an empty
references.trips array.

Move the main trip ID into tripsToInclude only when includeTrip is
true, while always appending the next, previous, and active trips
based on includeSchedule and includeStatus. Update and add tests to
verify block trips remain referenced while the main trip is omitted.
@coderabbitai

coderabbitai Bot commented Jun 21, 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 35 minutes and 43 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 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: 65294f0d-0216-4bf2-ac71-9aafed5e7f5d

📥 Commits

Reviewing files that changed from the base of the PR and between afdcd90 and 93b52d8.

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

Walkthrough

tripDetailsHandler is refactored so that tripsToInclude is built independently of IncludeTrip: schedule-derived preceding/next trip IDs and status-derived active trip IDs are now appended based on their own flags, and buildReferencedTrips is called whenever any IDs were collected. Existing tests and a new test validate the corrected behavior.

Changes

Referenced Trip Aggregation Fix

Layer / File(s) Summary
Decouple tripsToInclude from IncludeTrip gate
internal/restapi/trip_details_handler.go
tripsToInclude is initialized as an empty slice and conditionally extended by IncludeTrip, IncludeSchedule, and IncludeStatus flags independently. buildReferencedTrips is now called whenever the slice is non-empty rather than only when IncludeTrip=true.
Updated and new tests for includeTrip=false behavior
internal/restapi/trip_details_handler_test.go
TestTripDetailsHandlerWithIncludeTrip now asserts the main tripID is absent from references rather than expecting an empty list. New TestTripDetailsHandlerIncludeTripFalseKeepsBlockTrips compares includeTrip=true vs includeTrip=false (with includeSchedule=true) and asserts that non-main block trip IDs are present in both responses.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • OneBusAway/maglev#1068: Modifies the same trip_details_handler.go referenced-trips logic, gating buildReferencedTrips calls under the includeReferences flag — directly adjacent to the code path changed in this PR.

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 accurately summarizes the main change: fixing trip references when includeTrip is false, which is the core issue addressed in the PR.
Linked Issues check ✅ Passed The PR fully addresses issue #1087 by restructuring reference resolution logic to include block trips regardless of includeTrip setting while conditionally excluding the main trip.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the trip references behavior when includeTrip is false, with no unrelated modifications detected.

✏️ 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.

🧹 Nitpick comments (1)
internal/restapi/trip_details_handler_test.go (1)

174-192: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Consider asserting that test data includes block trips to prevent vacuous pass.

If the test fixture returned by mustGetTrip has no preceding/following trips, expectedBlockTrips will be empty and the final for loop (lines 189-192) won't execute any assertions. The test would pass without actually verifying the fix.

💡 Suggested assertion
 	for _, refTrip := range withTrip.Data.References.Trips {
 		if refTrip.ID != tripID {
 			expectedBlockTrips[refTrip.ID] = true
 		}
 	}
+
+	// Ensure test data actually has block trips to verify.
+	assert.NotEmpty(t, expectedBlockTrips,
+		"test fixture should include preceding/following trips to meaningfully test this behavior")
🤖 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/restapi/trip_details_handler_test.go` around lines 174 - 192, The
test could pass vacuously if the test fixture from mustGetTrip contains no block
trips, since expectedBlockTrips would be empty and the final for loop validating
block trips would not execute any assertions. Add an assertion after building
expectedBlockTrips to verify it is not empty, ensuring the test fixture actually
contains block trips and the test is meaningful.
🤖 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/restapi/trip_details_handler_test.go`:
- Around line 174-192: The test could pass vacuously if the test fixture from
mustGetTrip contains no block trips, since expectedBlockTrips would be empty and
the final for loop validating block trips would not execute any assertions. Add
an assertion after building expectedBlockTrips to verify it is not empty,
ensuring the test fixture actually contains block trips and the test is
meaningful.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 27a08dcb-112f-4c2b-be6e-9a2a797dc979

📥 Commits

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

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

Add an assertion to ensure expectedBlockTrips is not empty. This prevents a vacuous pass if the test fixture lacks preceding or following trips.
@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: preceding and following trips are missing from references when includeTrip=false

1 participant