Skip to content

fix: Only merge activities on computed parent station informed entities, not original child stop informed entities#974

Open
jzimbel-mbta wants to merge 4 commits intomasterfrom
jz-fix-alert-informed-entity-activities
Open

fix: Only merge activities on computed parent station informed entities, not original child stop informed entities#974
jzimbel-mbta wants to merge 4 commits intomasterfrom
jz-fix-alert-informed-entity-activities

Conversation

@jzimbel-mbta
Copy link
Member

Summary of changes

Asana Ticket: 🍎Alert informed entities should have activities as specified in the API

Overall summary of the change: the activities-merging logic is now applied exclusively to computed informed entities for parent stations, ensuring that the original informed entities are preserved.

I added a bunch of tests for this complex logic to be sure I didn't cause any other unintended changes in behavior.

Results of running the new tests against current main branch, without this change:
$ mix test apps/state/test/state/alert/hooks_test.exs
==> state
Running ExUnit with seed: 330364, max_cases: 22

.

  1) test pre_insert_hook/1 handles specific case from bugfix ticket (State.Alert.HooksTest)
     apps/state/test/state/alert/hooks_test.exs:353
     match (=) failed
     The following variables were pinned:
       informed_entities = [%{stop: "WR-0045-S", route: "CR-Haverhill", direction_id: 0, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]}, %{stop: "WR-0045-S", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]}, %{stop: "BNT-0000", route: "CR-Haverhill", direction_id: 0, route_type: 2, activities: ["BOARD", "RIDE"]}, %{stop: "WR-0053-S", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["BOARD", "RIDE"]}, %{stop: "WR-0053-S", route: "CR-Haverhill", direction_id: 0, route_type: 2, activities: ["EXIT", "RIDE"]}, %{stop: "BNT-0000", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["EXIT", "RIDE"]}]
       expected_new_informed_entities = [%{stop: "place-mlmnl", route: "CR-Haverhill", direction_id: 0, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]}, %{stop: "place-north", route: "CR-Haverhill", direction_id: 0, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]}, %{stop: "place-ogmnl", route: "CR-Haverhill", direction_id: 0, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]}, %{stop: "place-mlmnl", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]}, %{stop: "place-north", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]}, %{stop: "place-ogmnl", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]}]
     code:  assert %{preserved: ^informed_entities, added: ^expected_new_informed_entities} =
              get_computed_informed_entities(alert)
     left:  %{added: ^expected_new_informed_entities, preserved: ^informed_entities}
     right: %{
              added: [
                %{stop: "BNT-0000", route: "CR-Haverhill", direction_id: 0, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]},
                %{stop: "WR-0053-S", route: "CR-Haverhill", direction_id: 0, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]},
                %{activities: ["BOARD", "EXIT", "RIDE"], direction_id: 0, route: "CR-Haverhill", route_type: 2, stop: "place-mlmnl"},
                %{activities: ["BOARD", "EXIT", "RIDE"], direction_id: 0, route: "CR-Haverhill", route_type: 2, stop: "place-north"},
                %{activities: ["BOARD", "EXIT", "RIDE"], direction_id: 0, route: "CR-Haverhill", route_type: 2, stop: "place-ogmnl"},
                %{activities: ["BOARD", "EXIT", "RIDE"], direction_id: 1, route: "CR-Haverhill", route_type: 2, stop: "BNT-0000"},
                %{stop: "WR-0053-S", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]},
                %{stop: "place-mlmnl", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]},
                %{stop: "place-north", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]},
                %{stop: "place-ogmnl", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["BOARD", "EXIT", "RIDE"]}
              ],
              preserved: [
                %{activities: ["BOARD", "EXIT", "RIDE"], direction_id: 0, route: "CR-Haverhill", route_type: 2, stop: "WR-0045-S"},
                %{activities: ["BOARD", "EXIT", "RIDE"], direction_id: 1, route: "CR-Haverhill", route_type: 2, stop: "WR-0045-S"}
              ],
              removed: [%{stop: "BNT-0000", route: "CR-Haverhill", direction_id: 0, route_type: 2, activities: ["BOARD", "RIDE"]}, %{stop: "WR-0053-S", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["BOARD", "RIDE"]}, %{stop: "WR-0053-S", route: "CR-Haverhill", direction_id: 0, route_type: 2, activities: ["EXIT", "RIDE"]}, %{stop: "BNT-0000", route: "CR-Haverhill", direction_id: 1, route_type: 2, activities: ["EXIT", "RIDE"]}]
            }
     stacktrace:
       test/state/alert/hooks_test.exs:413: (test)

...
Finished in 0.1 seconds (0.00s async, 0.1s sync)
5 tests, 1 failure

@jzimbel-mbta jzimbel-mbta requested a review from a team as a code owner March 6, 2026 19:40
@jzimbel-mbta jzimbel-mbta requested review from a team, firestack and npatel-mbta and removed request for a team and firestack March 6, 2026 19:40
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.

1 participant