mirror of
https://github.com/ruvnet/RuView
synced 2026-07-04 14:23:18 +00:00
81cc241b9e
The Rust port at v2/ has been the primary codebase since the rename in #427. The Python implementation at v1/ is no longer the active target; the only load-bearing path is the deterministic proof bundle at v1/data/proof/ (per ADR-011 / ADR-028 witness verification). Move the whole Python tree into archive/v1/ and document the policy in archive/README.md: no new features, bug fixes only when they affect a still-load-bearing path (currently just the proof), CI continues to verify the proof on every push and PR. Path references updated in 26 files via path-pattern sed (only matches v1/<known-child> patterns, never bare v1 or API URLs like /api/v1/). Two double-prefix typos (archive/archive/v1/) caught and hand-fixed in verify-pipeline.yml and ADR-011. Validated: - Python proof verify.py imports cleanly at archive/v1/data/proof/ (numpy/scipy still required; CI installs requirements-lock.txt from archive/v1/ now) - cargo test --workspace --no-default-features → 1,539 passed, 0 failed, 8 ignored (unaffected by Python tree relocation) - ESP32-S3 on COM7 untouched (no firmware paths changed) After-merge: contributors should re-run any local `python v1/...` commands as `python archive/v1/...` (CLAUDE.md and CHANGELOG already updated).
66 lines
2.9 KiB
Python
66 lines
2.9 KiB
Python
"""Tests for HardwareService."""
|
|
|
|
import pytest
|
|
from unittest.mock import MagicMock, AsyncMock, patch
|
|
|
|
|
|
class TestHardwareServiceInit:
|
|
def test_init(self, mock_settings, mock_domain_config):
|
|
mock_settings.mock_hardware = True
|
|
with patch("src.services.hardware_service.RouterInterface"):
|
|
from src.services.hardware_service import HardwareService
|
|
svc = HardwareService(mock_settings, mock_domain_config)
|
|
assert svc.is_running is False
|
|
assert svc.stats["total_samples"] == 0
|
|
assert svc.stats["connected_routers"] == 0
|
|
|
|
def test_stats_defaults(self, mock_settings, mock_domain_config):
|
|
mock_settings.mock_hardware = True
|
|
with patch("src.services.hardware_service.RouterInterface"):
|
|
from src.services.hardware_service import HardwareService
|
|
svc = HardwareService(mock_settings, mock_domain_config)
|
|
assert svc.stats["successful_samples"] == 0
|
|
assert svc.stats["failed_samples"] == 0
|
|
assert svc.stats["last_sample_time"] is None
|
|
|
|
|
|
class TestHardwareServiceLifecycle:
|
|
@pytest.mark.asyncio
|
|
async def test_start(self, mock_settings, mock_domain_config):
|
|
mock_settings.mock_hardware = True
|
|
with patch("src.services.hardware_service.RouterInterface"):
|
|
from src.services.hardware_service import HardwareService
|
|
svc = HardwareService(mock_settings, mock_domain_config)
|
|
svc._initialize_routers = AsyncMock()
|
|
svc._monitoring_loop = AsyncMock()
|
|
await svc.start()
|
|
assert svc.is_running is True
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_double_start_idempotent(self, mock_settings, mock_domain_config):
|
|
mock_settings.mock_hardware = True
|
|
with patch("src.services.hardware_service.RouterInterface"):
|
|
from src.services.hardware_service import HardwareService
|
|
svc = HardwareService(mock_settings, mock_domain_config)
|
|
svc._initialize_routers = AsyncMock()
|
|
svc._monitoring_loop = AsyncMock()
|
|
await svc.start()
|
|
await svc.start() # idempotent
|
|
assert svc.is_running is True
|
|
|
|
|
|
class TestHardwareServiceRouter:
|
|
def test_no_routers_on_init(self, mock_settings, mock_domain_config):
|
|
mock_settings.mock_hardware = True
|
|
with patch("src.services.hardware_service.RouterInterface"):
|
|
from src.services.hardware_service import HardwareService
|
|
svc = HardwareService(mock_settings, mock_domain_config)
|
|
assert len(svc.router_interfaces) == 0
|
|
|
|
def test_max_recent_samples(self, mock_settings, mock_domain_config):
|
|
mock_settings.mock_hardware = True
|
|
with patch("src.services.hardware_service.RouterInterface"):
|
|
from src.services.hardware_service import HardwareService
|
|
svc = HardwareService(mock_settings, mock_domain_config)
|
|
assert svc.max_recent_samples == 1000
|