Files
Henner M. Kruse dc4a5c5b5e Close bats coverage gaps, add hide_command helper, wire up kcov
- 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.
2026-08-04 21:09:07 +00:00

60 lines
1.6 KiB
Bash

#!/usr/bin/env bats
# Tests for skills/obsidian-vault-kb/scripts/vault_backlinks.sh.
load '../helpers/common'
setup() {
sandbox_home
SCRIPT="$REPO_ROOT/skills/obsidian-vault-kb/scripts/vault_backlinks.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 plain [[note]] wikilink" {
run "$SCRIPT" homelab-overview
[ "$status" -eq 0 ]
[[ "$output" == *"dns-setup.md"* ]]
}
@test "finds a [[note|alias]] wikilink" {
cat > "$VAULT/Notes/router.md" << 'EOF'
See [[dns-setup|the DNS note]] for details.
EOF
run "$SCRIPT" dns-setup
[ "$status" -eq 0 ]
[[ "$output" == *"router.md"* ]]
[[ "$output" == *"homelab-overview.md"* ]]
}
@test "a note name with regex metacharacters is handled safely" {
cat > "$VAULT/Notes/weird.md" << 'EOF'
Related: [[weird.name[test]]]
EOF
run "$SCRIPT" 'weird.name[test]'
[ "$status" -eq 0 ]
[[ "$output" == *"weird.md"* ]]
}
@test "excludes backlinks that only exist inside a non-markdown file" {
echo '[[dns-setup]]' > "$VAULT/Notes/attachment2.pdf"
run "$SCRIPT" dns-setup
[ "$status" -eq 0 ]
[[ "$output" == *"homelab-overview.md"* ]]
[[ "$output" != *"attachment2.pdf"* ]]
}
@test "an unlinked note reports no backlinks found" {
run "$SCRIPT" nope-not-a-note
[ "$status" -eq 0 ]
[[ "$output" == *"no backlinks found"* ]]
}
@test "grep fallback still finds backlinks when rg is unavailable" {
hide_command rg
run "$SCRIPT" homelab-overview
[ "$status" -eq 0 ]
[[ "$output" == *"dns-setup.md"* ]]
}