mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-18 04:49:13 +00:00
fix(api-v3): address CodeRabbit findings on the blueprint split
- _redact_credentials: blank scalar descendants of objects reached
through a credential-owned list (e.g. tokens: [{"value": "secret"}])
regardless of field name -- the existing name-based walk only
protected direct dict values under a credential key, not list items.
- wifi.py: reject enabled/force/auto_enable_ap_mode values
_parse_bool_ish can't recognize (400) instead of silently treating
them as False, which could disable Wi-Fi or the radio itself.
- Starlark manifest locking: lock a stable manifest.json.lock sidecar
instead of manifest.json itself, in both the standalone route path
(_starlark_manifest_lock) and the plugin path
(StarlarkAppsPlugin._save_manifest / _update_manifest_safe).
manifest.json is replaced by an atomic rename on every write, which
swaps in a fresh inode; a lock held on the old inode does not
exclude a second locker that opens the path afresh right after the
rename and gets the new inode, so two writers could race despite
each holding "a lock". A sidecar that no write ever touches always
resolves to the same inode for every locker.
Skipped as stale: the "serialize the complete manifest
read-modify-write" finding at api_v3/__init__.py -- every standalone
handler that calls _write_starlark_manifest is already wrapped in
_starlark_manifest_lock() on this branch.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ frame for the whole display_duration instead of rotating on -- the same class
|
||||
of defect as a display() that returns None.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
import types
|
||||
from pathlib import Path
|
||||
@@ -197,6 +198,50 @@ class TestInstalledAppsTakeTurns:
|
||||
assert p.display(force_clear=True) is False
|
||||
|
||||
|
||||
class TestManifestLockSidecarIsStable:
|
||||
"""_save_manifest and _update_manifest_safe must lock a sidecar file that
|
||||
a manifest write never replaces. manifest.json itself is swapped for a
|
||||
fresh inode by every atomic write (temp file + rename); a lock taken on
|
||||
manifest.json directly would not exclude a second locker whose fresh
|
||||
os.open() lands on that new inode right after a write, so two writers
|
||||
could still race each other despite each believing it held the lock.
|
||||
web_interface._starlark_manifest_lock (web_interface/blueprints/api_v3)
|
||||
must lock this same sidecar name for that guarantee to hold across both
|
||||
the plugin-loaded and standalone paths.
|
||||
"""
|
||||
|
||||
def _plugin_with_manifest_dir(self, manager_module, tmp_path):
|
||||
p = _plugin(manager_module)
|
||||
p.manifest_file = tmp_path / "manifest.json"
|
||||
p.manifest_lock_file = tmp_path / "manifest.json.lock"
|
||||
return p
|
||||
|
||||
def test_the_lock_sidecar_is_not_the_manifest_file(self, manager_module, tmp_path):
|
||||
p = self._plugin_with_manifest_dir(manager_module, tmp_path)
|
||||
assert p.manifest_lock_file != p.manifest_file
|
||||
assert p.manifest_lock_file.name == "manifest.json.lock"
|
||||
|
||||
def test_the_locked_files_inode_survives_repeated_writes(self, manager_module, tmp_path):
|
||||
p = self._plugin_with_manifest_dir(manager_module, tmp_path)
|
||||
|
||||
assert p._save_manifest({"apps": {}})
|
||||
lock_ino_before = p.manifest_lock_file.stat().st_ino
|
||||
|
||||
for app_id in ("one", "two", "three"):
|
||||
def _update(manifest, app_id=app_id):
|
||||
manifest.setdefault("apps", {})[app_id] = {"enabled": True}
|
||||
assert p._update_manifest_safe(_update)
|
||||
|
||||
lock_ino_after = p.manifest_lock_file.stat().st_ino
|
||||
assert lock_ino_after == lock_ino_before, (
|
||||
"the locked file's inode changed across writes -- a locker that "
|
||||
"opened it before this write and one that opens it after would "
|
||||
"no longer contend for the same lock")
|
||||
|
||||
manifest = json.loads(p.manifest_file.read_text())
|
||||
assert set(manifest["apps"]) == {"one", "two", "three"}
|
||||
|
||||
|
||||
class TestAnimationsRunAtFrameRate:
|
||||
def test_the_plugin_asks_for_the_high_fps_loop(self, manager_module):
|
||||
"""The controller reads this attribute; a multi-frame app is otherwise
|
||||
|
||||
Reference in New Issue
Block a user