Files
skill-repo/tests/obsidian-vault-kb/vault_backlinks.bats
T
Henner M. Kruse 2d25e69632 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.
2026-08-04 19:34:51 +00:00

53 lines
1.4 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"* ]]
}