Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/watch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,23 @@ _watch_run() {

# ── Setup / Remove ───────────────────────────────────────────────────────────

# Absolute, stable path to the installed devflow launcher for a scheduled entry.
# `command -v devflow` can return a RELATIVE path (e.g. ./bin/devflow when PATH has a
# relative entry), and a launchd/cron job needs an ABSOLUTE target that survives
# auto-reinstall. Prefer the copy-install BINDIR launcher derived from DEVFLOW_ROOT
# (<prefix>/share/devflow -> <prefix>/bin/devflow); otherwise absolutize command -v.
_devflow_launcher() {
if [[ "${DEVFLOW_ROOT:-}" == */share/devflow && -x "${DEVFLOW_ROOT%/share/devflow}/bin/devflow" ]]; then
echo "${DEVFLOW_ROOT%/share/devflow}/bin/devflow"; return
fi
local dfb; dfb="$(command -v devflow 2>/dev/null || echo "${DEVFLOW_ROOT:-$(devflow_root)}/bin/devflow")"
case "$dfb" in
/*) echo "$dfb" ;;
*) local d; d="$(cd "$(dirname "$dfb")" 2>/dev/null && pwd)"
if [[ -n "$d" ]]; then echo "${d}/$(basename "$dfb")"; else echo "${HOME}/.local/bin/devflow"; fi ;;
esac
}

# ── native scheduler backend: macOS launchd ──────────────────────────────────
# A per-project LaunchAgent, not cron: macOS user-cron is unreliable (does not fire
# after sleep). StartCalendarInterval (not StartInterval) is used deliberately -
Expand Down Expand Up @@ -645,7 +662,7 @@ _watch_setup() {
project_dir="$(cd "$project_dir" && pwd)" # resolve to absolute

local devflow_bin
devflow_bin="$(command -v devflow 2>/dev/null || echo "${DEVFLOW_ROOT:-$(devflow_root)}/bin/devflow")"
devflow_bin="$(_devflow_launcher)" # absolute + stable (never a relative ./bin/devflow)

section "Sensitive File Watchdog Setup"
echo ""
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/watch.bats
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,22 @@ EOF
assert_output --partial "<key>EnvironmentVariables</key>"
assert_output --partial "<key>PATH</key><string>/Users/x/.local/bin:"
}

# ── _devflow_launcher: absolute + stable scheduler target ──────

@test "devflow_launcher derives the copy-install BINDIR launcher from DEVFLOW_ROOT" {
local pfx="${BATS_TEST_TMPDIR}/pref"; mkdir -p "$pfx/bin" "$pfx/share/devflow"
printf '#!/bin/bash\n' > "$pfx/bin/devflow"; chmod +x "$pfx/bin/devflow"
DEVFLOW_ROOT="$pfx/share/devflow" run _devflow_launcher
assert_success
assert_output "$pfx/bin/devflow"
}

@test "devflow_launcher always returns an absolute path" {
# copy-install derivation (the common path) must be absolute
local pfx="${BATS_TEST_TMPDIR}/pref2"; mkdir -p "$pfx/bin" "$pfx/share/devflow"
printf '#!/bin/bash\n' > "$pfx/bin/devflow"; chmod +x "$pfx/bin/devflow"
DEVFLOW_ROOT="$pfx/share/devflow" run _devflow_launcher
assert_success
[[ "$output" == /* ]] || fail "not absolute: $output"
}
Loading