Files
Panama/tests/quickshell/home-preferences-contract
T
Gabriel Brown e1faaf7a76 Drop the extension, and give the test suite a front door
Phase 6, the last of the fresh-install spec.

159 scripts lose their .sh: 110 contracts, 47 Vicinae commands, 2 compositor
contracts. A shebang and the executable bit already select the interpreter. The
extension only ever added something that had to stay in sync, and the rename
proved the point twice over in the space of an hour.

The spec's stated risk was Vicinae's script discovery. One script was renamed and
reloaded on its own before the other 46 followed; it came back as
scripts:panama.capture and all 47 resolve. What the probe turned up instead is
that the extension was never only a filename: Vicinae's command IDs embed it, so
every ID changed. Nothing in this repository refers to them, so nothing breaks.
The only trace is Vicinae's metadata.json, whose visited map had two Panama
entries that are now orphaned -- two commands lost their usage ranking and will
earn it back. Worth knowing before anyone renames these again on a machine that
has a keybind pointing at one.

Rewriting the references by exact filename missed two things it structurally
could not see: a name built from a variable, settings-$page.sh, and a glob,
-name '*.sh'. Both were in the contract that counts the generated commands, which
promptly reported 47 expected and 0 found. The mechanical part of a rename is the
part that looks finished.

The three subcommands. panama doctor fronts a health check that already existed
and already ran at the end of every install but could not be reached from a
terminal. panama upgrade re-runs the installer from anywhere. panama test runs
the suite, which had no entry point at all -- 121 files that were the main safety
net in this repository and were invisible in it.

Writing that runner found three tests nothing was running.
calendar_agenda_bridge_test, home_assistant_bridge_test and kdeconnect_bridge_test
are unittest suites without the executable bit, so no contract invoked them and
the first draft of the runner skipped them silently. All three pass, and have
passed unobserved for weeks. The runner collects *_test.py as well now, because a
runner with a blind spot is worse than no runner for the same reason a dependency
checker with one is: it reports PASS.

Six worktrees pruned. Each was re-checked rather than trusted to the spec's list,
and two needed it: panama-commands is not on feat/panama-commands but on
feat/gnome-tweaks-parity, and fix/panama-displays-review reads [ahead 3] -- ahead
of its remote, not of main, with every commit patch-equivalent to landed work.
roadmap-completion stays; it has five commits that are genuinely unlanded. The
branches are left alone: pruning a worktree costs nothing, deleting a branch is a
decision.

121 contracts pass.

Claude-Session: https://claude.ai/code/session_01NvgBuSWB5sE43yWmg21ozj
2026-08-20 21:55:55 -04:00

