Add bats test suite for git-manager and obsidian-vault-kb

Isolated per-test $HOME sandboxing via tests/helpers/common.bash.
Covers both plugins' wrapper scripts, their setup.sh, and
git-manager's two PreToolUse hooks (53 tests). Verified the suite
catches regressions by temporarily reintroducing the recently-fixed
vault_search.sh -g/-- ordering bug and confirming it fails.
This commit is contained in:
Henner M. Kruse
2026-08-04 19:34:51 +00:00
parent 20cdf74b58
commit 2d25e69632
9 changed files with 674 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env bats
# Tests for the two optional PreToolUse hooks. Run against the *deployed*
# copies (via a real setup.sh run into a sandboxed $HOME) rather than the
# repo source under hooks/ directly, because force-ask-on-raw-git.sh only
# gets its companion _lib.sh (for the "already supports" wording) once
# deployed alongside it — exactly like real usage.
load '../helpers/common'
setup() {
sandbox_home
SETUP="$REPO_ROOT/vendor/claude-code/plugins/git-manager/scripts/setup.sh"
"$SETUP" --settings-scope user --install-hook --install-raw-git-hook > /dev/null
CHAIN_HOOK="$HOME/.agent-skills/git-manager/bin/force-ask-on-chaining.sh"
RAWGIT_HOOK="$HOME/.agent-skills/git-manager/bin/force-ask-on-raw-git.sh"
}
# --- force-ask-on-chaining.sh ---
@test "chaining hook: && in the command forces an ask" {
input='{"tool_name":"Bash","tool_input":{"command":"git add -A && git commit -m x"}}'
run "$CHAIN_HOOK" <<< "$input"
[ "$status" -eq 0 ]
[[ "$output" == *'"permissionDecision": "ask"'* ]]
}
@test "chaining hook: a clean command produces no output" {
input='{"tool_name":"Bash","tool_input":{"command":"git status"}}'
run "$CHAIN_HOOK" <<< "$input"
[ "$status" -eq 0 ]
[ -z "$output" ]
}
@test "chaining hook: non-Bash tool_name produces no output even with chaining chars" {
input='{"tool_name":"Read","tool_input":{"command":"a && b"}}'
run "$CHAIN_HOOK" <<< "$input"
[ "$status" -eq 0 ]
[ -z "$output" ]
}
# --- force-ask-on-raw-git.sh ---
@test "raw-git hook: git_cmd.sh invocations are exempted" {
input='{"tool_name":"Bash","tool_input":{"command":"~/.agent-skills/git-manager/bin/git_cmd.sh status"}}'
run "$RAWGIT_HOOK" <<< "$input"
[ "$status" -eq 0 ]
[ -z "$output" ]
}
@test "raw-git hook: raw git on a wrapper-supported subcommand asks with 'already supports' wording" {
input='{"tool_name":"Bash","tool_input":{"command":"git status"}}'
run "$RAWGIT_HOOK" <<< "$input"
[ "$status" -eq 0 ]
[[ "$output" == *'"permissionDecision": "ask"'* ]]
[[ "$output" == *"already supports"* ]]
}
@test "raw-git hook: raw git on an unsupported subcommand asks with 'accepted fallback' wording" {
input='{"tool_name":"Bash","tool_input":{"command":"git stash"}}'
run "$RAWGIT_HOOK" <<< "$input"
[ "$status" -eq 0 ]
[[ "$output" == *'"permissionDecision": "ask"'* ]]
[[ "$output" == *"accepted fallback"* ]]
}
@test "raw-git hook: a non-git command produces no output" {
input='{"tool_name":"Bash","tool_input":{"command":"ls -la"}}'
run "$RAWGIT_HOOK" <<< "$input"
[ "$status" -eq 0 ]
[ -z "$output" ]
}