#!/usr/bin/env bash set -euo pipefail fail() { printf 'Control Center contract: %s\n' "$1" >&2 exit 1 } project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" cleanup() { qs ipc call quicksettings close >/dev/null 2>&1 || true qs ipc call kdeconnect reset >/dev/null 2>&1 || true qs ipc call home-assistant reset >/dev/null 2>&1 || true } trap cleanup EXIT rg -Fq 'readonly property int controlCenterWidth: 430' \ "$project_root/config/dot/quickshell/config/Theme.qml" \ || fail 'approved Control Center width is missing' rg -Fq 'readonly property int controlCenterTopGap: 2' \ "$project_root/config/dot/quickshell/config/Theme.qml" \ || fail 'approved top attachment is missing' rg -Fq 'margins.top: Theme.barHeight + Theme.controlCenterTopGap' \ "$project_root/config/dot/quickshell/modules/quicksettings/QuickSettings.qml" \ || fail 'Control Center is not tightly attached to the bar' rg -Fq 'implicitWidth: Theme.controlCenterWidth' \ "$project_root/config/dot/quickshell/modules/quicksettings/QuickSettings.qml" \ || fail 'Control Center window does not use its geometry token' rg -Fq 'HomeControls' \ "$project_root/config/dot/quickshell/modules/quicksettings/QuickSettingsPanel.qml" \ || fail 'Home controls are not mounted' rg -Fq 'PhoneControls' \ "$project_root/config/dot/quickshell/modules/quicksettings/QuickSettingsPanel.qml" \ || fail 'Phone controls are not mounted' rg -Fq 'visible: KdeConnect.phoneReachable' \ "$project_root/config/dot/quickshell/modules/bar/StatusCluster.qml" \ || fail 'reachable phone state is absent from the bar' for component in ControlSectionHeader HomeControls HomeTile PhoneControls RecentExchange; do [[ -f "$project_root/config/dot/quickshell/modules/quicksettings/$component.qml" ]] \ || fail "$component is missing" done qs ipc call home-assistant fixture ready >/dev/null qs ipc call kdeconnect fixture reachable >/dev/null qs ipc call quicksettings open >/dev/null hyprctl layers | rg -q 'namespace: qs-popover-quicksettings' \ || fail 'Control Center layer did not map' jq -e '.open == true and .expandedSection == ""' \ <<<"$(qs ipc call quicksettings status)" >/dev/null \ || fail 'Control Center did not open in its resting state' qs ipc call quicksettings section home >/dev/null jq -e '.open == true and .expandedSection == "home"' \ <<<"$(qs ipc call quicksettings status)" >/dev/null \ || fail 'Home section did not expand' qs ipc call quicksettings section phone >/dev/null jq -e '.open == true and .expandedSection == "phone"' \ <<<"$(qs ipc call quicksettings status)" >/dev/null \ || fail 'Phone did not replace Home as the expanded section' qs ipc call quicksettings section phone >/dev/null jq -e '.open == true and .expandedSection == ""' \ <<<"$(qs ipc call quicksettings status)" >/dev/null \ || fail 'expanded Phone section did not collapse' trap - EXIT cleanup printf 'Control Center contract: PASS\n'