155 lines
5.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
harness="$repo_dir/config/dot/quickshell/home-preferences-harness.qml"
preferences="$repo_dir/config/dot/quickshell/config/HomePreferences.qml"
state_home="$(mktemp -d /tmp/panama-home-preferences-state.XXXXXX)"
fail() {
printf 'home preferences contract: %s\n' "$1" >&2
exit 1
}
qs_for_harness() {
XDG_STATE_HOME="$state_home" qs -p "$harness" "$@"
}
cleanup() {
qs_for_harness kill >/dev/null 2>&1 || true
rm -rf "$state_home"
}
trap cleanup EXIT
start_harness() {
qs_for_harness --daemonize >/dev/null
for _ in $(seq 1 40); do
if qs_for_harness ipc show 2>/dev/null | rg -q '^target home-pref-test$'; then
# Construct the lazy singleton and let its explicit reload finish
# before issuing mutations through the IPC boundary.
qs_for_harness ipc call home-pref-test status >/dev/null
sleep 0.2
return
fi
sleep 0.1
done
fail 'test IPC target did not start'
}
stop_harness() {
qs_for_harness kill >/dev/null 2>&1 || true
for _ in $(seq 1 40); do
if ! qs_for_harness ipc show >/dev/null 2>&1; then
return
fi
sleep 0.1
done
fail 'test shell did not stop cleanly'
}
status_without_state_dir() {
qs_for_harness ipc call home-pref-test status | jq -c 'del(.stateDir)'
}
wait_for_status() {
local expected="$1"
local actual=""
for _ in $(seq 1 40); do
actual="$(status_without_state_dir)"
if jq -e --argjson expected "$expected" \
'.initialized == $expected.initialized and .favorites == $expected.favorites and .saveError == $expected.saveError' \
<<<"$actual" >/dev/null; then
return
fi
sleep 0.1
done
fail "unexpected status: $actual"
}
wait_for_file_content() {
local expected="$1"
for _ in $(seq 1 40); do
state_file="$(find "$state_home" -name panama-home.json -print -quit)"
if [[ -n "$state_file" ]] \
&& jq -e --argjson expected "$expected" '. == $expected' "$state_file" >/dev/null; then
return
fi
sleep 0.1
done
fail 'preferences file did not contain the complete atomic update'
}
assert_reset_persists_without_debounce() {
local expected=$' function resetHomeDefaults(): void {\n persistTimer.stop();\n values.favorites = [];\n values.initialized = false;\n root.saveError = "";\n preferencesFile.writeAdapter();\n }'
local actual
actual="$(sed -n '/^ function resetHomeDefaults(): void {$/,/^ }$/p' "$preferences")"
[[ "$actual" == "$expected" ]] \
|| fail 'resetHomeDefaults must stop debounce before directly writing the default state'
}
# A leading JSON whitespace prevents qs from expanding the array into IPC
# positional arguments; JSON.parse() intentionally accepts that whitespace.
initial_ids=' ["light.kitchen","light.hall","light.desk"]'
expected='{"initialized":true,"favorites":[{"id":"light.desk","alias":""},{"id":"light.kitchen","alias":"Island"}],"saveError":""}'
expected_file='{"initialized":true,"favorites":[{"id":"light.desk","alias":""},{"id":"light.kitchen","alias":"Island"}]}'
reordered_expected='{"initialized":true,"favorites":[{"id":"light.desk","alias":""},{"id":"light.kitchen","alias":"Island"},{"id":"light.hall","alias":""}],"saveError":""}'
reordered_file='{"initialized":true,"favorites":[{"id":"light.desk","alias":""},{"id":"light.kitchen","alias":"Island"},{"id":"light.hall","alias":""}]}'
empty_expected='{"initialized":true,"favorites":[],"saveError":""}'
empty_file='{"initialized":true,"favorites":[]}'
reset_expected='{"initialized":false,"favorites":[],"saveError":""}'
reset_file='{"initialized":false,"favorites":[]}'
assert_reset_persists_without_debounce
start_harness
qs_for_harness ipc call home-pref-test initialize "$initial_ids" >/dev/null
qs_for_harness ipc call home-pref-test alias light.kitchen ' Island ' >/dev/null
qs_for_harness ipc call home-pref-test move light.desk 0 >/dev/null
wait_for_status "$reordered_expected"
wait_for_file_content "$reordered_file"
stop_harness
start_harness
wait_for_status "$reordered_expected"
qs_for_harness ipc call home-pref-test remove light.hall >/dev/null
wait_for_status "$expected"
wait_for_file_content "$expected_file"
qs_for_harness ipc call home-pref-test reset >/dev/null
wait_for_status "$reset_expected"
wait_for_file_content "$reset_file"
stop_harness
start_harness
wait_for_status "$reset_expected"
qs_for_harness ipc call home-pref-test initialize "$initial_ids" >/dev/null
qs_for_harness ipc call home-pref-test alias light.kitchen ' Island ' >/dev/null
qs_for_harness ipc call home-pref-test move light.desk 0 >/dev/null
qs_for_harness ipc call home-pref-test remove light.hall >/dev/null
wait_for_status "$expected"
wait_for_file_content "$expected_file"
qs_for_harness ipc call home-pref-test remove light.desk >/dev/null
qs_for_harness ipc call home-pref-test remove light.kitchen >/dev/null
wait_for_status "$empty_expected"
wait_for_file_content "$empty_file"
stop_harness
start_harness
wait_for_status "$empty_expected"
qs_for_harness ipc call home-pref-test initialize ' ["light.new","light.other"]' >/dev/null
wait_for_status "$empty_expected"
jq -e '(keys | sort) == ["favorites", "initialized"]' "$state_file" >/dev/null \
|| fail 'preferences file contains keys other than initialized and favorites'
if jq -r '.. | strings' "$state_file" | rg -qi 'token|url|api'; then
fail 'preferences file contains credential-like data'
fi
trap - EXIT
cleanup
printf 'home preferences contract: PASS\n'