Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions apps/predbat/tests/test_control_handoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,45 @@ def test_opt_out_and_invalid_opt_in_are_strict(self):
self.assertTrue(self.base.control_write_gate.snapshot()["closed"])


class TestControlDebugExport(unittest.TestCase):
"""Live controller objects must never enter shared debug/state serialization."""

def test_actual_debug_export_excludes_live_control_objects(self):
"""Keep debug downloads usable without traversing locks or credentials."""
from datetime import datetime, timezone
from tempfile import TemporaryDirectory

import yaml
from userinterface import UserInterface
from utils import is_debug_excluded_key

with TemporaryDirectory() as root:
base = SimpleNamespace(
now_utc=datetime.now(timezone.utc),
config_root=root,
config_root_p=root,
inverters=[],
CONFIG_ITEMS=[],
components=None,
args={},
minutes_now=42,
log=lambda *_args: None,
)
gate = make_gate()
service = ControlHandoffService(base, "synthetic-instance", "synthetic-boot", "https://example.invalid", "synthetic-private-service-credential")
service.gate = gate
base.control_write_gate = gate
base.control_handoff_service = service
text = UserInterface.create_debug_yaml(base, write_file=False)
debug = yaml.safe_load(text)
self.assertEqual(debug["minutes_now"], 42)
for name in ("control_write_gate", "control_handoff_service"):
self.assertTrue(is_debug_excluded_key(name))
self.assertNotIn(name, debug)
self.assertNotIn("synthetic-private-service-credential", text)
self.assertNotIn("python/object", text)


def run_control_handoff_tests(_predbat=None):
"""Run through Predbat's normal unit-test registry as well as unittest."""
suite = unittest.defaultTestLoader.loadTestsFromModule(__import__(__name__, fromlist=["_"]))
Expand Down
2 changes: 2 additions & 0 deletions apps/predbat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ def copy(self):
"ha_interface",
"components",
"coordinator",
"control_write_gate",
"control_handoff_service",
"prediction",
"logfile",
"predheat",
Expand Down
Loading