Files
meshcore-bot/tests
agessaman f68da5287c fix(web-viewer): derive neighbours and hop distance from path evidence
307 direct neighbours was not plausible, and it was not real.

complete_contact_tracking.hop_count claims 800 zero-hop contacts. Only
68 of them have any one-hop path in observed_paths to corroborate that.
Their stored SNR piles up in a 1.5 dB band — 655 of 800 between 11.25
and 12.75 dB — and their RSSI clusters at -39..-48 dBm. Hundreds of
radios at different distances and terrain cannot land in a 10 dB window.
That is the signature of one strong local link being recorded against
every node whose traffic happened to arrive through it. Their return
paths agree: these "direct" contacts have out_path_len of 3 to 11.

The writer's intent is sound — repeater_manager only stores RSSI/SNR
when signal_info reports hops == 0 — so the field being fed to it does
not mean what the surrounding code assumes. Left as is; this change
stops the dashboard depending on it.

Neighbour membership now comes from path evidence: an advert whose
path_length equals its bytes_per_hop travelled exactly one hop. That
yields 38 nodes in 24h and 124 in 7d, with a plausible spread. Signal is
shown only where the path evidence and the stored hop count agree, which
is 5 and 12 nodes respectively; the rest read "no signal reading" rather
than borrowing a measurement taken on somebody else's link. A 24h/7d
selector bounds the window, capped well under observed_paths' 90-day
retention because a month-old link says nothing about today.

Separately, this fixes a bug I introduced. path_length is a BYTE count,
and with 2- or 3-byte hop encoding a 3-hop path is 6 or 9 bytes long. The
path-length histogram plotted that raw value on an axis readers would
take as hops, overstating distance two- to threefold on a mesh that is
~95% multibyte. It is replaced by a single hops-away chart computed as
path_length / bytes_per_hop, which also retires the histogram built on
the untrustworthy stored hop count. The result is unimodal, peaking at 3
hops and decaying — the shape a mesh should have, and not the bimodal
one the old chart drew.
2026-07-29 22:23:43 -07:00
..

MeshCore Bot Test Suite

This directory contains the test suite for the MeshCore Bot, focusing on graph-based path guessing functionality.

Structure

tests/
├── README.md              # This file
├── conftest.py            # Pytest fixtures and configuration
├── helpers.py             # Test data factories and helper functions
├── unit/                  # Unit tests (isolated, with mocks)
│   ├── test_mesh_graph_edges.py
│   ├── test_mesh_graph_validation.py
│   ├── test_mesh_graph_scoring.py
│   ├── test_mesh_graph_multihop.py
│   └── test_path_command_graph_selection.py
└── integration/          # Integration tests (with real database)
    └── test_path_resolution.py

Running Tests

Run all tests

pytest

Run only unit tests

pytest tests/unit/

Run only integration tests

pytest tests/integration/

Run specific test file

pytest tests/unit/test_mesh_graph_edges.py

Run specific test

pytest tests/unit/test_mesh_graph_edges.py::TestMeshGraphEdges::test_add_new_edge

Run with coverage

pytest --cov=modules --cov-report=html --cov-report=term-missing

Run with verbose output

pytest -v

Run with markers

pytest -m unit          # Run only unit tests
pytest -m integration  # Run only integration tests
pytest -m slow          # Run slow tests

Test Coverage

Unit Tests

test_mesh_graph_edges.py (15 tests)

Tests for MeshGraph edge management:

  • Adding new edges
  • Updating existing edges
  • Public key handling
  • Hop position tracking
  • Geographic distance
  • Edge queries (get, has, outgoing, incoming)
  • Prefix normalization

test_mesh_graph_validation.py (12 tests)

Tests for path validation:

  • Path segment validation
  • Confidence calculation
  • Recency checks
  • Bidirectional edge validation
  • Full path validation
  • Minimum observations filtering

test_mesh_graph_scoring.py (11 tests)

Tests for candidate scoring:

  • Score calculation with various edge combinations
  • Bidirectional bonuses
  • Hop position matching
  • Geographic distance bonuses
  • Minimum observations filtering

test_mesh_graph_multihop.py (12 tests)

Tests for multi-hop path inference:

  • 2-hop and 3-hop path finding
  • Intermediate node discovery
  • Minimum observations filtering
  • Bidirectional path bonuses
  • Score reduction for longer paths

test_path_command_graph_selection.py (8 tests)

Tests for PathCommand._select_repeater_by_graph:

  • Direct edge selection
  • Stored public key bonus
  • Star bias multiplier
  • Multi-hop inference
  • Confidence conversion

Integration Tests

test_path_resolution.py (5 tests)

End-to-end tests for full path resolution:

  • Path resolution with graph edges from database
  • Prefix collision resolution using graph data
  • Edge persistence across graph restarts
  • Graph vs geographic selection
  • Real-world multi-hop scenarios

Test Fixtures

Fixtures are defined in conftest.py:

  • mock_logger: Mock logger for testing
  • test_config: Test configuration with Path_Command settings
  • test_db: In-memory SQLite database for testing
  • mock_bot: Mock bot instance with all necessary attributes
  • mesh_graph: Clean MeshGraph instance for testing
  • populated_mesh_graph: MeshGraph instance with sample edges

Test Helpers

Helper functions in helpers.py:

  • create_test_repeater(): Factory for creating test repeater data
  • create_test_edge(): Factory for creating test edge data
  • create_test_path(): Factory for creating test path data
  • populate_test_graph(): Helper to populate a graph with test edges

Writing New Tests

Unit Test Example

import pytest
from tests.helpers import create_test_edge

@pytest.mark.unit
class TestMyFeature:
    def test_my_feature(self, mesh_graph):
        """Test description."""
        mesh_graph.add_edge('01', '7e')
        assert mesh_graph.has_edge('01', '7e')

Integration Test Example

import pytest

@pytest.mark.integration
class TestMyIntegration:
    def test_my_integration(self, mock_bot, test_db):
        """Test description."""
        # Use real database and bot components
        pass

Test Markers

Tests are marked with:

  • @pytest.mark.unit: Unit tests (isolated, with mocks)
  • @pytest.mark.integration: Integration tests (with real database)
  • @pytest.mark.slow: Slow-running tests

Dependencies

Test dependencies are in requirements.txt:

  • pytest>=7.0.0
  • pytest-asyncio>=0.21.0
  • pytest-mock>=3.10.0
  • pytest-cov>=4.0.0

Configuration

Pytest configuration is in pytest.ini:

  • Test discovery patterns
  • Async test support
  • Output options
  • Test markers

Notes

  • Unit tests use in-memory SQLite databases for speed
  • Integration tests may use real database connections
  • All tests should be deterministic and not depend on external services
  • Tests should clean up after themselves (fixtures handle this automatically)