Add production safety controls
This commit is contained in:
@@ -9,7 +9,7 @@ def test_addon_config_declares_future_addon() -> None:
|
||||
config = yaml.safe_load(Path("addon/config.yaml").read_text(encoding="utf-8"))
|
||||
|
||||
assert config["slug"] == "sillyhome_future"
|
||||
assert config["version"] == "2.0.0-alpha.8"
|
||||
assert config["version"] == "2.0.0-alpha.9"
|
||||
assert config["ingress"] is True
|
||||
assert config["ingress_port"] == 8099
|
||||
assert config["homeassistant_api"] is True
|
||||
|
||||
@@ -19,7 +19,7 @@ def test_health_and_backup_roundtrip(tmp_path, monkeypatch) -> None: # type: ig
|
||||
restore = client.post("/v2/backup/restore", json=backup.json())
|
||||
|
||||
assert health.status_code == 200
|
||||
assert health.json()["version"] == "2.0.0-alpha.8"
|
||||
assert health.json()["version"] == "2.0.0-alpha.9"
|
||||
assert backup.status_code == 200
|
||||
assert restore.status_code == 200
|
||||
assert restore.json() == {"status": "restored"}
|
||||
@@ -66,6 +66,17 @@ def test_dashboard_control_and_learning_endpoints(tmp_path, monkeypatch) -> None
|
||||
"confidence": 0.91,
|
||||
},
|
||||
)
|
||||
simulation = client.post(
|
||||
"/v2/simulate",
|
||||
json={
|
||||
"actuator_entity_id": "light.storage",
|
||||
"trigger_entity_id": "binary_sensor.storage_door",
|
||||
"trigger_state": "on",
|
||||
},
|
||||
)
|
||||
readiness = client.get("/v2/control/light.storage/readiness")
|
||||
global_control = client.post("/v2/control/global", json={"enabled": False})
|
||||
detailed_health = client.get("/v2/health")
|
||||
dashboard = client.get("/v2/dashboard")
|
||||
|
||||
assert entities.status_code == 200
|
||||
@@ -77,5 +88,13 @@ def test_dashboard_control_and_learning_endpoints(tmp_path, monkeypatch) -> None
|
||||
assert control.json()["stage"] == "dry_run"
|
||||
assert learning.status_code == 200
|
||||
assert learning.json()["patterns"][0]["trigger_entity_id"] == "binary_sensor.storage_door"
|
||||
assert simulation.status_code == 200
|
||||
assert simulation.json()["decision"]["target_state"] == "on"
|
||||
assert readiness.status_code == 200
|
||||
assert readiness.json()["ready"] is False
|
||||
assert global_control.status_code == 200
|
||||
assert global_control.json()["global_enabled"] is False
|
||||
assert detailed_health.status_code == 200
|
||||
assert detailed_health.json()["global_enabled"] is False
|
||||
assert dashboard.status_code == 200
|
||||
assert dashboard.json()["actuator_count"] == 1
|
||||
|
||||
@@ -134,6 +134,7 @@ def test_event_core_executes_allowed_active_decision(tmp_path: Path) -> None:
|
||||
actuator_entity_id="light.storage",
|
||||
stage=SafetyStage.ACTIVE,
|
||||
min_confidence=0.8,
|
||||
active_ready=True,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -153,3 +154,58 @@ def test_event_core_executes_allowed_active_decision(tmp_path: Path) -> None:
|
||||
decision = [item.decision for item in audit if item.decision is not None][0]
|
||||
assert calls == ["light.storage"]
|
||||
assert decision.executed is True
|
||||
|
||||
|
||||
def test_active_requires_dry_run_readiness(tmp_path: Path) -> None:
|
||||
stores = FutureStores(tmp_path)
|
||||
stores.save_runtime(
|
||||
RuntimeState(
|
||||
entities={
|
||||
"light.storage": EntityState(
|
||||
entity_id="light.storage",
|
||||
domain="light",
|
||||
state="off",
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
stores.save_learning(
|
||||
LearningState(
|
||||
profiles={
|
||||
"light.storage": LearningProfile(
|
||||
actuator_entity_id="light.storage",
|
||||
patterns=[
|
||||
BehaviorPatternV2(
|
||||
actuator_entity_id="light.storage",
|
||||
target_state="on",
|
||||
trigger_entity_id="binary_sensor.storage_door",
|
||||
trigger_state="on",
|
||||
support=3,
|
||||
confidence=0.95,
|
||||
)
|
||||
],
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
stores.save_control(
|
||||
stores.control().model_copy(
|
||||
update={
|
||||
"profiles": {
|
||||
"light.storage": ControlProfile(
|
||||
actuator_entity_id="light.storage",
|
||||
stage=SafetyStage.ACTIVE,
|
||||
min_confidence=0.8,
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
audit = EventCore(stores).process_state_event(
|
||||
StateEvent(entity_id="binary_sensor.storage_door", new_state="on")
|
||||
)
|
||||
|
||||
decision = [item.decision for item in audit if item.decision is not None][0]
|
||||
assert decision.allowed is False
|
||||
assert "Active ist noch nicht freigegeben" in decision.blockers[0]
|
||||
|
||||
Reference in New Issue
Block a user