dc4a5c5b5e
- tests/helpers/common.bash: hide_command hides python3/jq/rg via a per-directory-batched PATH shim (not per-file — that took minutes), making the fail-open/grep-fallback branches testable. - 20 new tests across all 7 .bats files: unknown flags, invalid --settings-scope, missing python3/jq, grep fallback when rg is unavailable, empty/multi-vault config edge cases, a vault path that stops existing or isn't a directory, and the previously-untested tool_name != Bash branch of force-ask-on-raw-git.sh. 53 -> 73 tests. - hooks.bats: deploy the hooks once in setup_file() (BATS_FILE_TMPDIR) instead of per-test (BATS_TEST_TMPDIR) -- faster, and gives kcov one stable path per hook to aggregate coverage against instead of a fragmented copy per test. - .gitignore (first in this repo) + tests/README.md Coverage section documenting the kcov invocation and why --include-pattern needs three entries, not two. Real, tool-measured coverage via kcov: 86.15% (255/296 lines) across all 10 wrapper/setup/hook scripts in both plugins, replacing an earlier manual ~68% branch-coverage estimate.
93 lines
3.4 KiB
Bash
93 lines
3.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"' ]
|
|
}
|
|
|
|
@test "an unknown flag errors" {
|
|
run "$SETUP" --settings-scope user --mode append --vault v="$VAULT" --bogus-flag
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"unknown argument '--bogus-flag'"* ]]
|
|
}
|
|
|
|
@test "an invalid --settings-scope value errors" {
|
|
run "$SETUP" --settings-scope nonsense --mode append --vault v="$VAULT"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"--settings-scope must be 'project' or 'user'"* ]]
|
|
}
|
|
|
|
@test "--settings-scope project writes under <project-dir>/.claude/settings.json" {
|
|
PROJECT_DIR="$BATS_TEST_TMPDIR/someproject"
|
|
mkdir -p "$PROJECT_DIR"
|
|
run "$SETUP" --settings-scope project --project-dir "$PROJECT_DIR" --mode append --vault v="$VAULT"
|
|
[ "$status" -eq 0 ]
|
|
[ -f "$PROJECT_DIR/.claude/settings.json" ]
|
|
[ ! -e "$HOME/.claude/settings.json" ]
|
|
}
|
|
|
|
@test "missing python3 fails with a clear error instead of a silent crash" {
|
|
hide_command python3
|
|
run "$SETUP" --settings-scope user --mode append --vault v="$VAULT"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"python3 is required"* ]]
|
|
}
|