Files
command-center/tests/gen-keybinds.bats
T
Frank e86e60af39 docs: close OKF conformance gaps found by night audit
- references/okf-spec.md: replace v0.2 note with the deltas verified
  against upstream SPEC.md 2026-10-19 (timestamp->generated.at and
  # Citations->sources are the two breaking changes; trust fields and
  root-index okf_version are additive; bundle stays v0.1).
- index.md: restore the agentic-web-research section lost in the
  2026-08-28 rebuild and link log.md (index-coverage doctrine).
- gen-keybinds.sh emits OKF frontmatter so its generated artifact
  (tools/niri/keybindings.md, regenerated, 120 bindings) passes kb-lint;
  test added red->green.
- fix the two broken [[niri]] wikilinks (handy, noctalia-shell).

Refs #29
2026-10-19 02:43:33 -07:00

78 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bats
# tests/gen-keybinds.bats — black-box tests for scripts/gen-keybinds.sh
#
# Contract: parse a keybinds.kdl into a markdown cheat sheet on stdout,
# or into a file with --write OUT. Observable surface: markdown rows,
# section headers, exit status, written file.
setup() {
GEN="$BATS_TEST_DIRNAME/../scripts/gen-keybinds.sh"
TMP="$(mktemp -d)"
cat > "$TMP/keybinds.kdl" <<'EOF'
binds {
// ─── Applications ───
Mod+Return hotkey-overlay-title="Open Terminal: Ghostty" { spawn "ghostty"; }
Mod+D hotkey-overlay-title="Open App Launcher: noctalia launcher" { spawn-sh "noctalia msg panel-toggle launcher"; }
Mod+E { spawn "nautilus"; }
// ─── Screenshots ───
Print hotkey-overlay-title="Fullscreen screenshot" { spawn-sh "noctalia msg screenshot-fullscreen"; }
// a plain comment, not a section
Mod+Shift+ESCAPE { show-hotkey-overlay; }
}
EOF
}
teardown() {
rm -rf "$TMP"
}
@test "renders a row per bind with title preferred over action" {
run "$GEN" "$TMP/keybinds.kdl"
[ "$status" -eq 0 ]
[[ "$output" == *'| `Mod+D` | Open App Launcher: noctalia launcher |'* ]]
[[ "$output" == *'| `Mod+Return` | Open Terminal: Ghostty |'* ]]
}
@test "binds without a title render their action" {
run "$GEN" "$TMP/keybinds.kdl"
[[ "$output" == *'| `Mod+E` | spawn "nautilus" |'* ]]
[[ "$output" == *'| `Mod+Shift+ESCAPE` | show-hotkey-overlay |'* ]]
}
@test "section comments become headers; plain comments are ignored" {
run "$GEN" "$TMP/keybinds.kdl"
[[ "$output" == *"## Applications"* ]]
[[ "$output" == *"## Screenshots"* ]]
[[ "$output" != *"a plain comment"* ]]
}
@test "row count matches bind count" {
run "$GEN" "$TMP/keybinds.kdl"
local rows
rows="$(grep -c '^| `' <<<"$output")"
[ "$rows" -eq 5 ]
}
@test "--write writes the markdown to the given path" {
run "$GEN" "$TMP/keybinds.kdl" --write "$TMP/out/keybindings.md"
[ "$status" -eq 0 ]
[ -f "$TMP/out/keybindings.md" ]
grep -q '| `Mod+D` | Open App Launcher: noctalia launcher |' "$TMP/out/keybindings.md"
grep -q 'GENERATED' "$TMP/out/keybindings.md"
}
@test "output begins with OKF frontmatter so the artifact passes kb-lint" {
run "$GEN" "$TMP/keybinds.kdl"
[ "${lines[0]}" = '---' ]
[[ "${lines[1]}" == 'type: reference' ]]
grep -q '^generated:' <<<"$output"
}
@test "missing input file fails loudly" {
run "$GEN" "$TMP/nope.kdl"
[ "$status" -ne 0 ]
[[ "$output" == *"no such file"* ]]
}