central/tests/test_telemetry_separation.py

104 lines
4 KiB
Python
Raw Normal View History

feat(telemetry-separation): dedicated /telemetry tab split from /events by adapter data_class (v0.7.4) PR #5 of the v0.7.x GUI rework arc. Production code; central-gui restart only (supervisor untouched -- data_class is read only by central-gui per request). - SourceAdapter gains a `data_class` class attr (Literal["event","telemetry"], default "event"). NWIS opts in as "telemetry" (continuous high-volume water gauges); every other adapter stays "event". The /events vs /telemetry split is thus registry-derived from class attrs -- no hardcoded adapter-name lists. - routes.py refactor: `_class_adapter_names(data_class)` and a `data_class` arg on `_adapter_filter_options` scope the flat + domain-grouped chip/legend lists to a class (colors stay keyed to the FULL registry, so an adapter keeps one color across tabs). `_fetch_events` accepts `class_adapters` and adds an `adapter = ANY(...)` condition. Shared `_events_query`, `_events_page(data_class, base_path)` and `_events_rows_fragment(...)` back both tabs; `/events`, `/events/rows`, `/telemetry`, `/telemetry/rows` are thin wrappers. - Templates parameterized with a `base_path` context var (form action, hx-get, hx-push-url header, clear-all redirect, JS BASE_PATH const); the `_events_rows` paginator macro takes `base`. Same templates serve both tabs; nav gains a Telemetry link. - /events.json UNCHANGED -- the cursor path sets no `class_adapters`, so the subject + pagination contract is intact (TestEventsJsonSubject still passes). Adds TestTelemetrySeparation (data_class defaults, registry split 11 event / 1 telemetry, class-scoped filter options, color stability, and the `adapter = ANY(...)` SQL shape incl. the no-class events.json path). Updates the events frontend tests for the base_path-parameterized templates. Full suite: 682 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 07:34:08 +00:00
"""Tests for v0.7.4 telemetry/event separation: SourceAdapter.data_class,
registry split, class-scoped filter options, and the data_class SQL filter.
Registry-derived (no hardcoded adapter lists beyond the nwis pin). No live DB.
"""
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from central.adapter import SourceAdapter
from central.adapter_discovery import discover_adapters
from central.gui import routes
feat(tomtom_flow): TomTom Orbis vector flow-tile telemetry adapter + CENTRAL_TRAFFIC_FLOW (v0.9.3) Third CENTRAL_TRAFFIC-family member, first telemetry traffic source. Polls a configured tile coverage set (Idaho metros, z=10), fetches Orbis vector flow tiles, decodes per-segment relative_speed + road geometry, emits one telemetry Event per road segment per poll to the new CENTRAL_TRAFFIC_FLOW stream. Renders as colored polylines (green free-flow -> red jam) on the /telemetry map. Production code; supervisor + gui + ARCHIVE restart (NEW event-bearing stream central.traffic_flow.> -> archive must resubscribe). Ships disabled; needs a "tomtom" api key in config.api_keys before enable. - Subject central.traffic_flow.{z}.{x}.{y} (token traffic_flow, non-overlapping with central.traffic.>). category="flow.tomtom_flow" -> GUI event_type "flow". - Severity from relative_speed: >=0.75=1, 0.5-0.75=2, 0.25-0.5=3, <0.25=4. - Cadence 300s; 7-day retention (high-volume telemetry). Dedup minute-bucketed, inherited from the v0.9.1 SourceAdapter mixin. - Shared tomtom_flow_parse module (decode + slippy-tile georeference) reused by the v0.9.4 on-demand passthrough endpoint. - Generic framework change (Option A, ~3 lines, inert for the other 14 adapters): Geo.geometry optional field + archive _build_geom_sql prefers it, so segments persist their real LineString to the PostGIS geom column. - Idaho-only (Orbis tier confirmed live). Cameras + Navi passthrough are follow-ups. - deps: mapbox-vector-tile (vector PBF decode); itsdangerous promoted to an explicit dependency (gui/csrf.py + gui/wizard.py imported it as an undeclared transitive that uv re-lock would otherwise prune). Full suite: 780 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 23:25:44 +00:00
# Adapters with data_class="telemetry" (the pinned split; grow as telemetry adapters land).
_TELEMETRY = ["nwis", "tomtom_flow"]
feat(telemetry-separation): dedicated /telemetry tab split from /events by adapter data_class (v0.7.4) PR #5 of the v0.7.x GUI rework arc. Production code; central-gui restart only (supervisor untouched -- data_class is read only by central-gui per request). - SourceAdapter gains a `data_class` class attr (Literal["event","telemetry"], default "event"). NWIS opts in as "telemetry" (continuous high-volume water gauges); every other adapter stays "event". The /events vs /telemetry split is thus registry-derived from class attrs -- no hardcoded adapter-name lists. - routes.py refactor: `_class_adapter_names(data_class)` and a `data_class` arg on `_adapter_filter_options` scope the flat + domain-grouped chip/legend lists to a class (colors stay keyed to the FULL registry, so an adapter keeps one color across tabs). `_fetch_events` accepts `class_adapters` and adds an `adapter = ANY(...)` condition. Shared `_events_query`, `_events_page(data_class, base_path)` and `_events_rows_fragment(...)` back both tabs; `/events`, `/events/rows`, `/telemetry`, `/telemetry/rows` are thin wrappers. - Templates parameterized with a `base_path` context var (form action, hx-get, hx-push-url header, clear-all redirect, JS BASE_PATH const); the `_events_rows` paginator macro takes `base`. Same templates serve both tabs; nav gains a Telemetry link. - /events.json UNCHANGED -- the cursor path sets no `class_adapters`, so the subject + pagination contract is intact (TestEventsJsonSubject still passes). Adds TestTelemetrySeparation (data_class defaults, registry split 11 event / 1 telemetry, class-scoped filter options, color stability, and the `adapter = ANY(...)` SQL shape incl. the no-class events.json path). Updates the events frontend tests for the base_path-parameterized templates. Full suite: 682 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 07:34:08 +00:00
# --- data_class defaults / registry split -----------------------------------
def test_base_default_is_event():
assert SourceAdapter.data_class == "event"
def test_registry_split_11_event_1_telemetry():
reg = discover_adapters()
by_class = {}
for name, cls in reg.items():
by_class.setdefault(getattr(cls, "data_class", "event"), []).append(name)
feat(tomtom_flow): TomTom Orbis vector flow-tile telemetry adapter + CENTRAL_TRAFFIC_FLOW (v0.9.3) Third CENTRAL_TRAFFIC-family member, first telemetry traffic source. Polls a configured tile coverage set (Idaho metros, z=10), fetches Orbis vector flow tiles, decodes per-segment relative_speed + road geometry, emits one telemetry Event per road segment per poll to the new CENTRAL_TRAFFIC_FLOW stream. Renders as colored polylines (green free-flow -> red jam) on the /telemetry map. Production code; supervisor + gui + ARCHIVE restart (NEW event-bearing stream central.traffic_flow.> -> archive must resubscribe). Ships disabled; needs a "tomtom" api key in config.api_keys before enable. - Subject central.traffic_flow.{z}.{x}.{y} (token traffic_flow, non-overlapping with central.traffic.>). category="flow.tomtom_flow" -> GUI event_type "flow". - Severity from relative_speed: >=0.75=1, 0.5-0.75=2, 0.25-0.5=3, <0.25=4. - Cadence 300s; 7-day retention (high-volume telemetry). Dedup minute-bucketed, inherited from the v0.9.1 SourceAdapter mixin. - Shared tomtom_flow_parse module (decode + slippy-tile georeference) reused by the v0.9.4 on-demand passthrough endpoint. - Generic framework change (Option A, ~3 lines, inert for the other 14 adapters): Geo.geometry optional field + archive _build_geom_sql prefers it, so segments persist their real LineString to the PostGIS geom column. - Idaho-only (Orbis tier confirmed live). Cameras + Navi passthrough are follow-ups. - deps: mapbox-vector-tile (vector PBF decode); itsdangerous promoted to an explicit dependency (gui/csrf.py + gui/wizard.py imported it as an undeclared transitive that uv re-lock would otherwise prune). Full suite: 780 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 23:25:44 +00:00
assert sorted(by_class.get("telemetry", [])) == _TELEMETRY
feat(telemetry-separation): dedicated /telemetry tab split from /events by adapter data_class (v0.7.4) PR #5 of the v0.7.x GUI rework arc. Production code; central-gui restart only (supervisor untouched -- data_class is read only by central-gui per request). - SourceAdapter gains a `data_class` class attr (Literal["event","telemetry"], default "event"). NWIS opts in as "telemetry" (continuous high-volume water gauges); every other adapter stays "event". The /events vs /telemetry split is thus registry-derived from class attrs -- no hardcoded adapter-name lists. - routes.py refactor: `_class_adapter_names(data_class)` and a `data_class` arg on `_adapter_filter_options` scope the flat + domain-grouped chip/legend lists to a class (colors stay keyed to the FULL registry, so an adapter keeps one color across tabs). `_fetch_events` accepts `class_adapters` and adds an `adapter = ANY(...)` condition. Shared `_events_query`, `_events_page(data_class, base_path)` and `_events_rows_fragment(...)` back both tabs; `/events`, `/events/rows`, `/telemetry`, `/telemetry/rows` are thin wrappers. - Templates parameterized with a `base_path` context var (form action, hx-get, hx-push-url header, clear-all redirect, JS BASE_PATH const); the `_events_rows` paginator macro takes `base`. Same templates serve both tabs; nav gains a Telemetry link. - /events.json UNCHANGED -- the cursor path sets no `class_adapters`, so the subject + pagination contract is intact (TestEventsJsonSubject still passes). Adds TestTelemetrySeparation (data_class defaults, registry split 11 event / 1 telemetry, class-scoped filter options, color stability, and the `adapter = ANY(...)` SQL shape incl. the no-class events.json path). Updates the events frontend tests for the base_path-parameterized templates. Full suite: 682 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 07:34:08 +00:00
# Everything else is event-class; the split must cover the whole registry.
feat(tomtom_flow): TomTom Orbis vector flow-tile telemetry adapter + CENTRAL_TRAFFIC_FLOW (v0.9.3) Third CENTRAL_TRAFFIC-family member, first telemetry traffic source. Polls a configured tile coverage set (Idaho metros, z=10), fetches Orbis vector flow tiles, decodes per-segment relative_speed + road geometry, emits one telemetry Event per road segment per poll to the new CENTRAL_TRAFFIC_FLOW stream. Renders as colored polylines (green free-flow -> red jam) on the /telemetry map. Production code; supervisor + gui + ARCHIVE restart (NEW event-bearing stream central.traffic_flow.> -> archive must resubscribe). Ships disabled; needs a "tomtom" api key in config.api_keys before enable. - Subject central.traffic_flow.{z}.{x}.{y} (token traffic_flow, non-overlapping with central.traffic.>). category="flow.tomtom_flow" -> GUI event_type "flow". - Severity from relative_speed: >=0.75=1, 0.5-0.75=2, 0.25-0.5=3, <0.25=4. - Cadence 300s; 7-day retention (high-volume telemetry). Dedup minute-bucketed, inherited from the v0.9.1 SourceAdapter mixin. - Shared tomtom_flow_parse module (decode + slippy-tile georeference) reused by the v0.9.4 on-demand passthrough endpoint. - Generic framework change (Option A, ~3 lines, inert for the other 14 adapters): Geo.geometry optional field + archive _build_geom_sql prefers it, so segments persist their real LineString to the PostGIS geom column. - Idaho-only (Orbis tier confirmed live). Cameras + Navi passthrough are follow-ups. - deps: mapbox-vector-tile (vector PBF decode); itsdangerous promoted to an explicit dependency (gui/csrf.py + gui/wizard.py imported it as an undeclared transitive that uv re-lock would otherwise prune). Full suite: 780 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 23:25:44 +00:00
assert sorted(by_class.get("event", [])) == sorted(n for n in reg if n not in _TELEMETRY)
assert len(by_class.get("event", [])) == len(reg) - len(_TELEMETRY)
feat(telemetry-separation): dedicated /telemetry tab split from /events by adapter data_class (v0.7.4) PR #5 of the v0.7.x GUI rework arc. Production code; central-gui restart only (supervisor untouched -- data_class is read only by central-gui per request). - SourceAdapter gains a `data_class` class attr (Literal["event","telemetry"], default "event"). NWIS opts in as "telemetry" (continuous high-volume water gauges); every other adapter stays "event". The /events vs /telemetry split is thus registry-derived from class attrs -- no hardcoded adapter-name lists. - routes.py refactor: `_class_adapter_names(data_class)` and a `data_class` arg on `_adapter_filter_options` scope the flat + domain-grouped chip/legend lists to a class (colors stay keyed to the FULL registry, so an adapter keeps one color across tabs). `_fetch_events` accepts `class_adapters` and adds an `adapter = ANY(...)` condition. Shared `_events_query`, `_events_page(data_class, base_path)` and `_events_rows_fragment(...)` back both tabs; `/events`, `/events/rows`, `/telemetry`, `/telemetry/rows` are thin wrappers. - Templates parameterized with a `base_path` context var (form action, hx-get, hx-push-url header, clear-all redirect, JS BASE_PATH const); the `_events_rows` paginator macro takes `base`. Same templates serve both tabs; nav gains a Telemetry link. - /events.json UNCHANGED -- the cursor path sets no `class_adapters`, so the subject + pagination contract is intact (TestEventsJsonSubject still passes). Adds TestTelemetrySeparation (data_class defaults, registry split 11 event / 1 telemetry, class-scoped filter options, color stability, and the `adapter = ANY(...)` SQL shape incl. the no-class events.json path). Updates the events frontend tests for the base_path-parameterized templates. Full suite: 682 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 07:34:08 +00:00
def test_class_adapter_names():
assert "nwis" not in routes._class_adapter_names("event")
feat(tomtom_flow): TomTom Orbis vector flow-tile telemetry adapter + CENTRAL_TRAFFIC_FLOW (v0.9.3) Third CENTRAL_TRAFFIC-family member, first telemetry traffic source. Polls a configured tile coverage set (Idaho metros, z=10), fetches Orbis vector flow tiles, decodes per-segment relative_speed + road geometry, emits one telemetry Event per road segment per poll to the new CENTRAL_TRAFFIC_FLOW stream. Renders as colored polylines (green free-flow -> red jam) on the /telemetry map. Production code; supervisor + gui + ARCHIVE restart (NEW event-bearing stream central.traffic_flow.> -> archive must resubscribe). Ships disabled; needs a "tomtom" api key in config.api_keys before enable. - Subject central.traffic_flow.{z}.{x}.{y} (token traffic_flow, non-overlapping with central.traffic.>). category="flow.tomtom_flow" -> GUI event_type "flow". - Severity from relative_speed: >=0.75=1, 0.5-0.75=2, 0.25-0.5=3, <0.25=4. - Cadence 300s; 7-day retention (high-volume telemetry). Dedup minute-bucketed, inherited from the v0.9.1 SourceAdapter mixin. - Shared tomtom_flow_parse module (decode + slippy-tile georeference) reused by the v0.9.4 on-demand passthrough endpoint. - Generic framework change (Option A, ~3 lines, inert for the other 14 adapters): Geo.geometry optional field + archive _build_geom_sql prefers it, so segments persist their real LineString to the PostGIS geom column. - Idaho-only (Orbis tier confirmed live). Cameras + Navi passthrough are follow-ups. - deps: mapbox-vector-tile (vector PBF decode); itsdangerous promoted to an explicit dependency (gui/csrf.py + gui/wizard.py imported it as an undeclared transitive that uv re-lock would otherwise prune). Full suite: 780 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 23:25:44 +00:00
assert sorted(routes._class_adapter_names("telemetry")) == _TELEMETRY
feat(telemetry-separation): dedicated /telemetry tab split from /events by adapter data_class (v0.7.4) PR #5 of the v0.7.x GUI rework arc. Production code; central-gui restart only (supervisor untouched -- data_class is read only by central-gui per request). - SourceAdapter gains a `data_class` class attr (Literal["event","telemetry"], default "event"). NWIS opts in as "telemetry" (continuous high-volume water gauges); every other adapter stays "event". The /events vs /telemetry split is thus registry-derived from class attrs -- no hardcoded adapter-name lists. - routes.py refactor: `_class_adapter_names(data_class)` and a `data_class` arg on `_adapter_filter_options` scope the flat + domain-grouped chip/legend lists to a class (colors stay keyed to the FULL registry, so an adapter keeps one color across tabs). `_fetch_events` accepts `class_adapters` and adds an `adapter = ANY(...)` condition. Shared `_events_query`, `_events_page(data_class, base_path)` and `_events_rows_fragment(...)` back both tabs; `/events`, `/events/rows`, `/telemetry`, `/telemetry/rows` are thin wrappers. - Templates parameterized with a `base_path` context var (form action, hx-get, hx-push-url header, clear-all redirect, JS BASE_PATH const); the `_events_rows` paginator macro takes `base`. Same templates serve both tabs; nav gains a Telemetry link. - /events.json UNCHANGED -- the cursor path sets no `class_adapters`, so the subject + pagination contract is intact (TestEventsJsonSubject still passes). Adds TestTelemetrySeparation (data_class defaults, registry split 11 event / 1 telemetry, class-scoped filter options, color stability, and the `adapter = ANY(...)` SQL shape incl. the no-class events.json path). Updates the events frontend tests for the base_path-parameterized templates. Full suite: 682 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 07:34:08 +00:00
assert "usgs_quake" in routes._class_adapter_names("event")
# --- class-scoped chip-picker / legend options -------------------------------
def test_event_options_exclude_nwis():
flat, grouped = routes._adapter_filter_options("event")
names = {a["name"] for a in flat}
assert "nwis" not in names
feat(tomtom_flow): TomTom Orbis vector flow-tile telemetry adapter + CENTRAL_TRAFFIC_FLOW (v0.9.3) Third CENTRAL_TRAFFIC-family member, first telemetry traffic source. Polls a configured tile coverage set (Idaho metros, z=10), fetches Orbis vector flow tiles, decodes per-segment relative_speed + road geometry, emits one telemetry Event per road segment per poll to the new CENTRAL_TRAFFIC_FLOW stream. Renders as colored polylines (green free-flow -> red jam) on the /telemetry map. Production code; supervisor + gui + ARCHIVE restart (NEW event-bearing stream central.traffic_flow.> -> archive must resubscribe). Ships disabled; needs a "tomtom" api key in config.api_keys before enable. - Subject central.traffic_flow.{z}.{x}.{y} (token traffic_flow, non-overlapping with central.traffic.>). category="flow.tomtom_flow" -> GUI event_type "flow". - Severity from relative_speed: >=0.75=1, 0.5-0.75=2, 0.25-0.5=3, <0.25=4. - Cadence 300s; 7-day retention (high-volume telemetry). Dedup minute-bucketed, inherited from the v0.9.1 SourceAdapter mixin. - Shared tomtom_flow_parse module (decode + slippy-tile georeference) reused by the v0.9.4 on-demand passthrough endpoint. - Generic framework change (Option A, ~3 lines, inert for the other 14 adapters): Geo.geometry optional field + archive _build_geom_sql prefers it, so segments persist their real LineString to the PostGIS geom column. - Idaho-only (Orbis tier confirmed live). Cameras + Navi passthrough are follow-ups. - deps: mapbox-vector-tile (vector PBF decode); itsdangerous promoted to an explicit dependency (gui/csrf.py + gui/wizard.py imported it as an undeclared transitive that uv re-lock would otherwise prune). Full suite: 780 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 23:25:44 +00:00
assert len(flat) == len(discover_adapters()) - len(_TELEMETRY)
feat(telemetry-separation): dedicated /telemetry tab split from /events by adapter data_class (v0.7.4) PR #5 of the v0.7.x GUI rework arc. Production code; central-gui restart only (supervisor untouched -- data_class is read only by central-gui per request). - SourceAdapter gains a `data_class` class attr (Literal["event","telemetry"], default "event"). NWIS opts in as "telemetry" (continuous high-volume water gauges); every other adapter stays "event". The /events vs /telemetry split is thus registry-derived from class attrs -- no hardcoded adapter-name lists. - routes.py refactor: `_class_adapter_names(data_class)` and a `data_class` arg on `_adapter_filter_options` scope the flat + domain-grouped chip/legend lists to a class (colors stay keyed to the FULL registry, so an adapter keeps one color across tabs). `_fetch_events` accepts `class_adapters` and adds an `adapter = ANY(...)` condition. Shared `_events_query`, `_events_page(data_class, base_path)` and `_events_rows_fragment(...)` back both tabs; `/events`, `/events/rows`, `/telemetry`, `/telemetry/rows` are thin wrappers. - Templates parameterized with a `base_path` context var (form action, hx-get, hx-push-url header, clear-all redirect, JS BASE_PATH const); the `_events_rows` paginator macro takes `base`. Same templates serve both tabs; nav gains a Telemetry link. - /events.json UNCHANGED -- the cursor path sets no `class_adapters`, so the subject + pagination contract is intact (TestEventsJsonSubject still passes). Adds TestTelemetrySeparation (data_class defaults, registry split 11 event / 1 telemetry, class-scoped filter options, color stability, and the `adapter = ANY(...)` SQL shape incl. the no-class events.json path). Updates the events frontend tests for the base_path-parameterized templates. Full suite: 682 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 07:34:08 +00:00
grouped_values = {opt["value"] for _, items in grouped for opt in items}
assert "nwis" not in grouped_values
def test_telemetry_options_only_nwis():
flat, grouped = routes._adapter_filter_options("telemetry")
feat(tomtom_flow): TomTom Orbis vector flow-tile telemetry adapter + CENTRAL_TRAFFIC_FLOW (v0.9.3) Third CENTRAL_TRAFFIC-family member, first telemetry traffic source. Polls a configured tile coverage set (Idaho metros, z=10), fetches Orbis vector flow tiles, decodes per-segment relative_speed + road geometry, emits one telemetry Event per road segment per poll to the new CENTRAL_TRAFFIC_FLOW stream. Renders as colored polylines (green free-flow -> red jam) on the /telemetry map. Production code; supervisor + gui + ARCHIVE restart (NEW event-bearing stream central.traffic_flow.> -> archive must resubscribe). Ships disabled; needs a "tomtom" api key in config.api_keys before enable. - Subject central.traffic_flow.{z}.{x}.{y} (token traffic_flow, non-overlapping with central.traffic.>). category="flow.tomtom_flow" -> GUI event_type "flow". - Severity from relative_speed: >=0.75=1, 0.5-0.75=2, 0.25-0.5=3, <0.25=4. - Cadence 300s; 7-day retention (high-volume telemetry). Dedup minute-bucketed, inherited from the v0.9.1 SourceAdapter mixin. - Shared tomtom_flow_parse module (decode + slippy-tile georeference) reused by the v0.9.4 on-demand passthrough endpoint. - Generic framework change (Option A, ~3 lines, inert for the other 14 adapters): Geo.geometry optional field + archive _build_geom_sql prefers it, so segments persist their real LineString to the PostGIS geom column. - Idaho-only (Orbis tier confirmed live). Cameras + Navi passthrough are follow-ups. - deps: mapbox-vector-tile (vector PBF decode); itsdangerous promoted to an explicit dependency (gui/csrf.py + gui/wizard.py imported it as an undeclared transitive that uv re-lock would otherwise prune). Full suite: 780 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 23:25:44 +00:00
assert sorted(a["name"] for a in flat) == _TELEMETRY
feat(telemetry-separation): dedicated /telemetry tab split from /events by adapter data_class (v0.7.4) PR #5 of the v0.7.x GUI rework arc. Production code; central-gui restart only (supervisor untouched -- data_class is read only by central-gui per request). - SourceAdapter gains a `data_class` class attr (Literal["event","telemetry"], default "event"). NWIS opts in as "telemetry" (continuous high-volume water gauges); every other adapter stays "event". The /events vs /telemetry split is thus registry-derived from class attrs -- no hardcoded adapter-name lists. - routes.py refactor: `_class_adapter_names(data_class)` and a `data_class` arg on `_adapter_filter_options` scope the flat + domain-grouped chip/legend lists to a class (colors stay keyed to the FULL registry, so an adapter keeps one color across tabs). `_fetch_events` accepts `class_adapters` and adds an `adapter = ANY(...)` condition. Shared `_events_query`, `_events_page(data_class, base_path)` and `_events_rows_fragment(...)` back both tabs; `/events`, `/events/rows`, `/telemetry`, `/telemetry/rows` are thin wrappers. - Templates parameterized with a `base_path` context var (form action, hx-get, hx-push-url header, clear-all redirect, JS BASE_PATH const); the `_events_rows` paginator macro takes `base`. Same templates serve both tabs; nav gains a Telemetry link. - /events.json UNCHANGED -- the cursor path sets no `class_adapters`, so the subject + pagination contract is intact (TestEventsJsonSubject still passes). Adds TestTelemetrySeparation (data_class defaults, registry split 11 event / 1 telemetry, class-scoped filter options, color stability, and the `adapter = ANY(...)` SQL shape incl. the no-class events.json path). Updates the events frontend tests for the base_path-parameterized templates. Full suite: 682 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 07:34:08 +00:00
grouped_values = [opt["value"] for _, items in grouped for opt in items]
feat(tomtom_flow): TomTom Orbis vector flow-tile telemetry adapter + CENTRAL_TRAFFIC_FLOW (v0.9.3) Third CENTRAL_TRAFFIC-family member, first telemetry traffic source. Polls a configured tile coverage set (Idaho metros, z=10), fetches Orbis vector flow tiles, decodes per-segment relative_speed + road geometry, emits one telemetry Event per road segment per poll to the new CENTRAL_TRAFFIC_FLOW stream. Renders as colored polylines (green free-flow -> red jam) on the /telemetry map. Production code; supervisor + gui + ARCHIVE restart (NEW event-bearing stream central.traffic_flow.> -> archive must resubscribe). Ships disabled; needs a "tomtom" api key in config.api_keys before enable. - Subject central.traffic_flow.{z}.{x}.{y} (token traffic_flow, non-overlapping with central.traffic.>). category="flow.tomtom_flow" -> GUI event_type "flow". - Severity from relative_speed: >=0.75=1, 0.5-0.75=2, 0.25-0.5=3, <0.25=4. - Cadence 300s; 7-day retention (high-volume telemetry). Dedup minute-bucketed, inherited from the v0.9.1 SourceAdapter mixin. - Shared tomtom_flow_parse module (decode + slippy-tile georeference) reused by the v0.9.4 on-demand passthrough endpoint. - Generic framework change (Option A, ~3 lines, inert for the other 14 adapters): Geo.geometry optional field + archive _build_geom_sql prefers it, so segments persist their real LineString to the PostGIS geom column. - Idaho-only (Orbis tier confirmed live). Cameras + Navi passthrough are follow-ups. - deps: mapbox-vector-tile (vector PBF decode); itsdangerous promoted to an explicit dependency (gui/csrf.py + gui/wizard.py imported it as an undeclared transitive that uv re-lock would otherwise prune). Full suite: 780 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 23:25:44 +00:00
assert sorted(grouped_values) == _TELEMETRY
feat(telemetry-separation): dedicated /telemetry tab split from /events by adapter data_class (v0.7.4) PR #5 of the v0.7.x GUI rework arc. Production code; central-gui restart only (supervisor untouched -- data_class is read only by central-gui per request). - SourceAdapter gains a `data_class` class attr (Literal["event","telemetry"], default "event"). NWIS opts in as "telemetry" (continuous high-volume water gauges); every other adapter stays "event". The /events vs /telemetry split is thus registry-derived from class attrs -- no hardcoded adapter-name lists. - routes.py refactor: `_class_adapter_names(data_class)` and a `data_class` arg on `_adapter_filter_options` scope the flat + domain-grouped chip/legend lists to a class (colors stay keyed to the FULL registry, so an adapter keeps one color across tabs). `_fetch_events` accepts `class_adapters` and adds an `adapter = ANY(...)` condition. Shared `_events_query`, `_events_page(data_class, base_path)` and `_events_rows_fragment(...)` back both tabs; `/events`, `/events/rows`, `/telemetry`, `/telemetry/rows` are thin wrappers. - Templates parameterized with a `base_path` context var (form action, hx-get, hx-push-url header, clear-all redirect, JS BASE_PATH const); the `_events_rows` paginator macro takes `base`. Same templates serve both tabs; nav gains a Telemetry link. - /events.json UNCHANGED -- the cursor path sets no `class_adapters`, so the subject + pagination contract is intact (TestEventsJsonSubject still passes). Adds TestTelemetrySeparation (data_class defaults, registry split 11 event / 1 telemetry, class-scoped filter options, color stability, and the `adapter = ANY(...)` SQL shape incl. the no-class events.json path). Updates the events frontend tests for the base_path-parameterized templates. Full suite: 682 passed, 1 skipped (central and unprivileged zvx, 3x each). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 07:34:08 +00:00
def test_colors_stable_across_classes():
"""A given adapter keeps the same color on /events and /telemetry (colors
are keyed to the full registry, not the per-tab subset)."""
full, _ = routes._adapter_filter_options()
full_color = {a["name"]: a["color"] for a in full}
ev, _ = routes._adapter_filter_options("event")
for a in ev:
assert a["color"] == full_color[a["name"]]
# --- data_class SQL filter (captured SQL) ------------------------------------
async def _capture(parsed):
captured = {}
async def fake_fetch(query, *args):
captured["query"] = query
captured["params"] = list(args)
return []
conn = MagicMock()
conn.fetch = fake_fetch
pool = MagicMock()
pool.acquire.return_value.__aenter__ = AsyncMock(return_value=conn)
pool.acquire.return_value.__aexit__ = AsyncMock(return_value=None)
with patch("central.gui.routes.get_pool", return_value=pool):
await routes._fetch_events(parsed)
return captured
@pytest.mark.asyncio
async def test_class_adapters_adds_adapter_any_condition():
parsed, _ = routes._parse_events_params({"time": "all"}, default_offset=0)
parsed["class_adapters"] = routes._class_adapter_names("event")
cap = await _capture(parsed)
assert "adapter = ANY($" in cap["query"]
assert routes._class_adapter_names("event") in cap["params"]
@pytest.mark.asyncio
async def test_no_class_adapters_no_class_condition():
"""events.json path: no class_adapters -> no extra adapter filter (all classes)."""
parsed, _ = routes._parse_events_params({"time": "all"}) # cursor-mode, no class
assert parsed.get("class_adapters") is None
cap = await _capture(parsed)
# The only adapter=ANY would come from a user filter, which we didn't set.
assert "adapter = ANY($" not in cap["query"]