#!/usr/bin/env bats # Tests for lib/core/bundle_resolver.sh. Validates the filesystem-fallback path: # we cannot rely on Spotlight indexing a fake /Applications under a tmpdir, # so each test forces the Spotlight path to miss (no binary or empty result) # and asserts the filesystem scan finds the app. setup_file() { PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)" export PROJECT_ROOT } setup() { FAKE_HOME="$(mktemp -d "${BATS_TEST_DIRNAME}/tmp-bundle-home.XXXXXX")" export FAKE_HOME mkdir -p "$FAKE_HOME/Applications" # Stage a fake /Applications tree inside the tmp area. bundle_has_installed_app # hardcodes the real /Applications roots, so we patch _MOLE_BUNDLE_RESOLVER_APP_ROOTS # from the test harness itself. FAKE_APPS="$FAKE_HOME/FakeApplications" export FAKE_APPS mkdir -p "$FAKE_APPS" } teardown() { rm -rf "$FAKE_HOME" } # Shared prelude: source base + resolver, disable mdfind, point resolver at FAKE_APPS. prelude() { cat <<'EOF' set -euo pipefail source "$PROJECT_ROOT/lib/core/base.sh" source "$PROJECT_ROOT/lib/core/timeout.sh" source "$PROJECT_ROOT/lib/core/bundle_resolver.sh" # Force Spotlight miss so we test only the filesystem fallback. mdfind() { return 0; } export -f mdfind # Override the hardcoded app roots for the test. _MOLE_BUNDLE_RESOLVER_APP_ROOTS=("$FAKE_APPS") EOF } make_app() { local app_dir="$1" local bundle_id="$2" mkdir -p "$app_dir/Contents" cat > "$app_dir/Contents/Info.plist" < CFBundleIdentifier $bundle_id EOF } @test "bundle_has_installed_app finds an app by CFBundleIdentifier (Spotlight miss)" { make_app "$FAKE_APPS/KeePassXC.app" "org.keepassxc.KeePassXC" run env FAKE_APPS="$FAKE_APPS" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc < "$app/Contents/Library/LaunchServices/com.adobe.ARMDC.SMJobBlessHelper" run env FAKE_APPS="$FAKE_APPS" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <