Skip to content

search-route: complete test coverage and spec verification - #1284

Open
ARCoder181105 wants to merge 4 commits into
OneBusAway:mainfrom
ARCoder181105:search-route-spec-coverage
Open

search-route: complete test coverage and spec verification#1284
ARCoder181105 wants to merge 4 commits into
OneBusAway:mainfrom
ARCoder181105:search-route-spec-coverage

Conversation

@ARCoder181105

@ARCoder181105 ARCoder181105 commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Completes the search-route endpoint review against the wiki spec. The endpoint's behavior was already correct — this fills in the missing test coverage and cleans up two small inconsistencies found along the way.

Tests added

  • maxCount validation: 0, non-numeric, and missing input entirely all return 400
  • limitExceeded asserted in both directions
  • Response envelope: version, currentTime, empty references.routes, outOfRange
  • Context cancellation, using a past deadline so it asserts an exact 504 with no timing race

Cleanup

  • routeSearchHandler now uses nulls.StringOrEmpty instead of hand-rolled sql.NullString unwrapping, matching every other route-building handler
  • Folded the redundant TestRouteSearchHandlerMaxCountBoundaries into the new table-driven maxCount test
  • Fixed a doc comment claiming lat/lon/radius filtering the handler never had

No behavior changes.

Notes

The "404 on no results" case from #1202 is deliberately skipped. #1197 closed by updating the spec: returning 200 with an empty list is maglev's intended deviation from legacy, matching search/stop. Adding the 404 would be a regression.

Two things left for the reviewer to decide, both out of scope here:

  • routes_fts indexes id, agency_id, short_name, long_name, desc, while the legacy Java index only covers route_long_name (falling back to the combined id when null) — so maglev matches a superset, e.g. routes hit only via route_desc.
  • searchStopsHandler has the same incorrect geo-filtering doc comment; it belongs to the search-stop card.

Closes #1202.

Test plan

  • go vet -tags "sqlite_fts5 sqlite_math_functions" ./...
  • go vet -tags "purego" ./...
  • make test
  • go fmt ./...

Summary by CodeRabbit

  • Bug Fixes

    • Improved route-search results so missing optional route fields are returned consistently as empty values.
    • Enhanced validation for result-count limits, including boundary cases and invalid inputs.
    • Corrected limit-status reporting for truncated and complete result sets.
  • Tests

    • Expanded coverage for response metadata, missing inputs, rate limiting, not-found responses, and request cancellation.

routeSearchHandler hand-rolled six sql.NullString unwraps instead of
using internal/nulls, the pattern every other route-building handler
follows (routes_for_agency_handler.go, routes_for_location_handler.go,
etc). No behavior change.
Covers gaps against the search-route wiki spec: maxCount validation
(0, non-numeric, missing input entirely all return 400),
limitExceeded=false, response envelope fields (version, currentTime,
empty references.routes), and a search-route row in the shared
context-cancellation table. Folds the now-redundant
TestRouteSearchHandlerMaxCountBoundaries into the new table-driven
maxCount test.

A no-match query returning 200 with an empty list is intentional and
left untouched: the wiki spec documents this as maglev's deliberate
deviation from the legacy 404 behavior, matching search/stop.
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The route-search handler now uses nulls.StringOrEmpty for nullable route fields. Tests expand coverage for response metadata, parameter validation, result limits, and context cancellation responses.

Changes

Route search validation

Layer / File(s) Summary
Nullable route field conversion
internal/restapi/route_search_handler.go
Route result construction converts nullable route fields to empty strings with nulls.StringOrEmpty.
Route search behavior tests
internal/restapi/route_search_handler_test.go, internal/restapi/context_cancellation_test.go
Tests cover response metadata, missing and invalid parameters, maxCount boundaries, limitExceeded states, and route-search cancellation responses.

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

Possibly related issues

Possibly related PRs

Suggested labels: LGTM

Suggested reviewers: ahmedhossamdev, burma-shave

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR omits required no-result, includeReferences=false, and deterministic route and agency ordering coverage from issue #1202. Add the missing tests, or update issue #1202 to document and approve the intentional deviations from its acceptance criteria.
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 (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed All code and test changes support the search-route coverage and specification-verification objectives.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary changes to search-route test coverage and specification verification.

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: 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/context_cancellation_test.go`:
- Around line 84-95: Add a route-search-specific test using an already-canceled
request context, and configure the test request or API setup to bypass the rate
limiter. Invoke routeSearchHandler directly and assert its deterministic
cancellation response status instead of accepting generic 200, 429, or 500
outcomes in the existing test.
🪄 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: e3fcfc6f-1635-4a42-939d-d71719c86d7d

📥 Commits

Reviewing files that changed from the base of the PR and between 3b73fd9 and 67d8e4d.

📒 Files selected for processing (3)
  • internal/restapi/context_cancellation_test.go
  • internal/restapi/route_search_handler.go
  • internal/restapi/route_search_handler_test.go

Comment thread internal/restapi/context_cancellation_test.go Outdated
The shared context-cancellation table used a 1ns timeout and a loose
multi-status assertion, and adding a search-route row to it meant
weakening that shared assertion to accept 429 just to cover the
rate-limiter budget spent by five earlier rows in the same test.

Revert that addition and instead give search-route its own
cancellation test using a past deadline, matching the existing
TestBlockHandlerContextCancellation pattern: deterministic
DeadlineExceeded with no timer-resolution race, exact 504 assertion,
own rate-limit budget.
data.outOfRange is hardcoded false for search-route per spec (no
geographic bounding), but no test checked it. Also the handler's doc
comment claimed optional lat/lon/radius filtering that the handler
never implemented — leftover from a copy-paste, corrected to describe
what the handler actually does.
@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

@Ahmedhossamdev Ahmedhossamdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

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.

search-route: complete test coverage and spec verification

2 participants