Skip to content

Commit baabc93

Browse files
committed
fix(haos): reject expired supervisor commands
1 parent 72a258a commit baabc93

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

tests/haos_image_build/build_image.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,10 @@ def supervisor_api(
790790
}
791791
if data is not None:
792792
msg["data"] = data
793+
_remaining_deadline_budget(
794+
deadline,
795+
f"supervisor/api {method} {endpoint} send",
796+
)
793797
self._ws.send(json.dumps(msg))
794798
# Skip any out-of-band messages (events on subscriptions etc.) and
795799
# match by id.

tests/src/unit/test_haos_supervisor_wait.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,31 @@ def test_supervisor_api_shares_receive_deadline_across_frames() -> None:
6565
assert socket.recv.call_args_list == [call(timeout=4.0), call(timeout=2.5)]
6666

6767

68+
def test_supervisor_api_expired_deadline_does_not_dispatch() -> None:
69+
"""An expired command budget cannot produce an uncertain write outcome."""
70+
ws = HAWebSocket(
71+
"http://127.0.0.1:18123",
72+
OAuthCredentials(access_token="access", refresh_token="refresh"),
73+
)
74+
socket = Mock()
75+
ws._ws = socket
76+
77+
with (
78+
patch(
79+
"tests.haos_image_build.build_image.time.monotonic",
80+
side_effect=[10.0, 10.0],
81+
),
82+
pytest.raises(
83+
TimeoutError,
84+
match=r"supervisor/api post /core/update send exceeded its deadline",
85+
),
86+
):
87+
ws.supervisor_api("/core/update", method="post", data={}, timeout=0.0)
88+
89+
socket.send.assert_not_called()
90+
socket.recv.assert_not_called()
91+
92+
6893
@pytest.mark.parametrize(
6994
("error", "expected_code", "expected_message"),
7095
[

0 commit comments

Comments
 (0)