mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-04 14:25:08 +00:00
* refactor(plugins): remove the no-op PluginHealthMonitor Its monitor loop did nothing (`if callbacks: pass`), register_health_check had no callers and api_v3.health_monitor was never read by any route. The live health data comes from PluginHealthTracker, which is untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(store): drop the never-set uninstall tombstones Nothing in production called mark_recently_uninstalled, so the reconciler's was_recently_uninstalled check was always False. The persistent uninstall registry is what actually stops resurrection; the reconciler test now exercises that gate instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(common): delete unused config/display/game helpers, utils and error_handler Nothing in core, the web UI, scripts or the plugin monorepo imports config_helper, display_helper, game_helper, utils or error_handler; only their own tests did. The error_handler re-exports leave src.common's __all__; APIHelper, TextHelper, ScrollHelper, LogoHelper and the adaptive layout exports are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(config): drop ConfigService's unused versioning and save API ConfigVersion, get_version/get_version_history/get_version_config, rollback, save_config, reload, get_plugin_config and the backward-compat load_config/get_config_path/get_secrets_path had no callers. The display controller only uses get_config, subscribe, unsubscribe and shutdown, plus the file watcher. Change detection now compares against the current checksum instead of the last history entry. The subscriber tests asserted `callback.called or True`; they now reload the way the watcher does and assert the notification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(plugins): drop unread plugin state history and callbacks plugin_state.PluginStateManager kept a bounded per-plugin transition history that only get_state_history (tests only) read; get_state_info reports a separate lifetime count, which stays. set_error_info and record_display had no callers, and set_state_with_error's `error` argument only fed the history. The web-side state_manager.PluginStateManager loses subscribe_to_state_changes, _notify_callbacks, set_plugin_error and get_state_version, none of which had callers; with no subscribers the old-state copy in update_plugin_state went with them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(plugins): remove unused PluginManager methods and attribute guards update_all_plugins was only called by a test (the display loop uses run_scheduled_updates); get_plugin_health_metrics, get_plugin_resource_metrics and get_plugin_state had no callers; and plugin_modules was written but never read. plugin_directories is now initialised in __init__, so the hasattr() guards around it go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(plugins): remove unused executor, loader, store and package helpers - PluginExecutor.execute_safe: no callers. - PluginLoader._parse_semver: only its own tests; compatibility.parse_semver is the live copy and test_compatibility.py already covers it. - PluginStoreManager.get_installed_plugin_info: no callers. - PluginResourceMonitor._local: never read. - src.plugin_system.get_store_manager and __api_version__: no importers in core, scripts or the plugin monorepo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(wifi): stop storing Wi-Fi passwords in wifi_config.json WiFiManager appended every joined network's SSID and password, in plaintext, to saved_networks in config/wifi_config.json, and nothing (web UI, backup restore, scripts) ever read them back: NetworkManager keeps its own credentials. The writes are gone, and loading the config now drops any saved_networks key and rewrites the file, so passwords already on disk are scrubbed. Also removes _check_dnsmasq_conflict (never called) and _detect_trixie, whose result only reached one log line, along with the NM_CONNECTIONS_PATHS constant only it used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(display): remove unreachable and unused DisplayController code - _follower_rebuild_scroll_image: never called. - mode_duration (never read) and last_mode_change (write-only). - The `chosen_cap <= 0` branch: chosen_cap is either the minimum of caps already filtered to > 0 or DEFAULT_DYNAMIC_DURATION_CAP (180). - The `max_duration < min_duration` branch directly after `max_duration = max(min_duration, max_duration)`. - The circuit-breaker branch's `display_result = False` and `manager_to_display = None`: the first is overwritten a few lines later, the second is already None there. - The bool-to-bool conversion of execute_display's result, which is always a bool. - The `loaded_plugins` lookup in _update_modules: PluginManager has no such attribute, so it always fell through to `plugins`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(vegas): remove unused config update, boundary finder and refresh VegasModeConfig.update had no callers outside its own tests (the coordinator rebuilds the config with from_config on a change); geometry.find_item_boundary and StreamManager._refresh_plugin_content had no callers at all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(run): drop the debug block that pretended to import the plugin system In debug mode run.py put src/plugin_system itself on sys.path and printed "Plugin system import successful" without importing anything. Nothing imports plugin_system modules by bare name, so the path entry did nothing either. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: delete tests that test nothing - test/plugins/test_{basketball_scoreboard,calendar,clock_simple, odds_ticker,soccer_scoreboard,text_display}.py skip everywhere the named plugins are not installed, including CI (LEDMATRIX_PLUGINS_DIR holds only the fixture plugin); test_plugin_matrix.py already covers every discovered plugin. Their PluginTestBase and the fixtures only it used (plugins_dir, mock_display_manager, mock_cache_manager, mock_plugin_manager, base_plugin_config in test/plugins/conftest.py) go with them. - test_plugin_system.py: test_discover_plugins (body was `pass`) and test_dependency_check (a comment), plus the test_plugin_manager fixture only the former requested. - test_display_manager.py: test_draw_image asserted that an image it had just assigned was not None. - test_display_controller.py: the rotation and schedule-override tests re-implemented the run-loop arithmetic inline and asserted on their own result without calling the controller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: expect one plugin_last_update success stamp after update_all_plugins EveryStampRecordsACompletion required at least two success-path stamps; the second was update_all_plugins, removed as test-only. The worker and synchronous paths share the remaining stamp in _execute_update_now, and the check that every stamp calls _note_update_completed is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
222 lines
8.5 KiB
Python
222 lines
8.5 KiB
Python
"""Tests that startup does not wait indefinitely for plugins to fetch data.
|
|
|
|
DisplayController.__init__ calls _update_modules() once, to populate plugin
|
|
data before the first frame. It walks every loaded plugin in turn, and each
|
|
update blocks the calling thread for up to the executor's 30s timeout, so the
|
|
uncapped total is the sum of every slow plugin on the system.
|
|
|
|
Profiled on a live rig with py-spy, the main thread sat 9.34s in
|
|
|
|
display_controller._update_modules
|
|
-> plugin_executor.execute_update
|
|
-> execute_with_timeout -> threading.join
|
|
|
|
and the controller's own log put the full pass at 82 seconds on the worst
|
|
boot measured (55 and 26 on the two before). The panel shows nothing for all
|
|
of it.
|
|
|
|
Nothing is lost by stopping early: a plugin that has never updated is
|
|
immediately due, so run_scheduled_updates() collects it seconds later with the
|
|
display already running.
|
|
"""
|
|
|
|
import os
|
|
import time
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
|
|
# display_controller imports display_manager, which binds the hardware
|
|
# rgbmatrix module unless EMULATOR=true is set before import (same convention
|
|
# as test_display_controller_vegas_tick.py).
|
|
os.environ.setdefault("EMULATOR", "true")
|
|
|
|
from src.display_controller import ( # noqa: E402
|
|
DisplayController, _INITIAL_UPDATE_BUDGET_SECONDS,
|
|
_MIN_INITIAL_UPDATE_TIMEOUT_SECONDS)
|
|
|
|
|
|
class FakeExecutor:
|
|
"""Records which plugins were updated, and can make some of them slow."""
|
|
|
|
def __init__(self, cost=0.0, slow=()):
|
|
self.updated = []
|
|
self.cost = cost
|
|
self.slow = set(slow)
|
|
|
|
def execute_update(self, plugin, plugin_id, timeout=None):
|
|
self.updated.append(plugin_id)
|
|
if plugin_id in self.slow:
|
|
time.sleep(self.cost)
|
|
return True
|
|
|
|
|
|
@pytest.fixture
|
|
def tiny_floor(monkeypatch):
|
|
"""Shrink the "worth starting" floor so timing tests stay quick."""
|
|
import src.display_controller as mod
|
|
monkeypatch.setattr(mod, "_MIN_INITIAL_UPDATE_TIMEOUT_SECONDS", 0.01)
|
|
|
|
|
|
def _controller(plugin_ids, executor):
|
|
c = DisplayController.__new__(DisplayController)
|
|
c.plugin_manager = Mock()
|
|
c.plugin_manager.plugins = {pid: Mock() for pid in plugin_ids}
|
|
c.plugin_manager.plugin_executor = executor
|
|
c.plugin_manager.plugin_last_update = {}
|
|
c.plugin_manager.health_tracker = None
|
|
return c
|
|
|
|
|
|
class TestTheBudgetIsRespected:
|
|
def test_without_a_deadline_every_plugin_is_updated(self):
|
|
ex = FakeExecutor()
|
|
_controller(['a', 'b', 'c'], ex)._update_modules()
|
|
assert ex.updated == ['a', 'b', 'c']
|
|
|
|
def test_a_passed_deadline_stops_the_pass(self):
|
|
ex = FakeExecutor()
|
|
_controller(['a', 'b', 'c'], ex)._update_modules(deadline=time.time() - 1)
|
|
assert ex.updated == [], "updated %r after the deadline" % ex.updated
|
|
|
|
def test_slow_plugins_do_not_drag_in_the_rest(self, tiny_floor):
|
|
# One plugin burns the whole budget; the remainder must be left alone
|
|
# rather than each adding its own wait.
|
|
ex = FakeExecutor(cost=0.3, slow={'slow'})
|
|
c = _controller(['slow'] + ['p%d' % i for i in range(20)], ex)
|
|
started = time.time()
|
|
c._update_modules(deadline=started + 0.2)
|
|
elapsed = time.time() - started
|
|
|
|
assert ex.updated == ['slow'], "updated %r" % ex.updated
|
|
# Bounded by the one in-flight update, not by twenty more.
|
|
assert elapsed < 1.0, "%.2fs" % elapsed
|
|
|
|
def test_a_generous_deadline_still_gets_everything(self):
|
|
ex = FakeExecutor()
|
|
c = _controller(['a', 'b', 'c'], ex)
|
|
c._update_modules(deadline=time.time() + 30)
|
|
assert ex.updated == ['a', 'b', 'c']
|
|
|
|
def test_the_deadline_is_checked_before_each_plugin(self, tiny_floor):
|
|
# Not just once up front: the budget can be spent partway through.
|
|
ex = FakeExecutor(cost=0.15, slow={'a', 'b', 'c', 'd'})
|
|
c = _controller(['a', 'b', 'c', 'd'], ex)
|
|
c._update_modules(deadline=time.time() + 0.2)
|
|
assert 0 < len(ex.updated) < 4, "updated %r" % ex.updated
|
|
|
|
|
|
class TestThePassIsBoundedInPractice:
|
|
def test_the_last_plugin_cannot_overrun_the_budget(self):
|
|
# Checking the deadline before each plugin is not enough on its own:
|
|
# one that starts with a moment left could still block for the
|
|
# executor's full timeout. On the rig that turned a 20s budget into a
|
|
# 31.8s pass, so the remaining budget is passed down as the timeout.
|
|
seen = []
|
|
|
|
class Executor:
|
|
def execute_update(self, plugin, plugin_id, timeout=None):
|
|
seen.append(timeout)
|
|
return True
|
|
|
|
c = _controller(['a', 'b', 'c'], Executor())
|
|
deadline = time.time() + 5
|
|
c._update_modules(deadline=deadline)
|
|
|
|
assert seen and all(t is not None for t in seen), seen
|
|
assert all(t <= 5.01 for t in seen), seen
|
|
# The exact remainder, never clamped up: clamping would let the pass
|
|
# run past its deadline. Anything below the floor is deferred instead,
|
|
# so what does start always has a usable slot.
|
|
assert all(t >= _MIN_INITIAL_UPDATE_TIMEOUT_SECONDS for t in seen), seen
|
|
|
|
def test_without_a_deadline_the_executor_default_is_left_alone(self):
|
|
seen = []
|
|
|
|
class Executor:
|
|
def execute_update(self, plugin, plugin_id, timeout=None):
|
|
seen.append(timeout)
|
|
return True
|
|
|
|
_controller(['a'], Executor())._update_modules()
|
|
assert seen == [None], seen
|
|
|
|
|
|
class TestTheBudgetItself:
|
|
def test_it_is_short_enough_to_be_worth_having(self):
|
|
# The measured uncapped worst case was 82s; a budget near that would
|
|
# not bound anything.
|
|
assert _INITIAL_UPDATE_BUDGET_SECONDS <= 30
|
|
|
|
def test_it_is_long_enough_for_a_quick_plugin_or_two(self):
|
|
assert _INITIAL_UPDATE_BUDGET_SECONDS >= 5
|
|
|
|
|
|
class TestNothingIsSilentlyDropped:
|
|
def test_deferred_plugins_are_named_in_the_log(self, caplog):
|
|
ex = FakeExecutor()
|
|
c = _controller(['a', 'b'], ex)
|
|
with caplog.at_level('INFO'):
|
|
c._update_modules(deadline=time.time() - 1)
|
|
text = "\n".join(r.getMessage() for r in caplog.records)
|
|
assert 'a' in text and 'b' in text, text
|
|
assert 'budget' in text.lower(), text
|
|
|
|
def test_nothing_is_logged_when_all_of_them_ran(self, caplog):
|
|
ex = FakeExecutor()
|
|
c = _controller(['a'], ex)
|
|
with caplog.at_level('INFO'):
|
|
c._update_modules(deadline=time.time() + 30)
|
|
assert not any('budget' in r.getMessage().lower() for r in caplog.records)
|
|
|
|
|
|
class TestItDoesNotBreakTheOrdinaryPaths:
|
|
def test_no_plugin_manager_is_harmless(self):
|
|
c = DisplayController.__new__(DisplayController)
|
|
c.plugin_manager = None
|
|
c._update_modules(deadline=time.time() - 1) # must not raise
|
|
|
|
def test_an_empty_plugin_set_is_harmless(self):
|
|
ex = FakeExecutor()
|
|
_controller([], ex)._update_modules(deadline=time.time() + 5)
|
|
assert ex.updated == []
|
|
|
|
|
|
class TestTooLittleBudgetDefersRatherThanClamps:
|
|
def test_a_plugin_starting_below_the_floor_is_deferred(self):
|
|
ex = FakeExecutor()
|
|
c = _controller(['a'], ex)
|
|
# Just under the floor: previously this was clamped up to the floor and
|
|
# run anyway, which pushed the pass past its deadline.
|
|
c._update_modules(
|
|
deadline=time.time() + _MIN_INITIAL_UPDATE_TIMEOUT_SECONDS - 0.05)
|
|
assert ex.updated == [], "started a plugin it could not give a slot to"
|
|
|
|
def test_a_plugin_starting_above_the_floor_still_runs(self):
|
|
ex = FakeExecutor()
|
|
c = _controller(['a'], ex)
|
|
c._update_modules(
|
|
deadline=time.time() + _MIN_INITIAL_UPDATE_TIMEOUT_SECONDS + 1)
|
|
assert ex.updated == ['a']
|
|
|
|
def test_the_timeout_is_the_remainder_not_the_floor(self):
|
|
seen = []
|
|
|
|
class Executor:
|
|
def execute_update(self, plugin, plugin_id, timeout=None):
|
|
seen.append(timeout)
|
|
return True
|
|
|
|
c = _controller(['a'], Executor())
|
|
c._update_modules(deadline=time.time() + 9)
|
|
assert seen and 8.5 <= seen[0] <= 9.01, seen
|
|
|
|
def test_the_pass_cannot_outlast_its_deadline(self, tiny_floor):
|
|
# Every plugin sleeps well past the budget; the deferral keeps the
|
|
# whole pass inside it rather than overrunning by a floor's worth.
|
|
ex = FakeExecutor(cost=0.4, slow={'a', 'b', 'c', 'd', 'e'})
|
|
c = _controller(['a', 'b', 'c', 'd', 'e'], ex)
|
|
started = time.time()
|
|
c._update_modules(deadline=started + 0.5)
|
|
assert time.time() - started < 1.2, "%.2fs" % (time.time() - started)
|