#!/usr/bin/env bats # # Tests for scripts/remove.sh — interactive removal of rulesets-managed # symlinks under ~/.claude/. # # Strategy (mirrors audit.bats): redirect HOME to a temp dir per test, # scaffold ~/.claude/{skills,rules,hooks} with symlinks pointing at REAL # repo files, run the real remove.sh against that synthetic ~/.claude/. # remove.sh resolves the repo root from its own location, so the "managed" # check compares against the real repo regardless of HOME. REAL_REPO="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)" REMOVE="$REAL_REPO/scripts/remove.sh" setup() { TEST_HOME="$(mktemp -d -t remove-bats.XXXXXX)" HOME_BAK="$HOME" export HOME="$TEST_HOME" mkdir -p "$TEST_HOME/.claude/skills" \ "$TEST_HOME/.claude/rules" \ "$TEST_HOME/.claude/hooks" # Symlinks into real repo files — exactly what `make install` creates. ln -s "$REAL_REPO/debug" "$TEST_HOME/.claude/skills/debug" ln -s "$REAL_REPO/claude-rules/commits.md" "$TEST_HOME/.claude/rules/commits.md" ln -s "$REAL_REPO/hooks/git-commit-confirm.py" \ "$TEST_HOME/.claude/hooks/git-commit-confirm.py" } teardown() { export HOME="$HOME_BAK" rm -rf "$TEST_HOME" } @test "remove --list emits scaffolded skill/rule/hook with correct kinds" { run bash "$REMOVE" --list [ "$status" -eq 0 ] [[ "$output" == *$'skill\tdebug'* ]] [[ "$output" == *$'rule\tcommits.md'* ]] [[ "$output" == *$'hook\tgit-commit-confirm.py'* ]] } @test "remove --list excludes a foreign symlink pointing outside the repo" { ln -s /etc/hostname "$TEST_HOME/.claude/rules/foreign.md" run bash "$REMOVE" --list [ "$status" -eq 0 ] [[ "$output" != *"foreign.md"* ]] # The genuine managed links are still listed. [[ "$output" == *$'rule\tcommits.md'* ]] } @test "remove --remove-selected removes the piped rule and leaves the skill" { run bash -c "printf 'rule\tcommits.md\n' | bash '$REMOVE' --remove-selected" [ "$status" -eq 0 ] [[ "$output" == *"rm rule commits.md"* ]] # Rule symlink gone, skill symlink intact. [ ! -L "$TEST_HOME/.claude/rules/commits.md" ] [ -L "$TEST_HOME/.claude/skills/debug" ] } @test "remove --remove-selected reports a missing item but still processes a valid one after it" { # First line names a link that doesn't exist; second is real. The loop # must report the failure visibly and continue to remove the valid one. run bash -c "printf 'rule\tghost.md\nskill\tdebug\n' | bash '$REMOVE' --remove-selected" [[ "$output" == *"ghost.md"* ]] [[ "$output" == *"rm skill debug"* ]] [ ! -L "$TEST_HOME/.claude/skills/debug" ] } @test "remove --remove-selected with empty stdin is a clean no-op, exit 0" { run bash -c "printf '' | bash '$REMOVE' --remove-selected" [ "$status" -eq 0 ] [ -z "$output" ] # Nothing touched. [ -L "$TEST_HOME/.claude/rules/commits.md" ] [ -L "$TEST_HOME/.claude/skills/debug" ] }