Skip to content

Make backup wrapper self-contained#281

Merged
EtanHey merged 2 commits into
mainfrom
fix/backup-wrapper-pythonpath
May 13, 2026
Merged

Make backup wrapper self-contained#281
EtanHey merged 2 commits into
mainfrom
fix/backup-wrapper-pythonpath

Conversation

@EtanHey
Copy link
Copy Markdown
Owner

@EtanHey EtanHey commented May 13, 2026

Summary

  • make scripts/launchd/backup-daily.sh set PYTHONPATH itself using installed BrainLayer repo path
  • have launchd installer expand __BRAINLAYER_DIR__ into the copied wrapper
  • cover wrapper self-contained behavior in backup launchd test

Why

Manual execution of ~/.local/lib/brainlayer/backup-daily.sh failed after PR #280 because PYTHONPATH was only provided by the LaunchAgent plist. The wrapper needs to work both from launchd and direct manual restore/proof runs.

Verification

  • python3 -m pytest tests/test_backup_daily.py -q -> 4 passed
  • bash -n scripts/launchd/backup-daily.sh scripts/launchd/install.sh -> passed
  • pre-push gate -> 1827 passed, 9 skipped, 75 deselected, 1 xfailed; MCP registration 3 passed; eval/hook routing 32 passed; Bun 1 pass; regression shell pass

Note

Low Risk
Low risk shell-script change that only affects the launchd-installed daily backup wrapper and its install-time templating; main risk is mis-resolving BRAINLAYER_DIR or bad escaping causing backups to fail to run.

Overview
Makes backup-daily.sh self-contained by resolving BRAINLAYER_DIR (env or install-time placeholder, with a fallback) and exporting PYTHONPATH to include src before running brainlayer.backup_daily.

Updates the launchd installer to generate the installed backup wrapper via sed substitution of __BRAINLAYER_DIR_VALUE__ (with escaping) instead of copying verbatim, and extends test_backup_daily.py to assert the placeholder/substitution plumbing and wrapper PYTHONPATH setup are present.

Reviewed by Cursor Bugbot for commit 2b4011a. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Make backup wrapper self-contained by templating BRAINLAYER_DIR and PYTHONPATH at install time

  • backup-daily.sh now contains a __BRAINLAYER_DIR_VALUE__ placeholder and sets PYTHONPATH to include $BRAINLAYER_DIR/src, rather than relying on the environment at runtime.
  • install.sh substitutes the placeholder with the actual BRAINLAYER_DIR value (with special characters escaped) via sed when copying the script, instead of a verbatim cp.
  • Tests in test_backup_daily.py verify the placeholder and PYTHONPATH are present in the wrapper and that the installer references the substitution logic.

Macroscope summarized 2b4011a.

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@EtanHey
Copy link
Copy Markdown
Owner Author

EtanHey commented May 13, 2026

@coderabbitai review

@EtanHey
Copy link
Copy Markdown
Owner Author

EtanHey commented May 13, 2026

@codex review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Warning

Rate limit exceeded

@EtanHey has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 4 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: af5d83d3-5bd3-4fb1-a7d3-44ec8f402ab9

📥 Commits

Reviewing files that changed from the base of the PR and between ec4a544 and 2b4011a.

📒 Files selected for processing (3)
  • scripts/launchd/backup-daily.sh
  • scripts/launchd/install.sh
  • tests/test_backup_daily.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/backup-wrapper-pythonpath

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbffe40d5a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/launchd/install.sh Outdated

cp "$src" "$dst"
sed \
-e "s|__BRAINLAYER_DIR__|$BRAINLAYER_DIR|g" \
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Escape BRAINLAYER_DIR before sed replacement

When the repository path contains sed replacement metacharacters such as & (for example a checkout under ~/R&D/brainlayer), this substitution writes a corrupted path into the installed wrapper because & expands to the matched placeholder in the replacement. The resulting PYTHONPATH points at a non-existent directory, so manual or launchd backup runs can fail to import brainlayer; escape the replacement string or use a safer templating approach before writing the wrapper.

Useful? React with 👍 / 👎.

Comment thread scripts/launchd/backup-daily.sh Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bbffe40. Configure here.

Comment thread scripts/launchd/backup-daily.sh Outdated
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b4011a640

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

cp "$src" "$dst"
escaped_brainlayer_dir="$(printf '%s' "$BRAINLAYER_DIR" | sed 's/[\\&|]/\\&/g')"
sed \
-e "s|__BRAINLAYER_DIR_VALUE__|$escaped_brainlayer_dir|g" \
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Quote the embedded repository path for the shell

When the checkout path contains shell syntax characters such as ", `, or $(, this writes the raw path into the generated backup-daily.sh assignment; sed escaping only protects the sed replacement, not the shell source that will be parsed later. For example a repo under a directory containing " produces an unterminated BRAINLAYER_DIR="${BRAINLAYER_DIR:-...}" line, so manual and launchd backup runs fail before importing brainlayer; use shell-safe quoting/escaping for the value before embedding it.

Useful? React with 👍 / 👎.

@EtanHey EtanHey merged commit 353ab3d into main May 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant