-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat(plugins): apply config edits live without a display restart (4 plugins) #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rpierce99
wants to merge
1
commit into
ChuckBuilds:main
Choose a base branch
from
rpierce99:feat/plugin-config-hot-reload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+843
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Regression test: baseball-scoreboard applies config edits live. | ||
|
|
||
| Before this fix the plugin had no on_config_change override, so the base | ||
| BasePlugin only swapped self.config: league enables, durations, live priority, | ||
| display-mode settings, the per-league managers and the rotation mode list all | ||
| kept their startup values until a display restart. This test fails against the | ||
| base behavior and passes once the plugin re-derives state on config change. | ||
|
|
||
| Leagues are left disabled so no network managers are constructed, but the full | ||
| re-derive / rebuild path still runs. | ||
|
|
||
| Run with the core venv from within a LEDMatrix tree, or set LEDMATRIX_CORE: | ||
| LEDMATRIX_CORE=/path/to/LEDMatrix .venv/bin/python \ | ||
| plugins/baseball-scoreboard/test_config_reload.py | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| HERE = os.path.dirname(os.path.abspath(__file__)) | ||
| sys.path.insert(0, HERE) | ||
|
|
||
| _core = os.environ.get("LEDMATRIX_CORE") | ||
| if _core and _core not in sys.path: | ||
| sys.path.insert(0, _core) | ||
|
|
||
| from manager import BaseballScoreboardPlugin # noqa: E402 | ||
|
|
||
| _passed = 0 | ||
| _failed = 0 | ||
|
|
||
|
|
||
| def check(cond, msg): | ||
| global _passed, _failed | ||
| if cond: | ||
| _passed += 1 | ||
| print(f" PASS: {msg}") | ||
| else: | ||
| _failed += 1 | ||
| print(f" FAIL: {msg}") | ||
|
|
||
|
|
||
| class _Matrix: | ||
| width = 128 | ||
| height = 32 | ||
|
|
||
|
|
||
| class _DisplayManager: | ||
| matrix = _Matrix() | ||
|
|
||
|
|
||
| def _make_plugin(config): | ||
| return BaseballScoreboardPlugin( | ||
| "baseball-scoreboard", | ||
| config, | ||
| display_manager=_DisplayManager(), | ||
| cache_manager=object(), | ||
| plugin_manager=object(), | ||
| ) | ||
|
|
||
|
|
||
| def test_on_config_change_applies_live(): | ||
| print("[baseball-scoreboard on_config_change]") | ||
| plugin = _make_plugin( | ||
| { | ||
| "display_duration": 30, | ||
| "mlb": {"enabled": False, "live_priority": False, | ||
| "display_modes": {"live_display_mode": "switch"}}, | ||
| } | ||
| ) | ||
| check(plugin.display_duration == 30.0, "initial display_duration derived") | ||
| check(plugin.mlb_live_priority is False, "initial mlb live_priority derived") | ||
| check(plugin._display_mode_settings["mlb"]["live"] == "switch", "initial display mode setting derived") | ||
|
|
||
| # Prime cycling state so we can confirm it is reset on change. | ||
| plugin.current_mode_index = 5 | ||
|
|
||
| plugin.on_config_change( | ||
| { | ||
| "display_duration": 45, | ||
| "game_display_duration": 20, | ||
| "mlb": { | ||
| "enabled": False, | ||
| "live_priority": True, | ||
| "display_modes": {"live_display_mode": "scroll"}, | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| check(plugin.display_duration == 45.0, "display_duration updated live") | ||
| check(plugin.game_display_duration == 20.0, "game_display_duration updated live") | ||
| check(plugin.mlb_live_priority is True, "mlb live_priority updated live") | ||
| check(plugin._display_mode_settings["mlb"]["live"] == "scroll", "display mode setting updated live") | ||
| check(plugin.current_mode_index == 0, "mode cycling reset") | ||
| check(isinstance(plugin.modes, list) and len(plugin.modes) > 0, "rotation modes rebuilt without crashing") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| test_on_config_change_applies_live() | ||
| print(f"\n{_passed} passed, {_failed} failed") | ||
| sys.exit(1 if _failed else 0) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep runtime enable flags consistent during partial config reloads.
Line 278 preserves prior state when
enabledis omitted, but Line 279 hard-defaults toTrue. That can unintentionally re-enable runtime behavior on partial config payloads.Suggested fix
🤖 Prompt for AI Agents