Finish the wonderland: System told truthfully, in eight tabs instead of ten

Claude-Session: https://claude.ai/code/session_01Ms2FbjQy31TVf3CEvQhGM8
This commit is contained in:
Gabriel Brown
2026-08-24 23:31:52 -04:00
parent 9ffaf45a4d
commit be0e55214b
57 changed files with 5040 additions and 925 deletions
+161 -2
View File
@@ -23,6 +23,16 @@ confirm_snapshot="$(jq -c '
action: {kind: "repair", label: "Restart Panama", confirm: true}
}]
' <<<"$warning_snapshot")"
updates_snapshot="$(jq -c '
.checks[0].action = {kind: "open", label: "Open Software Update", confirm: false, target: "updates"}
' <<<"$warning_snapshot")"
# "storage" is a real Settings page that `settingsTargets` deliberately does
# not list. The allow-list has to be an allow-list: if any page id were taken
# on trust, extending the doctor's vocabulary would stop being a change that
# has to be made on both sides, and this whole coupling would be decorative.
unlisted_snapshot="$(jq -c '
.checks[0].action = {kind: "open", label: "Open Storage", confirm: false, target: "storage"}
' <<<"$warning_snapshot")"
projection_snapshot="$(jq -c '
.fixtureSecret = "fixture-secret"
| .summary.fixtureSecret = "fixture-secret"
@@ -30,6 +40,11 @@ projection_snapshot="$(jq -c '
| .context.versions[0].fixtureSecret = "fixture-secret"
| .checks[0].fixtureSecret = "fixture-secret"
' <<<"$warning_snapshot")"
# One probe, in the same envelope as a full report. Re-checking a single row
# after fixing something by hand is the reason it exists: rescanning all thirty
# takes long enough that people stop doing it, and a row that never updates is
# a row that stops being believed.
single_check='{"schemaVersion":1,"generatedAt":"2026-08-24T00:00:00Z","summary":{"status":"healthy","healthy":1,"warnings":0,"errors":0,"unconfigured":0},"context":{"session":"hyprland","versions":[{"id":"quickshell","version":"0.3.0"}]},"checks":[{"id":"panama.caffeine","group":"panama-tools","title":"Caffeine","status":"ok","detail":"No duplicate sleep inhibitors."}]}'
adversarial_snapshot="$(jq -c '
.fixtureSecret = "fixture-secret"
| .summary.fixtureSecret = "fixture-secret"
@@ -85,6 +100,57 @@ if keys != ["summary", "busy", "generation", "acceptedGeneration", "checks"]:
raise SystemExit(1)
PY
# ── Both sides of a Settings target ─────────────────────────────────────────
#
# An `open` action carries the id of a Settings page, and the two halves of
# that agreement live in different languages in different directories: the
# doctor writes `target="updates"`, and Health decides whether it will accept
# one by looking the value up in `settingsTargets`.
#
# Getting one without the other is not a dead button. `validAction` returning
# false makes `validCheck` return false, which makes `consumeSnapshot` reject
# the WHOLE report -- so a single unlisted target takes every other check down
# with it and System Health goes blank, for a reason nothing on screen names.
# That is what "Open Software Update" would have done had it been given the
# target it was missing without `settingsTargets` being extended to match.
#
# Derived from both files rather than restated, so the next target added on
# either side has to be added on the other.
python3 - "$repo_dir/config/dot/quickshell/scripts/panama-doctor" "$service" <<'PY' \
|| fail 'the doctor emits a Settings or instructions target that Health would reject, which rejects the entire snapshot'
import re
import sys
doctor = open(sys.argv[1], encoding="utf-8").read()
health = open(sys.argv[2], encoding="utf-8").read()
def accepted(name: str) -> set[str]:
block = re.search(rf'property var {name}:\s*\[(.*?)\]', health, re.S)
if not block:
raise SystemExit(f"Health.qml no longer declares {name}")
return set(re.findall(r'"([a-z-]+)"', block.group(1)))
settings_targets = accepted("settingsTargets")
instruction_targets = accepted("instructionTargets")
emitted = re.findall(r'Action\(\s*"(open|instructions)"\s*,\s*"[^"]*"\s*,\s*target="([a-z-]+)"', doctor)
if not emitted:
raise SystemExit("no targeted actions were read from the doctor, so this proves nothing")
for kind, target in emitted:
allowed = settings_targets if kind == "open" else instruction_targets
if target not in allowed:
raise SystemExit(
f'the doctor emits a {kind} action targeting "{target}", which Health does not accept'
)
if "updates" not in settings_targets:
raise SystemExit('Health does not accept the "updates" target, so the Software Update '
'actions have nowhere to go')
PY
fixture_dir="$(mktemp -d /tmp/panama-health.XXXXXX)"
config_path="$fixture_dir/quickshell"
cp -a "$repo_dir/config/dot/quickshell" "$config_path"
@@ -130,6 +196,10 @@ printf '%s\n' \
" printf '%s\\n' '$warning_snapshot'" \
' exit 0' \
'fi' \
'if [[ "$1" == "check" ]]; then' \
' printf "%s\n" "$PANAMA_HEALTH_SINGLE_CHECK"' \
' exit 0' \
'fi' \
'if [[ "$1" == "--repair" ]]; then' \
' repair_start_time="$(awk '\''{ print $22 }'\'' "/proc/$$/stat")"' \
' printf "%s|%s\n" "$$" "$repair_start_time" >"$PANAMA_HEALTH_REPAIR_STARTED"' \
@@ -161,7 +231,7 @@ chmod +x "$copy_bin/wl-copy" "$copy_bin/notify-send"
run() {
PATH="$copy_bin:$PATH" PANAMA_HEALTH_HELPER="$helper" PANAMA_HEALTH_COPY_FILE="$copy_file" \
PANAMA_HEALTH_REPAIR_MODE_FILE="$repair_mode_file" PANAMA_HEALTH_REPAIR_LOG="$repair_log" \
PANAMA_HEALTH_NOTIFICATION_LOG="$notification_log" \
PANAMA_HEALTH_NOTIFICATION_LOG="$notification_log" PANAMA_HEALTH_SINGLE_CHECK="$single_check" \
PANAMA_HEALTH_REPAIR_STARTED="$repair_started_file" PANAMA_HEALTH_REPAIR_RELEASE="$repair_release_file" \
qs -p "$harness" "$@"
}
@@ -218,7 +288,7 @@ trap cleanup EXIT
PATH="$copy_bin:$PATH" PANAMA_HEALTH_HELPER="$helper" PANAMA_HEALTH_COPY_FILE="$copy_file" \
PANAMA_HEALTH_REPAIR_MODE_FILE="$repair_mode_file" PANAMA_HEALTH_REPAIR_LOG="$repair_log" \
PANAMA_HEALTH_NOTIFICATION_LOG="$notification_log" \
PANAMA_HEALTH_NOTIFICATION_LOG="$notification_log" PANAMA_HEALTH_SINGLE_CHECK="$single_check" \
PANAMA_HEALTH_REPAIR_STARTED="$repair_started_file" PANAMA_HEALTH_REPAIR_RELEASE="$repair_release_file" \
qs -p "$harness" --daemonize >/dev/null
for _ in $(seq 1 40); do
@@ -237,6 +307,38 @@ 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 "$updates_snapshot" 0)" == "true" ]] \
|| fail 'a check pointing at Software Update was rejected, so the whole report would go blank rather than one button being dead'
state="$(run ipc call health-test status)"
jq -e '.status == "warning" and .diagnosticUnavailable == false
and .checks == ["integration.calendar", "panama.caffeine"]' \
>/dev/null <<<"$state" || fail "the Software Update target did not survive acceptance intact: $state"
[[ "$(run ipc call health-test accept "$unlisted_snapshot" 0)" == "false" ]] \
|| fail 'a Settings target the service does not list was accepted, so the allow-list is not one'
# ── The command a repair will run, carried through ──────────────────────────
#
# Every field of a check is projected onto a known shape on the way in, which
# is what stops an unknown key from reaching the report -- and which means a
# NEW known key has to be added to the projection or it is silently dropped.
# `repairCommand` is the one where that failure is invisible: the repair still
# works, the row still says "Restart Vicinae", and the only thing missing is
# the sentence telling somebody what is about to run as them.
repair_command_snapshot="$(jq -c '
.checks[1].repairCommand = "systemd-inhibit --list"
' <<<"$warning_snapshot")"
[[ "$(run ipc call health-test accept "$repair_command_snapshot" 0)" == "true" ]] \
|| fail 'a check carrying its repair command was rejected'
jq -e '[.checks[] | select(.id == "panama.caffeine") | .repairCommand] == ["systemd-inhibit --list"]' \
>/dev/null <<<"$(run ipc call health-test report)" \
|| fail 'the repair command was projected away, so the row cannot say what it is about to run'
# A check with no repair, or a doctor that has not learned to send one, is
# still a check. Dropping the field is fine; refusing the report is not.
[[ "$(run ipc call health-test accept "$warning_snapshot" 0)" == "true" ]] \
|| fail 'a check without a repair command was rejected once the field existed'
[[ "$(run ipc call health-test accept "$projection_snapshot" 0)" == "true" ]] \
|| fail 'snapshot with unknown non-action fields was rejected instead of safely projected'
stored_report="$(run ipc call health-test report)"
@@ -398,6 +500,63 @@ state="$(run ipc call health-test status)"
jq -e '.repairingId == "" and .generation == ($before + 1)' --argjson before "$confirm_generation" \
>/dev/null <<<"$state" || fail "rejected repair altered process state: $state"
# ── One row, re-checked ─────────────────────────────────────────────────────
#
# The whole scan is thirty probes with network and D-Bus work behind several of
# them. Somebody who has just restarted a service by hand wants to know about
# that service, and making them wait nine seconds for the other twenty-nine is
# how a Re-check button stops being pressed and a stale row stops being
# believed. So `refreshCheck` runs one probe -- and has to leave the rest of
# the accepted report exactly as it was, since a single-check response says
# nothing about any other row.
: >"$repair_log"
[[ "$(run ipc call health-test recheck panama.caffeine)" == "true" ]] \
|| fail 'a single-check refresh was refused for a check that is in the report'
for _ in $(seq 1 60); do
state="$(run ipc call health-test status)"
jq -e '(.checkStates[] | select(.id == "panama.caffeine") | .status) == "ok"' \
>/dev/null <<<"$state" && break
sleep 0.1
done
jq -e '.checks == ["integration.calendar", "panama.caffeine"]
and (.checkStates[] | select(.id == "panama.caffeine") | .status) == "ok"
and (.checkStates[] | select(.id == "integration.calendar") | .status) == "warning"
and .summary == {status: "warning", healthy: 1, warnings: 1, errors: 0, unconfigured: 0}' \
>/dev/null <<<"$state" \
|| fail "a single-check refresh did not update exactly the one row it probed: $state"
grep -Fxq 'check panama.caffeine' "$repair_log" \
|| fail "refreshCheck did not ask the doctor for one check: $(<"$repair_log")"
! grep -Fxq -- '--json' "$repair_log" \
|| fail 'a single-check refresh ran the whole thirty-probe scan anyway'
: >"$repair_log"
[[ "$(run ipc call health-test recheck unknown.check)" == "false" ]] \
|| fail 'a check id that is not in the report started a probe'
[[ ! -s "$repair_log" ]] || fail 'a refused single-check refresh started a process'
# ── The report, saved rather than copied ────────────────────────────────────
#
# Copy Report puts the diagnostics on the clipboard, which is the right answer
# when the next step is pasting it into a message and the wrong one when the
# next step is attaching it, or reading it in an editor, or sending it from a
# session that is the thing being diagnosed. Same redacted projection, written
# to a file.
report_file="$fixture_dir/health-report.txt"
[[ "$(run ipc call health-test save "$report_file")" == "true" ]] \
|| fail 'saving the health report was refused'
for _ in $(seq 1 40); do
[[ -s "$report_file" ]] && break
sleep 0.1
done
[[ -s "$report_file" ]] || fail 'the saved health report is absent or empty'
grep -Fq 'panama.caffeine' "$report_file" \
|| fail 'the saved report does not contain the checks it is a report of'
! grep -Fq 'fixture-secret' "$report_file" \
|| fail 'the saved report is not the redacted projection that copyReport writes'
rg -Fq 'panama-health-report.txt' "$service" \
|| fail 'saveReport has no default destination, so the row has nowhere to write without a file dialog'
python3 - "$service" <<'PY' || fail 'external repair failure notification is not bounded'
import sys