06bd74d64f
- vault_index.sh: grep fallback for frontmatter tag extraction when rg is unavailable (had this for vault_search.sh/vault_backlinks.sh, not vault_index.sh). - git_cmd.bats: registered repo path that's a file, not a directory (had the obsidian equivalent, not git-manager's). - git_cmd.bats: missing python3 in resolve_repo_path (previously only tested via setup.sh/vault_index.sh, not git_cmd.sh's own _lib.sh). 76 tests now (was 73). kcov: 87.84% (260/296 lines), up from 86.15% -- both target files (vault_index.sh, git-manager _lib.sh) now at 100%. Remaining gap is entirely kcov's inability to trace multi-line python3/awk/jq blocks and bash 'case pattern) ;;' no-op branches, confirmed by checking hit counts on the surrounding lines -- not further closeable by adding tests.
108 lines
2.9 KiB
Bash
108 lines
2.9 KiB
Bash
#!/usr/bin/env bats
|
|
# Tests for skills/obsidian-vault-kb/scripts/vault_index.sh.
|
|
|
|
load '../helpers/common'
|
|
|
|
setup() {
|
|
sandbox_home
|
|
SCRIPT="$REPO_ROOT/skills/obsidian-vault-kb/scripts/vault_index.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 "folder structure excludes .obsidian and .git" {
|
|
run "$SCRIPT" v
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"/Notes"* ]]
|
|
[[ "$output" != *".obsidian"* ]]
|
|
[[ "$output" != *"/.git"* ]]
|
|
}
|
|
|
|
@test "note count per top-level folder counts only .md files" {
|
|
run "$SCRIPT" v
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"Notes: 2"* ]]
|
|
}
|
|
|
|
@test "frontmatter tags are extracted and deduplicated" {
|
|
run "$SCRIPT" v
|
|
[ "$status" -eq 0 ]
|
|
for tag in dns homelab networking overview; do
|
|
[[ "$output" == *"$tag"* ]]
|
|
done
|
|
}
|
|
|
|
@test "grep fallback still extracts tags when rg is unavailable" {
|
|
hide_command rg
|
|
run "$SCRIPT" v
|
|
[ "$status" -eq 0 ]
|
|
for tag in dns homelab networking overview; do
|
|
[[ "$output" == *"$tag"* ]]
|
|
done
|
|
}
|
|
|
|
@test "a note matching *overview* is flagged as a possible MOC file" {
|
|
run "$SCRIPT" v
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"homelab-overview.md"* ]]
|
|
}
|
|
|
|
@test "unknown vault name errors" {
|
|
run "$SCRIPT" not-a-real-vault
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"no vault named"* ]]
|
|
}
|
|
|
|
# --- resolve_vault_path / canonicalize_and_check_dir edge cases ---
|
|
# (exercised via vault_index.sh as a representative of the shared _lib.sh
|
|
# logic used identically by vault_search.sh and vault_backlinks.sh)
|
|
|
|
@test "no config file at all errors" {
|
|
rm -f "$CONFIG_FILE"
|
|
run "$SCRIPT"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"no configuration found"* ]]
|
|
}
|
|
|
|
@test "an empty vaults array errors" {
|
|
write_vault_config "$CONFIG_FILE" "append"
|
|
run "$SCRIPT"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"no vaults defined"* ]]
|
|
}
|
|
|
|
@test "multiple vaults registered without a name errors and lists names" {
|
|
VAULT2="$BATS_TEST_TMPDIR/vault2"
|
|
make_test_vault "$VAULT2"
|
|
write_vault_config "$CONFIG_FILE" "append" "v=$VAULT" "v2=$VAULT2"
|
|
run "$SCRIPT"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"multiple vaults configured"* ]]
|
|
[[ "$output" == *"v2"* ]]
|
|
}
|
|
|
|
@test "a registered vault path that no longer exists errors" {
|
|
write_vault_config "$CONFIG_FILE" "append" "gone=$BATS_TEST_TMPDIR/does-not-exist"
|
|
run "$SCRIPT" gone
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"does not exist"* ]]
|
|
}
|
|
|
|
@test "a registered vault path that is a file, not a directory, errors" {
|
|
FILE_PATH="$BATS_TEST_TMPDIR/not-a-dir"
|
|
echo "just a file" > "$FILE_PATH"
|
|
write_vault_config "$CONFIG_FILE" "append" "plain=$FILE_PATH"
|
|
run "$SCRIPT" plain
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"is not a directory"* ]]
|
|
}
|
|
|
|
@test "missing python3 fails with a clear error instead of a silent crash" {
|
|
hide_command python3
|
|
run "$SCRIPT" v
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"python3 is required"* ]]
|
|
}
|