Files
Frank f63d11de85 feat(blankpad): desk.sh profile switcher, hotplug autoswitch daemon, keybinds doc generator + bats suite
- desk.sh: list/current/switch/cycle/match/capture over cfg/desk-*.kdl
  profiles; apply = relink display.kdl, niri validate (rollback on fail),
  load-config-file, noctalia notification; match scores // requires: lines
  (EDID long names) against live niri msg outputs
- desk-autoswitch.sh: watch niri msg --json event-stream for
  OutputsChanged, debounced desk.sh match --apply, reconnect loop
- blankpad-desk-autoswitch.service: ConditionHost=blankpad user unit
- gen-keybinds.sh: keybinds.kdl -> markdown cheat sheet (sections from
  // --- headers, hotkey-overlay-title preferred over action)
- tests/: 27 bats cases, all green (desk 16, gen-keybinds 6,
  niri-config 5 incl. real niri validate on the assembled tree with
  each desk profile active)
2026-10-09 14:40:26 -07:00

67 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bats
# tests/niri-config.bats — the assembled niri config must pass `niri validate`
#
# Assembly mirrors deploy: base dotfiles/niri config + cfg files, overlaid
# by the per-host dotfiles/zz-blankpad overrides, display.kdl symlinked to a
# desk profile, live noctalia.kdl copied in (the repo include is not optional).
setup() {
REPO="$BATS_TEST_DIRNAME/.."
NIRI_BIN="$(command -v niri || true)"
TMP="$(mktemp -d)"
}
teardown() {
rm -rf "$TMP"
}
# Assemble a config tree with the given desk profile active.
assemble() {
local profile="${1:-desk-1-home}"
mkdir -p "$TMP/niri"
cp -r "$REPO/dotfiles/niri/.config/niri/." "$TMP/niri/"
cp -f "$REPO/dotfiles/zz-blankpad/niri/.config/niri/cfg/"*.kdl "$TMP/niri/cfg/"
ln -sfn "$profile.kdl" "$TMP/niri/cfg/display.kdl"
[ -f "$HOME/.config/niri/noctalia.kdl" ] &&
cp "$HOME/.config/niri/noctalia.kdl" "$TMP/niri/noctalia.kdl"
}
require_niri() {
[ -n "$NIRI_BIN" ] || skip "niri binary not found"
}
@test "assembly: host overrides win over base files" {
assemble
# the cycle-desk bind only exists in the zz-blankpad keybinds
grep -q 'desk.sh cycle' "$TMP/niri/cfg/keybinds.kdl"
! grep -q 'desk.sh cycle' "$REPO/dotfiles/niri/.config/niri/cfg/keybinds.kdl"
}
@test "validate: assembled config with desk-1-home active" {
require_niri
assemble desk-1-home
run "$NIRI_BIN" validate -c "$TMP/niri/config.kdl"
[ "$status" -eq 0 ]
}
@test "validate: assembled config with desk-2-portable active" {
require_niri
assemble desk-2-portable
run "$NIRI_BIN" validate -c "$TMP/niri/config.kdl"
[ "$status" -eq 0 ]
}
@test "validate: config is valid with the optional includes absent" {
require_niri
assemble
rm -f "$TMP/niri/cfg/switch-events.kdl" "$TMP/niri/cfg/display.kdl"
run "$NIRI_BIN" validate -c "$TMP/niri/config.kdl"
[ "$status" -eq 0 ]
}
@test "desk profiles: every profile declares at least one requires line" {
for f in "$REPO"/dotfiles/zz-blankpad/niri/.config/niri/cfg/desk-*.kdl; do
grep -q '^// requires:' "$f"
done
}