Skip to content

Honor latSpan and lonSpan in routes-for-location - #1275

Open
ARCoder181105 wants to merge 2 commits into
OneBusAway:mainfrom
ARCoder181105:fix/routes-for-location-span-ignored
Open

Honor latSpan and lonSpan in routes-for-location#1275
ARCoder181105 wants to merge 2 commits into
OneBusAway:mainfrom
ARCoder181105:fix/routes-for-location-span-ignored

Conversation

@ARCoder181105

@ARCoder181105 ARCoder181105 commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1226

routes-for-location accepted latSpan/lonSpan, then ignored them , a 10km × 10km box request got a 600m box.

BoundsFromParams sizes the box from the spans only when no radius is set. The handler assigned the default radius before calling it, so the span branch was unreachable.

Change

Apply the default radius only when neither a radius nor a usable pair of spans was supplied.

Guard is Radius == 0 && !(LatSpan > 0 && LonSpan > 0), not the LatSpan == 0 && LonSpan == 0 the issue specifies. With one span plus a query, the literal version leaves Radius at 0 and BoundsFromParams falls back to 600m instead of the specced 10km — its fallback isn't query-aware.

Tests

Replaced TestRoutesForLocationLatSpanAndLonSpan with a table-driven TestRoutesForLocationBoundingBoxSizing. The old test used a 0.01° box, near-identical to the default-radius box at the fixture latitude, so it passed whether or not spans were honoured.

Four cases, each returning a different result than the default box: spans widening the box, spans narrowing it, radius taking precedence over spans, and a lone latSpan falling back to the 10km query radius.

Summary by CodeRabbit

  • Bug Fixes

    • Improved location-based route searches by sanitizing query input.
    • Corrected radius selection when latitude and longitude bounds are provided.
    • Improved fallback behavior when only one bounding-box span is specified.
  • Tests

    • Expanded coverage for bounding-box sizing, radius precedence, and default-radius behavior.

The handler assigned a default radius to LocationParams whenever no radius
was supplied, before passing the params to BoundsFromParams. That helper
sizes the box from latSpan/lonSpan only when no radius is set, so the
pre-filled default meant the span branch was never reached and any
latSpan/lonSpan a client sent was silently discarded.

Apply the default radius only when neither a radius nor a usable pair of
spans was supplied. The predicate mirrors the one in BoundsFromParams:
both spans must be positive, since a single span leaves the box unsized
and must still fall back to the query-aware default radius.
The previous span test requested a 0.01 degree box, which at the fixture
latitude is close enough to the default radius box that both returned the
same single route. It passed whether or not the spans were honored, which
is why the gap went unnoticed.

Replace it with a table covering the three sizing rules from the spec:
spans widening and narrowing the box relative to the default radius, and
radius taking precedence when both are supplied. Add a case for a lone
latSpan, which must still fall back to the 10km query radius rather than
the 600m one.

Each case is built to return a different result than the default box, so
it fails if the spans are ignored. A fresh API per subtest avoids the
shared key's rate limit, and results are filtered to the RABA agency
because other tests leave synthetic agencies in the shared test database.
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9c638abb-7c63-4114-9b0a-290f85643136

📥 Commits

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

📒 Files selected for processing (2)
  • internal/restapi/routes_for_location_handler.go
  • internal/restapi/routes_for_location_handler_test.go

📝 Walkthrough

Walkthrough

The routes-for-location handler now sanitizes queries and preserves provided positive latitude and longitude spans instead of applying a default radius. Table-driven tests cover bounding-box sizing, radius precedence, and query-aware fallback behavior.

Changes

Location bounds

Layer / File(s) Summary
Span-aware radius selection
internal/restapi/routes_for_location_handler.go
The handler sanitizes query and applies the default radius only when radius, latSpan, and lonSpan are all unset.
Bounding-box sizing coverage
internal/restapi/routes_for_location_handler_test.go
Table-driven tests validate span widening, span narrowing, radius precedence, and query-aware default-radius fallback using expected route IDs.

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

Possibly related issues

Possibly related PRs

Suggested reviewers: fletcherw

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The query sanitization change is not covered by the linked issue or stated objectives. Remove the unrelated query sanitization change or link a separate issue that requires it.
✅ 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 describes the main change: honoring latSpan and lonSpan in routes-for-location.
Linked Issues check ✅ Passed The handler honors positive latSpan and lonSpan values, preserves radius precedence, and applies fallback behavior required by [#1226].
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.

@sonarqubecloud

sonarqubecloud Bot commented Aug 1, 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.

routes-for-location: Bounding box spans are ignored when radius is omitted

2 participants