Skip to content

MA-685: Migrate Transit shuttle data feed to OneBusAway API - #2389

Open
a6wu wants to merge 68 commits into
experimentalfrom
ma-685-onebusaway
Open

a6wu wants to merge 68 commits into
experimentalfrom
ma-685-onebusaway

Conversation

@a6wu

@a6wu a6wu commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrates the Transit screen's shuttle data feed from the legacy campus shuttle API (per-stop endpoint map with OAuth2 bearer tokens and 401-token-retry) to the OneBusAway REST API (Jira MA-685).

  • New OneBusAwayClient (lib/core/services/one_bus_away_client.dart): reads the API endpoint and key from the ONE_BUS_AWAY_API / ONE_BUS_AWAY_API_KEY environment variables (with a --dart-define fallback for device builds). Values are never hardcoded, committed, or logged; all exceptions are sanitized so key-bearing request URLs cannot leak into logs or the UI.
  • Stops now come from GET /api/where/stops-for-agency/UCSD.json (one call returns all 69 campus shuttle stops, including off-campus Grocery-Convoy stops); arrivals from GET /api/where/arrivals-and-departures-for-stop/{stopId}.json, both with envelope validation.
  • UI contract unchanged: OBA responses map onto the existing ShuttleStopModel / ArrivingShuttle shapes — provider and Transit UI files needed zero changes.
  • Scope preserved: arrivals are filtered to the UCSD agency so the feature keeps its campus-shuttle-only behavior despite the multi-agency regional feed.
  • Graceful degradation: malformed entries are skipped, arrivals without usable times are dropped, missing route names/colors fall back to defaults.

Testing

  • flutter analyze --no-pub --no-fatal-warnings --no-fatal-infos (exact CI invocation): clean (exit 0; remaining repo infos/warnings are pre-existing baseline in untouched files)
  • flutter test --no-pub: 58/58 passed, including 36 new tests covering the client (mocked dio HTTP adapter, no live API), OBA response mapping, and service behavior
  • Live smoke check against the real API: 69 stops fetched, live arrivals rendered correctly with MTS/NCTD arrivals filtered out

Notes for reviewers

  1. Device builds: machine env vars are not propagated into iOS/Android app processes, so on-device runs need the --dart-define=ONE_BUS_AWAY_API=... / ONE_BUS_AWAY_API_KEY=... fallback path (values still never committed). If the team prefers a different injection channel (e.g. credential store → build pipeline), that can be layered on top.
  2. Persisted stop IDs: users who saved stops under the legacy feed will have stale IDs in their profile; unknown IDs are already skipped gracefully, but a one-time migration could be considered separately.

Refs: MA-685


Implemented by an AI agent session (opencode, model api-glm-5.3) in a Coder pilot workspace; commit carries the Generated by opencode (AI) attribution trailer. Agent commits locally; push + PR opened by the orchestrator (a6wu).

silkfiy and others added 30 commits October 10, 2026 15:04
@klortiz13

Copy link
Copy Markdown
Contributor

Need ONE_BUS_AWAY_API_KEY in .env file to test

@a6wu

a6wu commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@klortiz13 added to our password tool

- Read OneBusAway configuration from the app's .env file
- Coordinate overlapping startup fetches and reuse cached stop data
- Retry HTTP 429 responses with Retry-After support and bounded backoff
- Clear stale errors after successful refreshes
- Avoid duplicate arrival requests for selected closest stops
- Safely sort immutable service results
- Keep successful stops visible when another stop's arrivals fail
- Display empty arrival responses without a generic card error
- Allow card height and text to adapt to screen width and text scaling
- Fix spacing around unavailable-arrivals messages
- Show "Arriving Now" instead of "Arriving in: 0 minutes"
- Restore readable, working Reload and Hide menu options
- Improve JSON logging and sanitized API/parsing error messages
- Add service, provider, layout, arrival text, and menu regression tests
@klortiz13
klortiz13 changed the base branch from experimental to dev November 6, 2026 20:01
@klortiz13 klortiz13 self-assigned this Nov 6, 2026
@klortiz13

Copy link
Copy Markdown
Contributor

Fixed a lot of issues. To mention some, the data was not being parsed correctly, the frontend was not rendering the data, it was making unecessary calls to the API, and when I fixed all of the above, I got data overflows, and some of the error messages were not following our UI standards (alignment and spacing).

@klortiz13
klortiz13 changed the base branch from dev to experimental November 7, 2026 01:21
@klortiz13

klortiz13 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Changed the base back to experimental to trigger builds. This PR is now stable. The AI got this task 40-50% to completion. I had to intervene to get it to 100%. I am assuming heavy tasks like this one (where migration is involved) are not suitable for an automated AI system.

@klortiz13

Copy link
Copy Markdown
Contributor

TODO: Need to add the one bus away .env variables to code magic for the builds to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants