mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-10-01 21:08:44 +01:00
* Surface fixup failures to the caller applying a suggestion Applying a suggestion whose fixup failed reported success: the fixup base swallowed ResolutionFixupError, the API returned OK, and the repair flow in Home Assistant completed and removed the repair from the UI while the issue persisted in Supervisor. Let the error propagate from the fixup instead. The autofix loop already handles and logs per-fixup errors, bus-event triggered fixups now get the same treatment in the event callback, and a user-applied suggestion surfaces the failure as an API error so clients can show that the fix did not apply. ResolutionFixupError becomes an APIError with a translatable error key so it is reported as a client-visible error instead of an unexpected one. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Drop ResolutionFixupError, let fixup failures bubble Per review: the generic wrapper existed for a time when suggestions were only applied by autofix and the one job was separating fixup failures from real bugs for Sentry. The suggestion API is in regular use now and the wrapper actively hurts it — well-defined errors from the underlying operations were caught and replaced with a generic message. Remove the exception type entirely and let the original errors reach the caller. The autofix loop and the bus-event fixup path treat any HassioError as an environmental/config failure: log and continue without Sentry capture (the raise site reports to Sentry where warranted); everything else is still captured. Direct raises in the data disk fixups become HassOSDataDiskError, the could-not-start check in the app start fixup becomes AppsError. ResolutionFixupJobError now derives from ResolutionError and JobException. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Share unattended fixup error handling between autofix and bus events Address review: the bus event listener only caught HassioError, so a Supervisor bug in a bus-triggered fixup ended as an unretrieved task exception without Sentry report, unlike the same bug during autofix. Both unattended paths now use a common apply_fixup_safely() helper: log HassioError (environmental, reported at the raise site if warranted), capture everything else. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
85 lines
2.9 KiB
Python
85 lines
2.9 KiB
Python
"""Test fixup systemd unit execute reset."""
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from supervisor.coresys import CoreSys
|
|
from supervisor.exceptions import DBusError, DBusSystemdNoSuchUnit
|
|
from supervisor.resolution.const import ContextType, IssueType, SuggestionType
|
|
from supervisor.resolution.data import Issue, Suggestion
|
|
from supervisor.resolution.fixups.systemd_unit_execute_reset import (
|
|
FixupSystemdUnitExecuteReset,
|
|
)
|
|
|
|
ISSUE = Issue(IssueType.SYSTEMD_UNIT_FAILED, ContextType.SYSTEM, reference="a.service")
|
|
SUGGESTION = Suggestion(
|
|
SuggestionType.EXECUTE_RESET,
|
|
ContextType.SYSTEM,
|
|
reference="a.service",
|
|
)
|
|
|
|
|
|
async def test_fixup_reset_success(coresys: CoreSys):
|
|
"""Test reset fixup succeeds and cleans issue/suggestion."""
|
|
systemd_unit_execute_reset = FixupSystemdUnitExecuteReset(coresys)
|
|
assert systemd_unit_execute_reset.suggestion == SuggestionType.EXECUTE_RESET
|
|
assert systemd_unit_execute_reset.context == ContextType.SYSTEM
|
|
assert systemd_unit_execute_reset.issues == [IssueType.SYSTEMD_UNIT_FAILED]
|
|
assert systemd_unit_execute_reset.auto is False
|
|
|
|
coresys.resolution.add_suggestion(SUGGESTION)
|
|
coresys.resolution.add_issue(ISSUE)
|
|
|
|
with patch.object(
|
|
coresys.dbus.systemd,
|
|
"reset_failed_unit",
|
|
new_callable=AsyncMock,
|
|
) as reset_failed_unit:
|
|
await systemd_unit_execute_reset()
|
|
|
|
reset_failed_unit.assert_awaited_once_with("a.service")
|
|
assert not coresys.resolution.suggestions
|
|
assert not coresys.resolution.issues
|
|
|
|
|
|
async def test_fixup_reset_no_such_unit(coresys: CoreSys):
|
|
"""Test no-such-unit is tolerated and clears issue/suggestion."""
|
|
systemd_unit_execute_reset = FixupSystemdUnitExecuteReset(coresys)
|
|
coresys.resolution.add_suggestion(SUGGESTION)
|
|
coresys.resolution.add_issue(ISSUE)
|
|
|
|
with patch.object(
|
|
coresys.dbus.systemd,
|
|
"reset_failed_unit",
|
|
new_callable=AsyncMock,
|
|
side_effect=DBusSystemdNoSuchUnit("missing"),
|
|
) as reset_failed_unit:
|
|
await systemd_unit_execute_reset()
|
|
|
|
reset_failed_unit.assert_awaited_once_with("a.service")
|
|
assert not coresys.resolution.suggestions
|
|
assert not coresys.resolution.issues
|
|
|
|
|
|
async def test_fixup_reset_dbus_error_keeps_issue(coresys: CoreSys):
|
|
"""Test DBus error keeps issue/suggestion in place."""
|
|
systemd_unit_execute_reset = FixupSystemdUnitExecuteReset(coresys)
|
|
coresys.resolution.add_suggestion(SUGGESTION)
|
|
coresys.resolution.add_issue(ISSUE)
|
|
|
|
with (
|
|
patch.object(
|
|
coresys.dbus.systemd,
|
|
"reset_failed_unit",
|
|
new_callable=AsyncMock,
|
|
side_effect=DBusError("boom"),
|
|
) as reset_failed_unit,
|
|
pytest.raises(DBusError),
|
|
):
|
|
await systemd_unit_execute_reset()
|
|
|
|
reset_failed_unit.assert_awaited_once_with("a.service")
|
|
assert ISSUE in coresys.resolution.issues
|
|
assert SUGGESTION in coresys.resolution.suggestions
|