From bbffe40d5a46846f6d1ad70b0d17e18f3846ef37 Mon Sep 17 00:00:00 2001 From: Test User Date: Wed, 13 May 2026 23:29:26 +0300 Subject: [PATCH 1/2] fix: make backup wrapper self-contained --- scripts/launchd/backup-daily.sh | 5 +++++ scripts/launchd/install.sh | 4 +++- tests/test_backup_daily.py | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/launchd/backup-daily.sh b/scripts/launchd/backup-daily.sh index 8dba1ae..b541fda 100755 --- a/scripts/launchd/backup-daily.sh +++ b/scripts/launchd/backup-daily.sh @@ -3,5 +3,10 @@ set -euo pipefail export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin" export PYTHONUNBUFFERED=1 +BRAINLAYER_DIR="${BRAINLAYER_DIR:-__BRAINLAYER_DIR__}" +if [ "$BRAINLAYER_DIR" = "__BRAINLAYER_DIR__" ]; then + BRAINLAYER_DIR="$HOME/Gits/brainlayer" +fi +export PYTHONPATH="$BRAINLAYER_DIR/src${PYTHONPATH:+:$PYTHONPATH}" exec "${BRAINLAYER_PYTHON:-python3}" -m brainlayer.backup_daily diff --git a/scripts/launchd/install.sh b/scripts/launchd/install.sh index 48a9c19..c602e6f 100755 --- a/scripts/launchd/install.sh +++ b/scripts/launchd/install.sh @@ -106,7 +106,9 @@ install_backup_script() { return 1 fi - cp "$src" "$dst" + sed \ + -e "s|__BRAINLAYER_DIR__|$BRAINLAYER_DIR|g" \ + "$src" > "$dst" chmod 755 "$dst" echo "Installed: $dst" } diff --git a/tests/test_backup_daily.py b/tests/test_backup_daily.py index 5442251..eda6729 100644 --- a/tests/test_backup_daily.py +++ b/tests/test_backup_daily.py @@ -100,16 +100,22 @@ def files(self): def test_launchd_installer_knows_backup_target(): install_path = Path("scripts/launchd/install.sh") + wrapper_path = Path("scripts/launchd/backup-daily.sh") plist_path = Path("scripts/launchd/com.brainlayer.backup-daily.plist") assert install_path.is_file(), f"Installer not found at {install_path}; check test working directory" + assert wrapper_path.is_file(), f"Backup wrapper not found at {wrapper_path}; check launchd wrapper is committed" assert plist_path.is_file(), f"Backup plist not found at {plist_path}; check launchd template is committed" install = install_path.read_text() + wrapper = wrapper_path.read_text() plist = plist_path.read_text() assert "backup-daily" in install assert "install_backup_script" in install + assert "__BRAINLAYER_DIR__" in install + assert "PYTHONPATH" in wrapper + assert "__BRAINLAYER_DIR__" in wrapper assert "com.brainlayer.backup-daily" in plist assert "3" in plist assert "17" in plist From 2b4011a6408db3e21e559611e107ee2225258cda Mon Sep 17 00:00:00 2001 From: Test User Date: Wed, 13 May 2026 23:38:27 +0300 Subject: [PATCH 2/2] fix: preserve installed backup wrapper path --- scripts/launchd/backup-daily.sh | 8 ++++---- scripts/launchd/install.sh | 4 +++- tests/test_backup_daily.py | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/launchd/backup-daily.sh b/scripts/launchd/backup-daily.sh index b541fda..5d06d51 100755 --- a/scripts/launchd/backup-daily.sh +++ b/scripts/launchd/backup-daily.sh @@ -3,10 +3,10 @@ set -euo pipefail export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin" export PYTHONUNBUFFERED=1 -BRAINLAYER_DIR="${BRAINLAYER_DIR:-__BRAINLAYER_DIR__}" -if [ "$BRAINLAYER_DIR" = "__BRAINLAYER_DIR__" ]; then - BRAINLAYER_DIR="$HOME/Gits/brainlayer" -fi +BRAINLAYER_DIR="${BRAINLAYER_DIR:-__BRAINLAYER_DIR_VALUE__}" +case "$BRAINLAYER_DIR" in + __BRAINLAYER_DIR_*) BRAINLAYER_DIR="$HOME/Gits/brainlayer" ;; +esac export PYTHONPATH="$BRAINLAYER_DIR/src${PYTHONPATH:+:$PYTHONPATH}" exec "${BRAINLAYER_PYTHON:-python3}" -m brainlayer.backup_daily diff --git a/scripts/launchd/install.sh b/scripts/launchd/install.sh index c602e6f..1ec6ffa 100755 --- a/scripts/launchd/install.sh +++ b/scripts/launchd/install.sh @@ -100,14 +100,16 @@ install_plist() { install_backup_script() { local src="$SCRIPT_DIR/backup-daily.sh" local dst="$BRAINLAYER_LIB_DIR/backup-daily.sh" + local escaped_brainlayer_dir if [ ! -f "$src" ]; then echo "ERROR: $src not found" return 1 fi + escaped_brainlayer_dir="$(printf '%s' "$BRAINLAYER_DIR" | sed 's/[\\&|]/\\&/g')" sed \ - -e "s|__BRAINLAYER_DIR__|$BRAINLAYER_DIR|g" \ + -e "s|__BRAINLAYER_DIR_VALUE__|$escaped_brainlayer_dir|g" \ "$src" > "$dst" chmod 755 "$dst" echo "Installed: $dst" diff --git a/tests/test_backup_daily.py b/tests/test_backup_daily.py index eda6729..fbd059d 100644 --- a/tests/test_backup_daily.py +++ b/tests/test_backup_daily.py @@ -113,9 +113,10 @@ def test_launchd_installer_knows_backup_target(): assert "backup-daily" in install assert "install_backup_script" in install - assert "__BRAINLAYER_DIR__" in install + assert "escaped_brainlayer_dir" in install + assert "__BRAINLAYER_DIR_VALUE__" in install assert "PYTHONPATH" in wrapper - assert "__BRAINLAYER_DIR__" in wrapper + assert "__BRAINLAYER_DIR_VALUE__" in wrapper assert "com.brainlayer.backup-daily" in plist assert "3" in plist assert "17" in plist