blitz_api/tests/test_electrs_advanced_status.py
fusion44 63b136d5ca
fix(apps): report electrs installed/configured/online in advanced status
_do_electrs_status_advanced only handled the negative cases: each guard
set installed/configured/status to its false-y value and returned early.
On the happy path (electrs installed, configured and running) it fell
through, populated the ports and sync details, but never set
s.installed/s.configured/s.status - so they kept their AppStatus
defaults (False/False/offline).

The /apps/status_advanced/electrs endpoint therefore reported electrs as
not installed and offline while simultaneously returning its ports and
sync details, disagreeing with the app_state_update_message status
(fusion44/blitz_api#286). Set the positive values when each guard passes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 13:07:52 +02:00

59 lines
1.8 KiB
Python

"""
Regression test for raspiblitz-web#286.
_do_electrs_status_advanced populated the detail fields on the happy path but
never set installed/configured/status, so a fully installed, configured and
running electrs was still reported as installed=false, configured=false,
status=offline (while paradoxically returning ports and sync details).
"""
from app.api.models import ProcessResult
from app.apps.impl import raspiblitz as rb
from app.apps.models import AppOnlineStatus
from app.external.result_type.src.result.result import Ok
_STATUS_OUT = "\n".join(
[
"##### STATUS ELECTRS SERVICE",
"version='v0.10.6'",
"configured=1",
"installed=1",
"serviceRunning=1",
"localIP='192.168.1.5'",
"publicIP='1.2.3.4'",
"portTCP='50001'",
"portSSL='50002'",
"TORaddress='abc.onion'",
]
)
_SYNC_OUT = "\n".join(
[
"serviceRunning=1",
"electrumResponding=1",
"blockheight='800000'",
"blockheightPercent='100'",
"initialSynced=1",
"infoSync=''",
]
)
async def test_electrs_advanced_reports_installed_when_running(monkeypatch):
async def fake_exec(command, **kwargs):
out = _SYNC_OUT if "status-sync" in command else _STATUS_OUT
return Ok(ProcessResult(0, out, ""))
monkeypatch.setattr(rb, "exec_bash_command", fake_exec)
result = await rb._do_electrs_status_advanced()
assert isinstance(result, Ok)
s = result.ok_value
# sanity: we reached the happy path (details populated)
assert s.http_port == "50001"
assert s.details["electrum_responding"] == "1"
# the actual bug: these were left at their False/offline defaults
assert s.installed is True
assert s.configured is True
assert s.status == AppOnlineStatus.ONLINE