blob: bfacf5f71afaf1e7208009845f927fff30fc9f44 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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" ]
}
|