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.
80 lines
2.3 KiB
Bash
80 lines
2.3 KiB
Bash
#!/usr/bin/env bats
|
|
# Tests for skills/obsidian-vault-kb/scripts/vault_search.sh.
|
|
#
|
|
# The "non-markdown file not matched" test is a direct regression guard for
|
|
# the bug where `-g` glob filters were placed after `--`, so ripgrep treated
|
|
# them as literal positional paths instead of options and the *.md filter
|
|
# silently never applied (confirmed by matching content inside a .pdf).
|
|
|
|
load '../helpers/common'
|
|
|
|
setup() {
|
|
sandbox_home
|
|
SCRIPT="$REPO_ROOT/skills/obsidian-vault-kb/scripts/vault_search.sh"
|
|
CONFIG_FILE="$HOME/.agent-skills/obsidian-vault-kb/config.json"
|
|
VAULT="$BATS_TEST_TMPDIR/vault"
|
|
make_test_vault "$VAULT"
|
|
write_vault_config "$CONFIG_FILE" "append" "v=$VAULT"
|
|
}
|
|
|
|
@test "finds a match inside a markdown note" {
|
|
run "$SCRIPT" pihole
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"dns-setup.md"* ]]
|
|
}
|
|
|
|
@test "does not match content that exists only inside a non-markdown file" {
|
|
run "$SCRIPT" attachment-only-marker
|
|
[[ "$output" == *"(no matches)"* ]]
|
|
[[ "$output" != *"attachment.pdf"* ]]
|
|
}
|
|
|
|
@test "does not match content that exists only inside .obsidian" {
|
|
run "$SCRIPT" obsidian-internal-marker
|
|
[[ "$output" == *"(no matches)"* ]]
|
|
}
|
|
|
|
@test "no spurious ripgrep argument errors on stderr/stdout" {
|
|
run "$SCRIPT" pihole
|
|
[[ "$output" != *"No such file or directory"* ]]
|
|
}
|
|
|
|
@test "a subfolder argument narrows the search root" {
|
|
run "$SCRIPT" pihole v Notes
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"== Search root: $VAULT/Notes =="* ]]
|
|
[[ "$output" == *"dns-setup.md"* ]]
|
|
}
|
|
|
|
@test "a subfolder containing '..' is rejected" {
|
|
run "$SCRIPT" pihole v ../../etc
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"no '..' or absolute paths"* ]]
|
|
}
|
|
|
|
@test "an absolute-path subfolder is rejected" {
|
|
run "$SCRIPT" pihole v /etc
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"no '..' or absolute paths"* ]]
|
|
}
|
|
|
|
@test "a subfolder symlink escaping the vault is rejected" {
|
|
ln -s /etc "$VAULT/Notes/escape-link"
|
|
run "$SCRIPT" pihole v Notes/escape-link
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"outside the vault"* ]]
|
|
}
|
|
|
|
@test "a subfolder that doesn't exist in the vault errors" {
|
|
run "$SCRIPT" pihole v NoSuchFolder
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"does not exist in the vault"* ]]
|
|
}
|
|
|
|
@test "grep fallback still finds matches when rg is unavailable" {
|
|
hide_command rg
|
|
run "$SCRIPT" pihole
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"dns-setup.md"* ]]
|
|
}
|