mirror of
https://github.com/zvx-echo6/meshai.git
synced 2026-08-26 17:31:34 +00:00
Triaged all 20 known-red tests. 13 were stale tests asserting rotted expectations against deliberate, documented behavior changes; fixed by deriving expected values instead of hard-coding, or updating the expectation to match a documented policy change: - test_adapter_config_foundation.py / test_adapter_config_api.py: REGISTRY/API key-count and key-set guards hard-coded magic numbers (59/94/17) that rotted repeatedly. Now derive expectations from REGISTRY itself and, for the schema version, from the migrations directory, so they can't rot the same way again. - test_fire_tracker_phase4.py: two tests hardcoded a nonexistent deployment path (/opt/meshai/meshai/router.py) that matches no Dockerfile WORKDIR in this repo; resolve the module path via importlib.util.find_spec instead. - test_tombstone_broadcast.py: asserted fire severity == "immediate", which commit2f677e85deliberately downgraded to "priority" (to stop fire broadcasts bypassing the Grouper/cooldown during NATS backlog replay) without updating this test. - test_pipeline_grouper.py: test_immediate_severity_bypasses_grouper asserted an immediate-severity bypass that commit85d48ce3("fix(fire): remove immediate-severity exemption from grouper + cooldown") DELETED on purpose -- fire events carry _severity_override="immediate", and the exemption left fire with no rate control at all in normal live operation. Re-adding the bypass would re-open that fire-spam hole on a public-safety mesh, so the test moves, not the source. Renamed + inverted to assert the real contract (all severities coalesce; only a missing group_key passes through). - test_tail_followups.py: dispatcher mock was missing dispatch_scheduled_fire_broadcast (a method added alongside the generic dispatch_scheduled_broadcast; test_reminders.py already mocks both). - test_tracking_v057.py: guard required an empty tracking-family adapter list in Environment.tsx, but the frontend has long grouped the pre-existing native satpass adapter under the "Tracking" display section (its own "satpass" backend toggle, unrelated to the Phase-7 tracking family every other guard in this file confirms is still unimplemented). Narrowed the guard to allow only that known entry. - test_v052_dispatcher.py: two tests used category="wildfire_incident", which the phase3b fire migration (#33) forced onto a dedicated formatter via NATIVE_ALWAYS_DECIDE; swapped to wildfire_hotspot (same emoji/label, not in NATIVE_ALWAYS_DECIDE) to keep exercising the generic composer logic under test. Also fixes one stale COMMENT (comment-only, no logic change) in meshai/notifications/pipeline/__init__.py's start_pipeline(): it still claimed "Immediate events bypass the grouper and don't need this [periodic flush]", which has been false since85d48ce3and is precisely what makes the deleted bypass look like a missing feature. The comment now records that the removal was deliberate and must not be reverted. The remaining 6 failures are left untouched -- 2 confirmed real bugs, to be fixed deliberately in their own changes: - meshcore_transport.py defines `_resolve_contact` TWICE on MeshCoreTransport (line 171 from PR #56, line 1227 from PR #92). The second silently shadows the first, so the DM contact-resolution refetch-on-miss that #56 added is dead code in production. (3 tests) - SCHEMA_VERSION (persistence/db.py:33) is stale at 26 vs. the actual highest migration v28; v27 and v28 shipped without bumping it. (3 tests) Plus 1 environment gap, not a code defect: test_natural_language_fire_question_routes_to_llm needs the `openai` package, which is declared in requirements.txt but not installed here. Suite: 20 failed, 2240 passed, 72 skipped -> 7 failed, 2254 passed, 72 skipped. All 7 remaining failures are ones classified above; no new failures introduced elsewhere in the suite. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
189 lines
8.6 KiB
Python
189 lines
8.6 KiB
Python
"""v0.5.7-tracking: Central tracking adapter check + categories audit.
|
|
|
|
The tracking family is a PLACEHOLDER for Phase 7 (per
|
|
meshai/notifications/categories.py:19 header comment: "tracking - ADS-B,
|
|
AIS, satellite passes (Phase 7)"). As of v0.5.7-tracking it has:
|
|
|
|
- "tracking" in VALID_TOGGLES (reserved toggle name)
|
|
- dashboard-frontend/src/pages/Environment.tsx FAMILIES list entry with
|
|
label="Tracking", icon=Satellite, adapters=['satpass'] (a pre-existing
|
|
UI-only grouping of the native satpass adapter under the "Tracking"
|
|
display section; satpass has its own "satpass" backend toggle and is
|
|
NOT itself a Phase-7 tracking-family adapter -- the guard below allows
|
|
only this one known entry and fails on anything else)
|
|
- ZERO native adapter files in meshai/env/
|
|
- ZERO ALERT_CATEGORIES entries with toggle="tracking"
|
|
- ZERO Central wires (no central.tracking.* / central.aprs.* / etc.;
|
|
no entries in _SUBJECTS_BARE; no entries in CENTRAL_ADAPTER_TO_SOURCE)
|
|
|
|
This file pins all of those invariants as regression guards. The intent
|
|
is that a future Phase 7 commit that flips any of these (e.g. adds an
|
|
APRS adapter, wires a Central tracking subject) will fail these tests
|
|
and FORCE the implementer to come back and complete the family-audit
|
|
shape (registry entries with required fields, composer emoji/labels,
|
|
test file refresh) the same way every other family in v0.5.7 was done.
|
|
|
|
Central v0.10.0 cross-check
|
|
---------------------------
|
|
The Central v0.10.0 guide (docs/CONSUMER-INTEGRATION.md at v0.10.0-itd-511)
|
|
documents 22 per-adapter sections covering wx / fire / quake / space /
|
|
disaster / traffic / hydro -- NONE are tracking-related. The producer
|
|
source tree src/central/adapters/ contains 24 adapter files; NONE are
|
|
named for any tracking concept (aprs / adsb / opensky / satellite /
|
|
position). Subject prefixes used: central.{disaster,fire,fires,hydro,
|
|
meta,models,quake,space,traffic,traffic_cameras,traffic_flow,wx}.> --
|
|
no central.tracking.* / central.aprs.*.
|
|
|
|
Same shape as v0.5.7-avalanche: no Central counterpart, native-only
|
|
(currently native-empty).
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from meshai.central.consumer import (
|
|
CENTRAL_ADAPTER_TO_SOURCE,
|
|
CentralConsumer,
|
|
_SUBJECTS_BARE,
|
|
_subjects_for,
|
|
)
|
|
from meshai.config import EnvironmentalConfig
|
|
from meshai.notifications.categories import ALERT_CATEGORIES, VALID_TOGGLES
|
|
|
|
|
|
# ---------- FIX 1: Central has no tracking adapter -----------------------
|
|
|
|
|
|
def test_central_has_no_tracking_subject_prefix():
|
|
"""No Central stream/subject namespace uses a tracking-style prefix."""
|
|
for adapter, subs in _SUBJECTS_BARE.items():
|
|
for s in subs:
|
|
assert "tracking" not in s.lower(), \
|
|
f"unexpected tracking subject for adapter {adapter}: {s!r}"
|
|
for needle in ("aprs", "adsb", "opensky", "ads_b"):
|
|
assert needle not in s.lower(), \
|
|
f"unexpected {needle!r} subject for adapter {adapter}: {s!r}"
|
|
|
|
|
|
def test_central_adapter_remap_has_no_tracking_entries():
|
|
"""No Central adapter name remaps to a tracking source on either side."""
|
|
for src_name, mesh_name in CENTRAL_ADAPTER_TO_SOURCE.items():
|
|
for needle in ("tracking", "aprs", "adsb", "opensky"):
|
|
assert needle not in src_name.lower(), \
|
|
f"unexpected Central adapter name: {src_name}"
|
|
assert needle not in mesh_name.lower(), \
|
|
f"unexpected meshai source name: {mesh_name}"
|
|
|
|
|
|
def test_tracking_source_is_unknown_to_subjects_for():
|
|
"""Asking the consumer for tracking-source subjects returns empty for
|
|
every region -- the source isn't in the table at all."""
|
|
for region in ("us.id", "us.mt", "", None):
|
|
assert _subjects_for("tracking", region) == [], \
|
|
f"_subjects_for('tracking', {region!r}) should be []"
|
|
assert _subjects_for("aprs", region) == []
|
|
assert _subjects_for("adsb", region) == []
|
|
|
|
|
|
# ---------- meshai-side placeholder invariants ---------------------------
|
|
|
|
|
|
def test_tracking_toggle_is_reserved_in_valid_toggles():
|
|
"""The toggle name 'tracking' is reserved (placeholder for Phase 7)
|
|
even though no categories use it yet."""
|
|
assert "tracking" in VALID_TOGGLES
|
|
|
|
|
|
def test_alert_categories_has_zero_tracking_entries():
|
|
"""v0.5.7-tracking placeholder check: registry has no toggle='tracking'
|
|
entries. If Phase 7 lands, this test should be updated alongside the
|
|
new entries -- not silently deleted."""
|
|
tracking_entries = [
|
|
cid for cid, info in ALERT_CATEGORIES.items()
|
|
if info.get("toggle") == "tracking"
|
|
]
|
|
assert tracking_entries == [], \
|
|
f"unexpected tracking-family entries: {tracking_entries}"
|
|
|
|
|
|
def test_no_native_tracking_adapter_files():
|
|
"""meshai/env/ has no tracking-related adapter files. Phase 7 will
|
|
add at least one (likely aprs.py / adsb.py / opensky.py); when it
|
|
does, this test should be updated to point at the new adapter."""
|
|
env_dir = Path("meshai/env")
|
|
if not env_dir.is_dir():
|
|
pytest.skip("meshai/env not present in this working tree")
|
|
files = {p.name for p in env_dir.iterdir() if p.suffix == ".py"}
|
|
for needle in ("aprs", "adsb", "ads_b", "opensky", "tracking", "satellite"):
|
|
for fname in files:
|
|
assert needle not in fname.lower(), \
|
|
f"unexpected env adapter file {fname!r} hints at a tracking adapter"
|
|
|
|
|
|
# ---------- frontend placeholder invariant -------------------------------
|
|
|
|
|
|
def test_environment_tsx_tracking_family_has_only_the_satpass_preview():
|
|
"""Environment.tsx FAMILIES entry for 'tracking' must have adapters
|
|
limited to the pre-existing ['satpass'] preview grouping -- it must
|
|
NOT gain any actual Phase-7 tracking adapter (aprs/adsb/opensky/etc).
|
|
|
|
This guard originally required adapters=[] outright, but Environment.tsx
|
|
has grouped the native satpass (SGP4) adapter under the "Tracking" UI
|
|
section (icon: Satellite) since before this test's earliest visible
|
|
history -- satellite-pass tracking is thematically "tracking" for
|
|
display purposes, even though satpass has always had its OWN dedicated
|
|
backend registry toggle ("satpass", see
|
|
meshai/notifications/categories.py) rather than "tracking". All 7 other
|
|
guards in this file (zero Central subjects, zero ALERT_CATEGORIES
|
|
entries, zero native adapter files, etc.) confirm the backend-side
|
|
Phase-7 tracking family genuinely has not landed; only this test's
|
|
stricter-than-reality assumption about the frontend grouping was wrong.
|
|
If Phase 7 lands for real, update this test together with the new
|
|
ALERT_CATEGORIES entries + adapter files + composer glyphs.
|
|
"""
|
|
tsx = Path("dashboard-frontend/src/pages/Environment.tsx")
|
|
if not tsx.is_file():
|
|
pytest.skip("Environment.tsx not present in this working tree")
|
|
text = tsx.read_text()
|
|
# Look for the FAMILIES line for tracking; the adapter list must be
|
|
# limited to the known satpass preview entry.
|
|
assert "key: 'tracking'" in text or 'key: "tracking"' in text, \
|
|
"Environment.tsx FAMILIES is missing the tracking placeholder entry"
|
|
# Pattern: `key: 'tracking', label: 'Tracking', icon: Satellite, adapters: [...]`
|
|
# Accept any quote style + minor formatting tolerance.
|
|
import re
|
|
m = re.search(
|
|
r"""key:\s*['"]tracking['"]\s*,\s*"""
|
|
r"""label:\s*['"]Tracking['"]\s*,\s*"""
|
|
r"""icon:\s*\w+\s*,\s*"""
|
|
r"""adapters:\s*\[([^\]]*)\]""",
|
|
text, re.DOTALL,
|
|
)
|
|
assert m, (
|
|
"Environment.tsx FAMILIES tracking entry not found in the expected shape"
|
|
)
|
|
adapters = {a.strip().strip("'\"") for a in m.group(1).split(",") if a.strip()}
|
|
assert adapters == {"satpass"}, (
|
|
f"Environment.tsx tracking-family adapter list is {sorted(adapters)!r}, "
|
|
"expected only the pre-existing {'satpass'} preview entry. "
|
|
"If you're landing Phase 7, update this test together with the "
|
|
"new ALERT_CATEGORIES entries + adapter files + composer glyphs."
|
|
)
|
|
|
|
|
|
# ---------- safety: no orphan routing into tracking ----------------------
|
|
|
|
|
|
def test_no_prefix_fallback_routes_to_tracking():
|
|
"""The _TOGGLE_PREFIX_FALLBACK chain in categories.py has no rule that
|
|
silently routes unknown categories to toggle='tracking'. Adding such
|
|
a rule without paired registry entries would create orphan tracking
|
|
events -- the v0.5.7 audit purity rule (every emitted = selectable)
|
|
forbids this."""
|
|
from meshai.notifications.categories import _TOGGLE_PREFIX_FALLBACK
|
|
for prefix, toggle in _TOGGLE_PREFIX_FALLBACK:
|
|
assert toggle != "tracking", \
|
|
f"prefix-fallback {prefix!r} -> tracking without registry entries"
|