2d25e69632
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.
65 lines
2.4 KiB
Bash
65 lines
2.4 KiB
Bash
#!/usr/bin/env bats
|
|
# Tests for vendor/claude-code/plugins/obsidian-vault-kb/scripts/setup.sh.
|
|
|
|
load '../helpers/common'
|
|
|
|
setup() {
|
|
sandbox_home
|
|
SETUP="$REPO_ROOT/vendor/claude-code/plugins/obsidian-vault-kb/scripts/setup.sh"
|
|
SETTINGS_FILE="$HOME/.claude/settings.json"
|
|
CONFIG_FILE="$HOME/.agent-skills/obsidian-vault-kb/config.json"
|
|
VAULT="$BATS_TEST_TMPDIR/vault"
|
|
make_test_vault "$VAULT"
|
|
}
|
|
|
|
@test "writes the three Bash rules and one Read rule" {
|
|
run "$SETUP" --settings-scope user --mode append --vault v="$VAULT"
|
|
[ "$status" -eq 0 ]
|
|
allow=$(json_get "$SETTINGS_FILE" "permissions.allow")
|
|
[[ "$allow" == *'Bash(~/.agent-skills/obsidian-vault-kb/bin/vault_index.sh:*)'* ]]
|
|
[[ "$allow" == *'Bash(~/.agent-skills/obsidian-vault-kb/bin/vault_search.sh:*)'* ]]
|
|
[[ "$allow" == *'Bash(~/.agent-skills/obsidian-vault-kb/bin/vault_backlinks.sh:*)'* ]]
|
|
[[ "$allow" == *'Read(~/.agent-skills/obsidian-vault-kb/config.json)'* ]]
|
|
}
|
|
|
|
@test "--mode outside the fixed set errors" {
|
|
run "$SETUP" --settings-scope user --mode not-a-real-mode --vault v="$VAULT"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"--mode must be read-only, append, or maintain"* ]]
|
|
}
|
|
|
|
@test "at least one --vault is required" {
|
|
run "$SETUP" --settings-scope user --mode append
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"at least one --vault"* ]]
|
|
}
|
|
|
|
@test "a --vault pointing at a nonexistent directory errors before writing config" {
|
|
run "$SETUP" --settings-scope user --mode append --vault v="$BATS_TEST_TMPDIR/nope"
|
|
[ "$status" -ne 0 ]
|
|
[ ! -f "$CONFIG_FILE" ]
|
|
}
|
|
|
|
@test "registers the vault path and mode in config.json" {
|
|
run "$SETUP" --settings-scope user --mode append --vault v="$VAULT"
|
|
[ "$status" -eq 0 ]
|
|
mode=$(json_get "$CONFIG_FILE" "mode")
|
|
[ "$mode" = '"append"' ]
|
|
path=$(json_get "$CONFIG_FILE" "vaults.0.path")
|
|
[ "$path" = "\"$VAULT\"" ]
|
|
}
|
|
|
|
@test "registering the same vault name twice updates the path instead of duplicating" {
|
|
VAULT2="$BATS_TEST_TMPDIR/vault2"
|
|
make_test_vault "$VAULT2"
|
|
"$SETUP" --settings-scope user --mode append --vault v="$VAULT" > /dev/null
|
|
run "$SETUP" --settings-scope user --mode maintain --vault v="$VAULT2"
|
|
[ "$status" -eq 0 ]
|
|
count=$(python3 -c "import json; print(len(json.load(open('$CONFIG_FILE'))['vaults']))")
|
|
[ "$count" -eq 1 ]
|
|
path=$(json_get "$CONFIG_FILE" "vaults.0.path")
|
|
[ "$path" = "\"$VAULT2\"" ]
|
|
mode=$(json_get "$CONFIG_FILE" "mode")
|
|
[ "$mode" = '"maintain"' ]
|
|
}
|