1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 19:40:07 +00:00

fix: preserve interrupt semantics and restore purge traps

This commit is contained in:
tw93
2026-02-27 11:18:53 +08:00
parent 194fe871e5
commit a9433e4acd
5 changed files with 81 additions and 0 deletions

View File

@@ -110,6 +110,19 @@ teardown() {
[ "$status" -eq 0 ]
}
@test "safe_remove preserves interrupt exit codes" {
local test_file="$TEST_DIR/interrupt_file"
echo "test" > "$test_file"
run bash -c "
source '$PROJECT_ROOT/lib/core/common.sh'
rm() { return 130; }
safe_remove '$test_file' true
"
[ "$status" -eq 130 ]
[ -f "$test_file" ]
}
@test "safe_remove in silent mode suppresses error output" {
run bash -c "source '$PROJECT_ROOT/lib/core/common.sh'; safe_remove '/System/test' true 2>&1"
[ "$status" -eq 1 ]

View File

@@ -308,6 +308,44 @@ EOF
[ "$status" -eq 0 ]
}
@test "select_purge_categories restores caller EXIT/INT/TERM traps" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/clean/project.sh"
trap 'echo parent-exit' EXIT
trap 'echo parent-int' INT
trap 'echo parent-term' TERM
before_exit=$(trap -p EXIT)
before_int=$(trap -p INT)
before_term=$(trap -p TERM)
PURGE_CATEGORY_SIZES="1"
PURGE_RECENT_CATEGORIES="false"
select_purge_categories "demo" <<< $'\n' > /dev/null 2>&1 || true
after_exit=$(trap -p EXIT)
after_int=$(trap -p INT)
after_term=$(trap -p TERM)
if [[ "$before_exit" == "$after_exit" && "$before_int" == "$after_int" && "$before_term" == "$after_term" ]]; then
echo "PASS"
else
echo "FAIL"
echo "before_exit=$before_exit"
echo "after_exit=$after_exit"
echo "before_int=$before_int"
echo "after_int=$after_int"
echo "before_term=$before_term"
echo "after_term=$after_term"
exit 1
fi
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"PASS"* ]]
}
@test "confirm_purge_cleanup accepts Enter" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
set -euo pipefail