Skip to content

Refactor boolean parsing in trips-for-route - #1233

Open
3rabiii wants to merge 4 commits into
OneBusAway:mainfrom
3rabiii:fix-trips-for-route-gap5
Open

Refactor boolean parsing in trips-for-route#1233
3rabiii wants to merge 4 commits into
OneBusAway:mainfrom
3rabiii:fix-trips-for-route-gap5

Conversation

@3rabiii

@3rabiii 3rabiii commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes inconsistent boolean parameter parsing in the trips-for-route endpoint. Updates the handler to use strconv.ParseBool for all boolean query parameters (includeSchedule, includeStatus, includeTrip, and includeReferences). This ensures that invalid values correctly evaluate to false, while preserving the spec-required default of true when the parameters are completely omitted. This aligns the endpoint with the established pattern used in peer handlers (like trips-for-location).

Changes

  • internal/restapi/trips_for_route_handler.go: Replaced the legacy != "false" string comparison checks with a standardized strconv.ParseBool approach for all boolean flags.
  • internal/restapi/trips_for_route_handler_test.go: Added comprehensive table-driven tests to rigorously verify the parsing behavior across all scenarios (omitted/default, explicit true, explicit false, and invalid/junk values).

Closes: #1232

Summary by CodeRabbit

  • Bug Fixes

    • Improved boolean query parameter handling for the trips-for-route API.
    • Optional schedule, status, trip, and reference details now default to enabled when parameters are omitted.
    • Explicit false, empty, or invalid values consistently disable the corresponding details.
    • Trip responses now reliably include or omit schedule, status, trip, and reference information based on these parameters.
  • Tests

    • Added coverage for omitted, valid, false, empty, and invalid boolean parameter values.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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: 40 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4a5e3104-6f8d-4032-b3d2-4f3bed6b0efd

📥 Commits

Reviewing files that changed from the base of the PR and between 9fdf56b and 7267187.

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

Walkthrough

The trips-for-route handler now parses includeSchedule, includeStatus, includeTrip, and includeReferences consistently. Omitted values default to true; invalid, empty, and false values produce false. Table-driven tests verify parsing and response content.

Changes

Trips-for-route boolean parsing

Layer / File(s) Summary
Boolean parsing and validation
internal/restapi/trips_for_route_handler.go, internal/restapi/trips_for_route_handler_test.go
The handler uses parseBoolQueryParam for all four inclusion flags. Tests cover omitted, true, false, empty, and invalid values, plus the default-enabled behavior.

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

Possibly related PRs

Suggested reviewers: ahmedhossamdev, burma-shave

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the boolean parsing refactor for the trips-for-route endpoint.
Linked Issues check ✅ Passed The handler now defaults omitted parameters to true and parses invalid boolean values as false, as required by issue #1232.
Out of Scope Changes check ✅ Passed The changes are limited to boolean parsing in the trips-for-route handler and its corresponding tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 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 259-270: Extend the table-driven cases in the trips-for-route
handler tests to cover empty includeSchedule and includeStatus query values,
expecting both flags to be false, and add an independent includeStatus=true case
expecting status true. Keep the existing defaults and invalid-value cases
unchanged.

In `@internal/restapi/trips_for_route_handler.go`:
- Around line 30-37: Update the query-parameter parsing in the trip route
handler to independently read includeTrip and includeReferences, alongside
includeSchedule and includeStatus, with each defaulting to true and parsing
provided boolean values. Propagate the corresponding flags through
buildTripReferences so each parameter controls its own output behavior; do not
reuse includeSchedule for includeTrip.
- Around line 30-37: Update the includeSchedule and includeStatus
query-parameter handling in the trips-for-route handler to distinguish omitted
parameters from present-but-empty values. Apply the same
presence/check-before-parse behavior used by the trip-details implementation,
rejecting empty supplied values as invalid while preserving the default true
values when parameters are omitted.
🪄 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: 08fe1063-8ed6-493e-a2d9-9ebaf5c0985f

