fix(ipaws): route county-only CAP alerts + auto-refresh toggles live (#159)

County-only civil CAP alerts (SAME geocode, no <polygon>) had no geometry, so
the geometry-based region tagger could not place them: no region -> no
region_routes match -> silently not broadcast. Many CEMs / 911 outages / some
AMBER alerts are county-only.

- Bundle work/meshai/county_centroids.py: Census 2023 national county gazetteer
  internal points (3,222 counties + DC/territories), FIPS->(lat,lon), with
  SAME PSSCCC -> 5-digit FIPS helpers.
- env/ipaws.py: when a CAP alert has SAME geocode(s) but NO polygon, set a Point
  (single county) or MultiPoint (multi-county) geometry from the county
  centroid(s) so the EXISTING coverage/region tagger locates it and tags ALL
  matching regions. Real polygon geometry always wins (never overridden).
- dashboard/server.py: call register_config_routes_hooks(app) in create_app so
  the toggle auto-refresh middleware is actually wired in prod (was test-only);
  saving a family toggle now takes effect live without POST
  /api/notifications/refresh-toggles.

Tests: county-only alert tags SW Idaho + matches emergency route cell;
multi-county tags all regions; polygon path unchanged; create_app wires the
refresh middleware; panhandle coverage-gap documented.

Co-authored-by: Matt Johnson <mj@k7zvx.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
malice 2026-07-17 12:08:29 -06:00 committed by GitHub
commit 8460ab50e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 3574 additions and 2 deletions

View file

@ -71,6 +71,24 @@ def test_auto_refresh_does_not_fire_on_other_section():
assert refreshed["n"] == 0
def test_create_app_registers_auto_refresh_middleware():
"""Regression: create_app() must actually WIRE the auto-refresh middleware.
It was defined in register_config_routes_hooks() but never called from
create_app(), so in prod a saved toggle never refreshed the live filter and
had to be poked with POST /api/notifications/refresh-toggles by hand."""
from meshai.dashboard.server import create_app
app = create_app()
dispatches = []
for mw in app.user_middleware:
fn = (getattr(mw, "kwargs", {}) or {}).get("dispatch")
if fn is not None:
dispatches.append(getattr(fn, "__qualname__", ""))
assert any("_auto_refresh_toggle_filter" in q for q in dispatches), (
"create_app() did not register the toggle auto-refresh middleware"
)
# ============================================================================
# Item 2 -- env_reporter cap from adapter_config
# ============================================================================