From 45c98c2ec89ef44814338f15fb72e6297feba1ff Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sun, 15 Mar 2026 08:55:17 +0800 Subject: [PATCH] fix: explicitly skip system binary launch agents and harden test isolation Add hint_is_system_binary() to short-circuit detection for plists that use /bin/*, /usr/bin/*, /usr/libexec/* etc. as their program path. These are custom scripts, not app-backed launch agents, so the stale detection logic does not apply. Previously the function relied on the absence of AssociatedBundleIdentifiers as an implicit skip, which could fail on certain macOS plutil edge cases. Also add teardown() in clean_hints.bats to explicitly remove the LaunchAgents directory after each test, and add run_with_timeout mock in the "skips custom shell wrappers" test to prevent mdfind from influencing results. This eliminates the intermittent failure where test 70 showed "Review:" in output without "Potential stale login item:". --- lib/clean/hints.sh | 16 ++++++++++++++++ tests/clean_hints.bats | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/lib/clean/hints.sh b/lib/clean/hints.sh index 0ac04dd..570b596 100644 --- a/lib/clean/hints.sh +++ b/lib/clean/hints.sh @@ -100,6 +100,19 @@ hint_is_app_scoped_launch_target() { return 1 } +# shellcheck disable=SC2329 +hint_is_system_binary() { + local program="$1" + + case "$program" in + /bin/* | /sbin/* | /usr/bin/* | /usr/sbin/* | /usr/libexec/*) + return 0 + ;; + esac + + return 1 +} + # shellcheck disable=SC2329 hint_launch_agent_bundle_exists() { local bundle_id="$1" @@ -433,6 +446,9 @@ show_user_launch_agent_hint_notice() { local associated="" program=$(hint_extract_launch_agent_program_path "$plist") + if [[ -n "$program" ]] && hint_is_system_binary "$program"; then + continue + fi if [[ -n "$program" ]] && hint_is_app_scoped_launch_target "$program" && [[ ! -e "$program" ]]; then reason="Missing app/helper target" target="${program/#$HOME/~}" diff --git a/tests/clean_hints.bats b/tests/clean_hints.bats index 928c76c..634ba39 100644 --- a/tests/clean_hints.bats +++ b/tests/clean_hints.bats @@ -23,6 +23,10 @@ setup() { mkdir -p "$HOME/.config/mole" } +teardown() { + rm -rf "$HOME/Library/LaunchAgents" +} + @test "probe_project_artifact_hints reuses purge targets and excludes noisy names" { local root="$HOME/hints-root" mkdir -p "$root/proj/node_modules" "$root/proj/vendor" "$root/proj/bin" @@ -153,6 +157,7 @@ set -euo pipefail source "$PROJECT_ROOT/lib/core/common.sh" source "$PROJECT_ROOT/lib/clean/hints.sh" note_activity() { :; } +run_with_timeout() { shift; "$@"; } show_user_launch_agent_hint_notice EOT5