central/tests/test_telemetry_separation.py
malice 03602c02f8 v0.13.0: sat_orbits adapter (forward-orbit-track per satellite) + antimeridian splitter
New SourceAdapter publishes one forward-orbit-track LineString per tracked
satellite per poll (5min cadence, 90min horizon, 60s vertex resolution).
Drives the "each sat's path" map view Matt asked for after enabling the
satellite family and seeing overlapping orange visibility-footprint
circles + a polar-orbit ground track wrapping the wrong way across the
antimeridian.

Companion to v0.12.0 sat_positions: one publishes the current sub-sat POINT
per minute, sat_orbits publishes the LINE of where it's going. Complement,
not replacement.

data_class=telemetry (continuous trajectory state, surfaces on /telemetry).
Geo carries both centroid (current sub-sat point for the "here it is" dot)
and geometry (the forward track LineString or MultiLineString).

Antimeridian splitter is the key new sat_common primitive: walks the
vertex list, splits at +/-180 crossings, interpolates lat at the crossing
point for crisp dateline termination. ALSO fixes the v0.11.2
satpass_predict "wrong-way wrap" bug by rewiring _build_pass_geometry's
ground_track through the same splitter (sibling concern, documented in
the PR body as intentional scope-coupling).

CENTRAL_SAT stream STREAM_CATEGORY_DOMAINS extends from
('tle', 'pass', 'position') to ('tle', 'pass', 'position', 'orbit'). No
max_bytes bump needed; 6 sats x 12 polls/hour x 24 hours x ~5KB = ~8.5
MB/day, negligible against the 5 GiB cap.

GUI events_list.html adds a small per-NORAD-ID color helper using
golden-angle HSL hue distribution. sat_orbits events render with
per-satellite colors; other adapters keep their existing per-adapter
palette color (additive).

Phase A sanity verified: ISS TLE at 2026-06-09T07:00 UTC propagates to
91 vertices over 90min, first vertex matches v0.11.1's known sub-sat
point (170.66 lon, -17.15 lat, 417.4 km alt), one antimeridian crossing
splits the track into a 2-segment MultiLineString.

44/44 satpass_predict regression-guard tests pass after the
_build_pass_geometry rewire. One new test specifically exercises the
splitter inside _build_pass_geometry for a synthesized polar-orbit
ground_track.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-09 18:44:14 -06:00

108 lines
4.3 KiB
Python

"""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
# Adapters with data_class="telemetry" (the pinned split; grow as telemetry adapters land).
# v0.11.0 added celestrak_tle (orbital state -- continuous-ish refresh, telemetry-class).
# v0.12.0 added sat_positions (60s sub-sat point per tracked satellite).
# v0.13.0 added sat_orbits (90min forward-track LineString per satellite, every 5min).
_TELEMETRY = ["celestrak_tle", "itd_511_cameras", "nwis", "sat_orbits",
"sat_positions", "tomtom_flow"]
# --- data_class defaults / registry split -----------------------------------
def test_base_default_is_event():
assert SourceAdapter.data_class == "event"
def test_registry_split_event_vs_telemetry():
reg = discover_adapters()
by_class = {}
for name, cls in reg.items():
by_class.setdefault(getattr(cls, "data_class", "event"), []).append(name)
assert sorted(by_class.get("telemetry", [])) == _TELEMETRY
# Everything else is event-class; the split must cover the whole registry.
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)
def test_class_adapter_names():
assert "nwis" not in routes._class_adapter_names("event")
assert sorted(routes._class_adapter_names("telemetry")) == _TELEMETRY
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
assert len(flat) == len(discover_adapters()) - len(_TELEMETRY)
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")
assert sorted(a["name"] for a in flat) == _TELEMETRY
grouped_values = [opt["value"] for _, items in grouped for opt in items]
assert sorted(grouped_values) == _TELEMETRY
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"]