feat(doctor): battery health readout (#80)
Some checks failed
Check / eval (push) Has been cancelled

Report-only cycle_count + retained capacity (charge_* or energy_*) as
% of design on system batteries; soft warn below 70% of design; skip
when attrs missing. NOMARCHY_POWER_SUPPLY_ROOT for the checks.doctor
fixture (test_power has no cycle/design attrs).

Verified: V2 — nix flake check --no-build; checks.doctor green (fake
BAT0 cycles/% + Device-scope ignore); local BAT0 smoke (energy_*).
This commit is contained in:
Bernardo Magri
2026-07-11 10:06:13 +01:00
parent 3132ba5ac8
commit 71786bda6b
7 changed files with 114 additions and 16 deletions

View File

@@ -428,8 +428,34 @@
# sheet must still exit 0 i.e. the section runs without
# erroring under `set -euo pipefail`.
healthy = machine.succeed("nomarchy-doctor 2>&1")
for probe in ["NetworkManager", "fingerprint", "fwupd", "VA-API", "hibernate"]:
for probe in ["NetworkManager", "fingerprint", "fwupd", "VA-API", "hibernate", "battery health"]:
assert probe in healthy, f"doctor hardware section missing a self-gated '{probe}' row:\n{healthy}"
# #80 battery health: faked sysfs (test_power has no cycle/design).
machine.succeed(
"mkdir -p /tmp/fake-ps/BAT0 && "
"echo Battery > /tmp/fake-ps/BAT0/type && "
"echo System > /tmp/fake-ps/BAT0/scope && "
"echo 150 > /tmp/fake-ps/BAT0/cycle_count && "
"echo 4000000 > /tmp/fake-ps/BAT0/charge_full && "
"echo 5000000 > /tmp/fake-ps/BAT0/charge_full_design"
)
bat = machine.succeed(
"NOMARCHY_POWER_SUPPLY_ROOT=/tmp/fake-ps nomarchy-doctor 2>&1"
)
assert "BAT0 health" in bat, f"doctor missing battery health line:\n{bat}"
assert "150 cycles" in bat, f"doctor missing cycle_count:\n{bat}"
assert "80% of design capacity" in bat, f"doctor missing design %:\n{bat}"
# Peripheral Device-scope batteries must not produce a health line.
machine.succeed(
"mkdir -p /tmp/fake-ps/MOUSE0 && "
"echo Battery > /tmp/fake-ps/MOUSE0/type && "
"echo Device > /tmp/fake-ps/MOUSE0/scope && "
"echo 9 > /tmp/fake-ps/MOUSE0/cycle_count"
)
bat2 = machine.succeed(
"NOMARCHY_POWER_SUPPLY_ROOT=/tmp/fake-ps nomarchy-doctor 2>&1"
)
assert "MOUSE0" not in bat2, f"doctor reported Device-scope battery:\n{bat2}"
'';
};