aboutsummaryrefslogtreecommitdiff
path: root/scripts/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-22 17:38:56 -0500
committerCraig Jennings <c@cjennings.net>2026-05-22 17:38:56 -0500
commit95f57618b1e55b910d143fa6d188323a1cc4484f (patch)
tree84cebbba456466ad8c0453f3964481ba813d32f5 /scripts/tests
parentca6a213841129a72881f17d7050dff3b48c637ac (diff)
downloadrulesets-95f57618b1e55b910d143fa6d188323a1cc4484f.tar.gz
rulesets-95f57618b1e55b910d143fa6d188323a1cc4484f.zip
feat(make): add an interactive remove target with fzf
make remove is the granular counterpart to make uninstall, which removes everything. remove.sh lists every rulesets-managed symlink under ~/.claude/ — only links whose target resolves into the repo, so foreign symlinks are left alone — pipes them through fzf --multi, and rm's the picked links. The repo's own files stay put, and make install re-creates anything removed. It's split into --list and --remove-selected modes so the logic is testable without fzf. 5 bats cases cover the listing, the foreign-link exclusion, removal, report-and-continue on a missing target, and the empty no-op. The removal loop runs without set -e and without rm -f, so a vanished target reports visibly and the rest still process. shellcheck clean, make test green.
Diffstat (limited to 'scripts/tests')
-rw-r--r--scripts/tests/remove.bats83
1 files changed, 83 insertions, 0 deletions
diff --git a/scripts/tests/remove.bats b/scripts/tests/remove.bats
new file mode 100644
index 0000000..bfacf5f
--- /dev/null
+++ b/scripts/tests/remove.bats
@@ -0,0 +1,83 @@
+#!/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" ]
+}