mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-17 20:39:13 +00:00
fix(plugins): reject bool and -inf hook results in dynamic interval
get_update_interval() ran bool through float() (bool is an int subclass, so True/False became 1.0/0.0) and only checked for +inf, not -inf. Both cases landed on the MIN_DYNAMIC_UPDATE_INTERVAL floor by coincidence instead of falling back to the static/manifest interval as invalid input should. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017Tst9cied2ri9bH4QRWa6H
This commit is contained in:
@@ -8,6 +8,7 @@ API Version: 1.0.0
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import math
|
||||||
import queue
|
import queue
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
@@ -793,6 +794,11 @@ class PluginManager:
|
|||||||
return None
|
return None
|
||||||
if requested is None:
|
if requested is None:
|
||||||
return None
|
return None
|
||||||
|
if isinstance(requested, bool):
|
||||||
|
self.logger.debug(
|
||||||
|
"get_update_interval() returned a bool for %s, which is not a number",
|
||||||
|
plugin_id)
|
||||||
|
return None
|
||||||
try:
|
try:
|
||||||
requested = float(requested)
|
requested = float(requested)
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
@@ -800,7 +806,7 @@ class PluginManager:
|
|||||||
"get_update_interval() returned %r for %s, which is not a number",
|
"get_update_interval() returned %r for %s, which is not a number",
|
||||||
requested, plugin_id)
|
requested, plugin_id)
|
||||||
return None
|
return None
|
||||||
if requested != requested or requested == float('inf'): # NaN / inf
|
if not math.isfinite(requested): # NaN / +inf / -inf
|
||||||
return None
|
return None
|
||||||
return max(requested, self.MIN_DYNAMIC_UPDATE_INTERVAL)
|
return max(requested, self.MIN_DYNAMIC_UPDATE_INTERVAL)
|
||||||
|
|
||||||
|
|||||||
@@ -98,10 +98,16 @@ class TestABrokenHookCannotStopUpdates:
|
|||||||
def test_a_non_numeric_hook_falls_back(self, manager, junk):
|
def test_a_non_numeric_hook_falls_back(self, manager, junk):
|
||||||
assert manager._get_plugin_update_interval("sports", _Plugin(wants=junk)) == 60.0
|
assert manager._get_plugin_update_interval("sports", _Plugin(wants=junk)) == 60.0
|
||||||
|
|
||||||
@pytest.mark.parametrize("junk", [float("nan"), float("inf")])
|
@pytest.mark.parametrize("junk", [float("nan"), float("inf"), float("-inf")])
|
||||||
def test_nan_and_infinity_fall_back(self, manager, junk):
|
def test_nan_and_infinity_fall_back(self, manager, junk):
|
||||||
assert manager._get_plugin_update_interval("sports", _Plugin(wants=junk)) == 60.0
|
assert manager._get_plugin_update_interval("sports", _Plugin(wants=junk)) == 60.0
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("junk", [True, False])
|
||||||
|
def test_a_bool_hook_falls_back(self, manager, junk):
|
||||||
|
"""bool is a subclass of int, so it must be rejected before float()
|
||||||
|
turns it into 0.0/1.0 and the floor silently swallows the mistake."""
|
||||||
|
assert manager._get_plugin_update_interval("sports", _Plugin(wants=junk)) == 60.0
|
||||||
|
|
||||||
|
|
||||||
class TestTheFloor:
|
class TestTheFloor:
|
||||||
"""A plugin asking for 0 would be re-entered on every tick of the render
|
"""A plugin asking for 0 would be re-entered on every tick of the render
|
||||||
|
|||||||
Reference in New Issue
Block a user