📥 Commits

Reviewing files that changed from the base of the PR and between e2a1eed and ca1c59a.

📒 Files selected for processing (2)
  • internal/restapi/trips_for_route_handler.go
  • internal/restapi/trips_for_route_handler_test.go

Comment thread internal/restapi/trips_for_route_handler_test.go Outdated
Comment thread internal/restapi/trips_for_route_handler.go Outdated
3rabiii added 3 commits August 2, 2026 04:37
Update includeSchedule and includeStatus to use strconv.ParseBool
instead of basic string comparison. This ensures invalid values
default to false while omitted values default to true, aligning
with the API spec and the behavior of peer handlers like
trips-for-location.

Comprehensive test cases are added to strictly verify the parsing
of omitted, valid, and invalid boolean query parameters.
Update boolean parsing in trips-for-route to use r.URL.Query().Has()
instead of checking for empty strings via Get(). This ensures that
explicitly provided but empty parameters (e.g., ?includeSchedule=)
are correctly parsed as invalid and evaluate to false, rather than
incorrectly falling back to the true default.

Additionally, add missing test cases highlighted in code review:
- Present-but-empty parameters expecting false
- Explicit success case for includeStatus=true
Extract boolean parsing logic into a shared parseBoolQueryParam helper
and apply it to includeSchedule, includeStatus, includeTrip, and
includeReferences.

This ensures omitted parameters correctly default to true, while present
but empty or invalid values safely evaluate to false, resolving
inconsistencies flagged in code review. Adds comprehensive matrix tests
for all scenarios.
@3rabiii
3rabiii force-pushed the fix-trips-for-route-gap5 branch from 76d6e83 to 9fdf56b Compare August 2, 2026 10:34
@3rabiii
3rabiii marked this pull request as ready for review August 2, 2026 10:39

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/restapi/trips_for_route_handler_test.go (1)

422-437: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the unused wantRefsPopulated field.

wantRefsPopulated is declared per test case but never read in the test body (Lines 448-461). Both subtests run identical assertions that expect empty references, regardless of the field's value. Since the handler builds references from an empty trip/stop set on this code path, references stay empty even when includeReferences=true, so the field cannot drive different expectations here. Remove the field, or add a one-line comment stating why it's always empty, so a future reader does not assume the test differentiates the two cases.

♻️ Proposed cleanup
 	tests := []struct {
 		name              string
 		includeReferences string
-		wantRefsPopulated bool
 	}{
 		{
-			name:              "Empty List - Include References Explicit",
-			includeReferences: "true",
-			wantRefsPopulated: true,
+			name:              "Empty List - Include References Explicit",
+			includeReferences: "true",
 		},
 		{
-			name:              "Empty List - Exclude References",
-			includeReferences: "false",
-			wantRefsPopulated: false,
+			name:              "Empty List - Exclude References",
+			includeReferences: "false",
 		},
 	}
🤖 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/trips_for_route_handler_test.go` around lines 422 - 437,
Remove the unused wantRefsPopulated field from the test case struct and both
test entries in the table-driven test. Keep the existing subtest inputs and
identical empty-reference assertions unchanged.
🤖 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.

Outside diff comments:
In `@internal/restapi/trips_for_route_handler_test.go`:
- Around line 422-437: Remove the unused wantRefsPopulated field from the test
case struct and both test entries in the table-driven test. Keep the existing
subtest inputs and identical empty-reference assertions unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 73c0b700-9b66-43f9-92b1-32554883c1bc

📥 Commits

Reviewing files that changed from the base of the PR and between ca1c59a and 9fdf56b.

📒 Files selected for processing (2)
  • internal/restapi/trips_for_route_handler.go
  • internal/restapi/trips_for_route_handler_test.go

Clean up TestTripsForRouteHandler_ReferencesInclusion_EmptyList by
removing the wantRefsPopulated field. It was declared but never
evaluated since references are always empty on this path.
@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

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.

Boolean parameters use inconsistent parsing in trips-for-route

1 participant