meshai/work/tests/test_satpass_registration.py
malice e9daabfbff
fix(satpass): default feed_source to native; correct misleading config comments (#139)
Central is retired -- its NATS broker (nats://central.echo6.mesh:4222) no
longer exists -- but SatpassConfig.feed_source still defaulted to "central",
overriding the _SourcedFeed mixin default of "native". A fresh install that
enabled satpass got a silently dead adapter. The dashboard reinforced it:
Environment.tsx seeded feed_source 'central' and labelled the adapter
"via Central".

Also corrects comments that documented the opposite of the code: the
adapter_config keys usgs_quake.global_mag_floor / regional_mag_floor were
labelled "CENTRAL-PATH ONLY", but notifications/gating/quake.py reads them
unconditionally in the native path. Following those comments would have led
someone to delete live config keys.

- config.py: SatpassConfig.feed_source "central" -> "native" + docstring
- adapter_config/defaults.py: correct the two "CENTRAL-PATH ONLY" comments
- Environment.tsx: seed 'native'; reword the satpass subtitle
- tests: assert the native default; pin central explicitly where a test
  exercises the central path or the feed_source flip

Suite: 2337 passed, 6 pre-existing failures (stale SCHEMA_VERSION x3,
expired TLE fixtures x2, one order-dependent), no new failures.

Co-authored-by: Matt Johnson <mj@k7zvx.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-17 14:09:24 -06:00

96 lines
3.4 KiB
Python

"""Tests for satpass adapter registration on EnvironmentalConfig.
Verifies:
- SatpassConfig exists and defaults to feed_source="native"
- EnvironmentalConfig.satpass field is present and correctly typed
- _subject_owned() includes central.sat.* subjects when satpass is registered
- adapter_config REGISTRY contains satpass keys with valid types
"""
import pytest
# -- config model tests -------------------------------------------------------
def test_satpass_config_exists():
from meshai.config import SatpassConfig
cfg = SatpassConfig()
assert cfg.feed_source == "native"
assert cfg.enabled is False
def test_satpass_config_is_sourced_feed():
from meshai.config import SatpassConfig, _SourcedFeed
assert issubclass(SatpassConfig, _SourcedFeed)
def test_satpass_config_rejects_invalid_feed_source():
from meshai.config import SatpassConfig
with pytest.raises(ValueError, match="feed_source"):
SatpassConfig(feed_source="bogus")
def test_environmental_config_has_satpass():
from meshai.config import EnvironmentalConfig, SatpassConfig
env = EnvironmentalConfig()
assert hasattr(env, "satpass")
assert isinstance(env.satpass, SatpassConfig)
def test_environmental_satpass_default_native():
from meshai.config import EnvironmentalConfig
env = EnvironmentalConfig()
assert env.satpass.feed_source == "native"
# -- adapter_config REGISTRY --------------------------------------------------
def test_registry_has_satpass_enabled():
from meshai.adapter_config.defaults import REGISTRY
assert ("satpass", "enabled") in REGISTRY
spec = REGISTRY[("satpass", "enabled")]
assert spec["type"] == "bool"
assert spec["default"] is False
def test_registry_satpass_types_valid():
"""All satpass REGISTRY entries must use types in the valid vocabulary."""
from meshai.adapter_config.defaults import REGISTRY
valid = {"int", "float", "str", "bool", "json"}
satpass_keys = [(a, k) for a, k in REGISTRY if a == "satpass"]
assert len(satpass_keys) >= 5, f"Expected >= 5 satpass keys, got {len(satpass_keys)}"
for a, k in satpass_keys:
assert REGISTRY[(a, k)]["type"] in valid, (
f"satpass.{k} has invalid type {REGISTRY[(a, k)]['type']!r}"
)
def test_registry_satpass_list_types_are_json():
"""List-valued satpass keys must use type='json', not 'list'."""
from meshai.adapter_config.defaults import REGISTRY
for key in ("observers", "norad_ids", "command_norad_ids"):
spec = REGISTRY[("satpass", key)]
assert spec["type"] == "json", (
f"satpass.{key} should be type='json', got {spec['type']!r}"
)
def test_adapter_meta_has_satpass():
from meshai.adapter_config.defaults import ADAPTER_META
assert "satpass" in ADAPTER_META
# -- YAML round-trip -----------------------------------------------------------
def test_yaml_parsing_satpass():
"""SatpassConfig should be deserialized from YAML config dict."""
from meshai.config import SatpassConfig, _dict_to_dataclass, EnvironmentalConfig
import yaml
yaml_str = "environmental:\n satpass:\n enabled: true\n feed_source: native\n"
data = yaml.safe_load(yaml_str)
env = _dict_to_dataclass(EnvironmentalConfig, data["environmental"])
assert isinstance(env.satpass, SatpassConfig)
assert env.satpass.enabled is True
assert env.satpass.feed_source == "native"