From 1a91d00f2ccd08c56c7ad2b18166397cbc098674 Mon Sep 17 00:00:00 2001 From: Gabriel Brown Date: Tue, 18 Aug 2026 07:48:02 -0400 Subject: [PATCH] Stop two contracts from latching a broken desktop state Both tests run against the live session and capture "what it was before" so they can put it back. Neither checked that what they found was sane, so one interrupted run poisoned every run after it -- and because each subsequent run faithfully restored the bad value, the desktop stayed broken while the failure looked like an ordinary flake. displays-contract left the monitor at scale 1.25 after a failed revert. The next run recorded 1.25 as the original and restored the desktop to it. It now reads the shipped scale out of monitors.lua and refuses to run when the live display disagrees. A failure to parse that value is fatal rather than skipped, because silently skipping the check is how the laundering happened in the first place. focus-session-expiry kills and restarts the shell mid-session, so an interrupted run leaves caffeine on with nothing left to turn it off. The next `focus start` recorded "previously on", handed it back on expiry, and failed the assertion that caffeine ends off -- identically, forever, with the desktop unable to idle or lock the entire time. It now refuses to start unless caffeine is already off, which is the only state in which the test can tell "restored correctly" from "never released". Both guards name the exact command to recover with. Verified each fires on a dirty state and passes on a clean one; caffeine was found latched on this machine and has been released. Claude-Session: https://claude.ai/code/session_01BRvzt4H8XXLPVH5MyYdk9L --- tests/quickshell/displays-contract.sh | 19 +++++++++++++++++++ tests/quickshell/focus-session-expiry.sh | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/quickshell/displays-contract.sh b/tests/quickshell/displays-contract.sh index a7fda87..767e9cc 100755 --- a/tests/quickshell/displays-contract.sh +++ b/tests/quickshell/displays-contract.sh @@ -113,6 +113,25 @@ config_home="$(mktemp -d /tmp/panama-displays-config.XXXXXX)" run() { XDG_CONFIG_HOME="$config_home" qs -p "$harness" "$@"; } status() { run ipc call displays-test status; } +# The shipped geometry, read from the Hyprland config rather than from the +# running compositor. +# +# Everything below captures "original" from what it observes at start, which is +# correct only if the display is already in a good state. A previous run that +# failed mid-revert leaves the display changed, and the next run then captures +# THAT as the original and faithfully restores the desktop to a broken value. +# One flake becomes permanent. So refuse to run from a state that does not match +# what the config says, rather than laundering it. +shipped_scale="$(sed -n 's/^local shipped_scale *= *\([0-9.]*\).*/\1/p' \ + "$repo_dir/config/dot/hypr/monitors.lua" | head -1)" +[[ -n "$shipped_scale" ]] || fail 'could not read the shipped scale from monitors.lua -- the guard below depends on it, and skipping it silently is how a dirty baseline gets laundered' +if [[ -n "$shipped_scale" ]]; then + live_scale="$(hyprctl -j monitors | jq -r '.[0].scale')" + if ! awk -v a="$live_scale" -v b="$shipped_scale" 'BEGIN { exit !(a == b) }'; then + fail "the display is at scale $live_scale but the config ships $shipped_scale -- refusing to capture a dirty state as the baseline. Restore it first: hyprctl eval 'hl.monitor({ output = \"DP-2\", mode = \"4500x3000@60\", scale = $shipped_scale, transform = 0 })'" + fi +fi + original_mode="" original_scale="" original_transform="" diff --git a/tests/quickshell/focus-session-expiry.sh b/tests/quickshell/focus-session-expiry.sh index 178087f..f9efa7a 100755 --- a/tests/quickshell/focus-session-expiry.sh +++ b/tests/quickshell/focus-session-expiry.sh @@ -13,6 +13,20 @@ cleanup() { trap cleanup EXIT qs ipc call focus end >/dev/null 2>&1 || true + +# focus start records the caffeine state it found so end() can hand it back, and +# the assertion below requires caffeine to finish off. Both are only true if +# caffeine starts off. +# +# This test kills and restarts the live shell, so an interrupted run leaves +# caffeine on with nothing to turn it back off. The next run then records +# "previously on", faithfully restores it, and fails -- and every run after +# that fails identically, with the desktop quietly unable to idle or lock the +# whole time. Refuse to start from that state rather than latching it in. +if [[ "$(qs ipc call caffeine status 2>/dev/null)" != "false" ]]; then + fail 'caffeine is on before the session starts -- this test cannot distinguish "restored correctly" from "never released". Turn it off first: qs ipc call caffeine toggle' +fi + qs ipc call focus start >/dev/null state_file=$(find "${XDG_STATE_HOME:-$HOME/.local/state}/quickshell/by-shell" -name focus-session.json -print -quit)