Add Panama health state service

This commit is contained in:
Gabriel Brown
2026-08-18 09:20:16 -04:00
parent 0ca83f74c7
commit e2e03252e4
4 changed files with 455 additions and 0 deletions
+107
View File
@@ -0,0 +1,107 @@
#!/usr/bin/env bash
# Health owns the accepted diagnostic snapshot. A newer unreadable response
# must degrade diagnostics without discarding the last report that Settings
# and future health surfaces will render.
set -euo pipefail
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
harness="$repo_dir/config/dot/quickshell/health-harness.qml"
service="$repo_dir/config/dot/quickshell/services/Health.qml"
warning_snapshot='{"schemaVersion":1,"generatedAt":"2026-08-18T00:00:00Z","summary":{"status":"warning","healthy":0,"warnings":2,"errors":0,"unconfigured":0},"context":{"session":"hyprland","versions":[{"id":"quickshell","version":"0.3.0"}]},"checks":[{"id":"integration.calendar","group":"integrations","title":"Calendar","status":"warning","detail":"Calendar probe timed out.","action":{"kind":"open","label":"Open Date & Time","confirm":false,"target":"datetime"}},{"id":"panama.caffeine","group":"panama-tools","title":"Caffeine","status":"warning","detail":"Duplicate inhibitors are active.","action":{"kind":"repair","label":"Release duplicate inhibitors","confirm":false}}]}'
fail() {
printf 'health service contract: %s\n' "$1" >&2
exit 1
}
[[ -f "$service" ]] || fail 'Health.qml is missing'
[[ -f "$harness" ]] || fail 'health harness is missing'
fixture_dir="$(mktemp -d /tmp/panama-health.XXXXXX)"
helper="$fixture_dir/panama-doctor"
printf '%s\n' \
'#!/usr/bin/env bash' \
'if [[ "$1" == "--json" ]]; then' \
' sleep 0.2' \
" printf '%s\\n' '$warning_snapshot'" \
' exit 0' \
'fi' \
'if [[ "$1" == "--repair" && "$2" == "panama.caffeine" && "$3" == "--json" ]]; then' \
' exit 0' \
'fi' \
'exit 2' >"$helper"
chmod +x "$helper"
run() { PANAMA_HEALTH_HELPER="$helper" qs -p "$harness" "$@"; }
harness_pid=""
cleanup() {
[[ -n "$harness_pid" ]] && kill "$harness_pid" >/dev/null 2>&1 || true
rm -rf "$fixture_dir"
}
trap cleanup EXIT
PANAMA_HEALTH_HELPER="$helper" qs -p "$harness" --daemonize >/dev/null
for _ in $(seq 1 40); do
run ipc show 2>/dev/null | rg -q '^target health-test$' && break
sleep 0.1
done
run ipc show 2>/dev/null | rg -q '^target health-test$' || fail 'test IPC target did not start'
harness_pid="$(run list | awk '/Process ID:/ { print $3; exit }')"
[[ "$(run ipc call health-test accept "$warning_snapshot" 0)" == "true" ]] \
|| fail 'valid warning snapshot was rejected'
state="$(run ipc call health-test status)"
jq -e '.status == "warning" and .acceptedGeneration == 0 and .checks == ["integration.calendar", "panama.caffeine"] and .diagnosticUnavailable == false' \
>/dev/null <<<"$state" || fail "valid warning snapshot was not accepted intact: $state"
[[ "$(run ipc call health-test accept "$warning_snapshot" -1)" == "false" ]] \
|| fail 'older generation replaced the current snapshot'
state="$(run ipc call health-test status)"
jq -e '.acceptedGeneration == 0 and .checks == ["integration.calendar", "panama.caffeine"]' \
>/dev/null <<<"$state" || fail "older generation altered accepted state: $state"
[[ "$(run ipc call health-test accept '{not json' 1)" == "false" ]] \
|| fail 'malformed snapshot was accepted'
state="$(run ipc call health-test status)"
jq -e '.diagnosticUnavailable == true and .checks == ["integration.calendar", "panama.caffeine"]' \
>/dev/null <<<"$state" || fail "malformed snapshot discarded the last valid checks: $state"
before_generation="$(jq -r .generation <<<"$state")"
run ipc call health-test queue >/dev/null
state="$(run ipc call health-test status)"
jq -e '.queuedRefresh == true and .generation == ($before + 1)' --argjson before "$before_generation" \
>/dev/null <<<"$state" || fail "two refreshes did not retain exactly one follow-up: $state"
for _ in $(seq 1 120); do
state="$(run ipc call health-test status)"
jq -e '.busy == false and .generation == ($before + 2) and .queuedRefresh == false' --argjson before "$before_generation" \
>/dev/null <<<"$state" && break
sleep 0.1
done
jq -e '.busy == false and .generation == ($before + 2) and .queuedRefresh == false' --argjson before "$before_generation" \
>/dev/null <<<"$state" || fail "queued refresh did not run exactly once: $state"
[[ "$(run ipc call health-test repair panama.caffeine)" == "true" ]] \
|| fail 'repairable check was refused'
for _ in $(seq 1 120); do
state="$(run ipc call health-test status)"
jq -e '.busy == false and .generation == ($before + 3)' --argjson before "$before_generation" \
>/dev/null <<<"$state" && break
sleep 0.1
done
jq -e '.busy == false and .generation == ($before + 3)' --argjson before "$before_generation" \
>/dev/null <<<"$state" || fail "accepted repair did not trigger one rescan: $state"
[[ "$(run ipc call health-test repair unknown.check)" == "false" ]] \
|| fail 'unknown check started a repair'
[[ "$(run ipc call health-test repair integration.calendar)" == "false" ]] \
|| fail 'non-repairable check started a repair'
state="$(run ipc call health-test status)"
jq -e '.repairingId == "" and .generation == ($before + 3)' --argjson before "$before_generation" \
>/dev/null <<<"$state" || fail "rejected repair altered process state: $state"
trap - EXIT
cleanup
printf 'health service contract: PASS\n'