Files
Panama/tests/quickshell/panama-commands-contract.sh
T
Gabriel Brown a68e4f6dcd Make every settings page reachable from the launcher
Settings had a search index and the launcher had script commands, and
neither knew about the other: finding a setting meant opening Settings
first and searching there. One command per page is now generated from
the same sources the in-app search reads -- the sidebar page list, the
group routing, and the schema labels -- so a setting searchable inside
Settings is searchable from the launcher without a second list to
maintain.

Generating it surfaced a gap in the in-app search as well. Six pages had
no vocabulary at all, because their contents come from the system rather
than our schema, so searching "volume" found nothing in Settings either.
They now carry entries, which improves both surfaces.

The product prefix is dropped from every hand-written command title. The
generated ones are qualified "Settings: <page>" instead: a bare page
label collides with the feature of the same name, and two commands
sharing a title are indistinguishable in a launcher.

Claude-Session: https://claude.ai/code/session_01BRvzt4H8XXLPVH5MyYdk9L
2026-08-19 09:47:07 -04:00

117 lines
4.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
commands_dir="$repo_dir/config/local/share/vicinae/scripts"
work="$(mktemp -d /tmp/panama-commands.XXXXXX)"
dispatch_log="$work/dispatch.log"
fail() {
printf 'Panama commands contract: %s\n' "$1" >&2
exit 1
}
cleanup() {
rm -rf "$work"
}
trap cleanup EXIT
declare -A expected=(
[open-control-center.sh]=control-center
[open-notifications.sh]=notifications
[open-calendar.sh]=calendar
[open-clipboard.sh]=clipboard
[open-mission-control.sh]=overview
[open-settings.sh]=settings
[check-system-health.sh]=health
[toggle-dnd.sh]=dnd
[toggle-caffeine.sh]=caffeine
[toggle-night-light.sh]=night-light
[start-focus.sh]=focus-start
[end-focus.sh]=focus-end
[capture.sh]=capture
[screen-intelligence.sh]=intelligence
[quick-screenshot.sh]=screenshot
[toggle-microphone.sh]=microphone
[open-prism-gallery.sh]=gallery
[restart-shell.sh]=restart-shell
)
# The per-page settings commands are generated from the settings page list, so
# they are enumerated from that list rather than restated here -- a hand-written
# copy would have to be edited every time a page is added, which is exactly the
# kind of second list this generator exists to avoid.
sidebar="$repo_dir/config/dot/quickshell/modules/settings/SettingsSidebar.qml"
while read -r page; do
[[ -n "$page" ]] || continue
[[ "$page" == "home" ]] && continue
expected[settings-$page.sh]="settings-page $page"
done < <(grep -oE '\{ page: "[a-z-]+"' "$sidebar" | sed 's/.*"\([a-z-]*\)"/\1/')
(( ${#expected[@]} > 18 )) || fail 'no generated per-page commands were found; run scripts/panama-settings-commands'
# Generated commands must match their source. A stale command dispatches to a
# page that has been renamed or removed, and the launcher reports nothing wrong.
"$repo_dir/config/dot/quickshell/scripts/panama-settings-commands" --check >/dev/null \
|| fail 'the generated per-page commands are stale; run scripts/panama-settings-commands'
mkdir -p "$work/home/.config/quickshell/scripts"
cat >"$work/home/.config/quickshell/scripts/panama-action" <<'EOF'
#!/usr/bin/env bash
printf '%s\n' "$*" >>"$PANAMA_COMMAND_TEST_LOG"
EOF
chmod +x "$work/home/.config/quickshell/scripts/panama-action"
[[ -d "$commands_dir" ]] || fail 'Vicinae command directory is missing'
mapfile -t actual_files < <(find "$commands_dir" -maxdepth 1 -type f -name '*.sh' -printf '%f\n' | sort)
[[ ${#actual_files[@]} -eq ${#expected[@]} ]] \
|| fail "expected ${#expected[@]} commands, found ${#actual_files[@]}"
declare -A seen_titles=()
for script_name in "${!expected[@]}"; do
script="$commands_dir/$script_name"
[[ -x "$script" ]] || fail "$script_name is missing or not executable"
vicinae script check "$script" >/dev/null \
|| fail "$script_name is rejected by Vicinae"
title="$(sed -n 's/^# @vicinae.title //p' "$script")"
# No product prefix: this is the desktop's own settings, not a third-party
# add-on announcing itself in someone else's launcher. Uniqueness still
# matters, because two commands with one title are indistinguishable there.
[[ -n $title ]] || fail "$script_name has no title"
[[ $title != Panama* ]] || fail "$script_name still carries the product prefix: $title"
[[ -z ${seen_titles[$title]+x} ]] || fail "duplicate launcher title: $title"
seen_titles[$title]=1
grep -Fxq '# @vicinae.mode silent' "$script" \
|| fail "$script_name does not close quietly after success"
grep -Fq '# @vicinae.description ' "$script" \
|| fail "$script_name has no searchable description"
grep -Fq '# @vicinae.keywords ' "$script" \
|| fail "$script_name has no search vocabulary"
grep -Fxq '# @vicinae.icon ../../icons/hicolor/scalable/apps/panama-settings.svg' "$script" \
|| fail "$script_name does not use the Panama application identity"
if [[ $script_name == check-system-health.sh ]]; then
[[ $title == 'Check System Health' ]] \
|| fail "health command has the wrong title: $title"
grep -Fxq '# @vicinae.schemaVersion 1' "$script" \
|| fail 'health command does not use schema version 1'
grep -Fxq '# @vicinae.keywords ["health", "doctor", "repair", "services"]' "$script" \
|| fail 'health command has the wrong search vocabulary'
grep -Fxq 'exec "$HOME/.config/quickshell/scripts/panama-action" health' "$script" \
|| fail 'health command bypasses the stable dispatcher path'
fi
: >"$dispatch_log"
HOME="$work/home" PANAMA_COMMAND_TEST_LOG="$dispatch_log" "$script"
dispatched="$(cat "$dispatch_log")"
[[ $dispatched == "${expected[$script_name]}" ]] \
|| fail "$script_name dispatched [$dispatched], expected [${expected[$script_name]}]"
done
printf 'Panama commands contract: PASS (%d commands)\n' "${#expected[@]}"