fix: register missing Situation endpoint route (#798) - #804
fix: register missing Situation endpoint route (#798)#804tejasva-vardhan wants to merge 3 commits into
Conversation
|
@aaronbrethorst @Ahmedhossamdev would love any review on this! |
|
@aaronbrethorst @fletcherw @Ahmedhossamdev @burma-shave would love any review on this!! |
Code reviewFound 2 issues:
maglev/internal/gtfs/realtime.go Lines 213 to 215 in c9cfa01 maglev/internal/restapi/situation_handler_test.go Lines 44 to 46 in c9cfa01
maglev/internal/restapi/situation_handler.go Lines 32 to 38 in c9cfa01 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
aaronbrethorst
left a comment
There was a problem hiding this comment.
Thanks for this, and sorry it sat for so long — that's on us, not you. The endpoint design is right: the handler shape matches our other simple-ID real-time endpoints, extractAndValidateID handles the .json suffix the way the rest of the API does, and putting GetAllAlerts on the manager with dedup-by-ID across feeds under the read lock is the correct place for that logic.
The blocker is that the branch has gone stale, and in a way that GitHub is actively hiding from us. The PR shows as mergeable with green checks, but those checks ran on 2026-03-28 against a main that no longer exists. There's no textual conflict, so nothing flags it — but merging as-is breaks the build in two places:
1. sort is no longer imported in internal/gtfs/realtime.go.
GetAllAlerts calls sort.Strings(feedIDs). Since this branch was opened, #809 ("refactor: replace sort package with slices") removed the sort import from that file — main now uses slices.Sort throughout (three call sites). Because your diff only adds a function body and doesn't touch the import block, the merge result is a file that calls sort.Strings with no sort import: undefined: sort.
Swap it for slices.Sort(feedIDs) to match the surrounding code.
2. AddTestAlert no longer exists.
situation_handler_test.go calls api.GtfsManager.AddTestAlert(alert). On main that helper is named AddAlertForTest (internal/gtfs/gtfs_manager.go:819); AddTestAlert isn't defined anywhere in the repo now. Renaming the call is the whole fix.
A rebase onto main plus those two changes should get CI running against reality again.
Two smaller things while you're in there:
- The
len(situations) == 0guard insituationHandleris unreachable.BuildSituationReferencesappends exactly oneSituationper input alert unconditionally, so a one-element input always yields one element. It's dead code and it's the one branch with no test — I'd just drop it. TestSituationHandlerWithSituationbuilds the alert withHeaderandDescriptionbut only asserts onid,reason, andseverity. The translated-string fields are the ones most likely to regress silently; assertingsummaryanddescriptionwould make the test earn its keep.
One note that isn't about your code: issue #798 claims the handler and tests already existed and just needed wiring up. That isn't true of main — neither situation_handler.go nor its test exists there, and this PR creates both. So this is a new endpoint implementation, not a one-line route registration. Worth knowing since it means there's no prior art to match, and also worth flagging that we have no spec for this endpoint: it isn't in the maglev wiki, it isn't in testdata/openapi.yml, and the docs repo only describes situation as a referenced element, not a standalone method. I'm comfortable with the envelope you chose, but if you have a reference response from a production OBA server, that'd be good to capture.
Related: references is always empty here, even though a situation's allAffects can carry agency/route/stop/trip IDs that a client would want resolved. Not a blocker given there's no spec to point at, but worth a thought.
Rebase and fix the two build breaks and I'll take another look promptly.
Use slices.Sort and AddAlertForTest so the branch compiles against current main. Drop the unreachable empty-situation guard and assert summary and description on the handler test.
c9cfa01 to
f20054e
Compare
|
Warning Review limit reached
Next review available in: 12 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
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. Comment |
|
@aaronbrethorst
|
Tests share one GTFS manager, and route-handler tests already seed test-alert-123. GetAllAlerts keeps the first ID, so the situation test was asserting against the wrong alert. Co-authored-by: Cursor <cursoragent@cursor.com>
|



Overview
This PR resolves #798 by properly registering the
GET /api/where/situation/{id}route in the REST API. While the handler logic was present, it was not wired to the router, causing a 404/HTML fallback when requesting real-time service alerts.Changes
internal/restapi/routes.go.situationHandlerto correctly fetch and format service alerts usingapi.extractAndValidateID.GetAllAlerts()ininternal/gtfs/realtime.goto provide access to the in-memory GTFS-RT alert store.internal/restapi/situation_handler_test.go(verified withgo test).Verification (Before vs After)
To ensure full parity with the legacy OBA Java API, I verified the fix using both the
maglev-validatorand manual browser testing.1. Maglev Validator Comparison
Local Maglev (
localhost:4000) vs Production Java API (api.pugetsound.onebusaway.org).2. Browser Manual Testing
Endpoint:
/api/where/situation/1_84714.json?key=testNote for Reviewers: - Only core logic files for the fix are included in this PR.
modernc.org/sqlite) and local performance bypasses were intentionally excluded to maintain upstream standards.