Skip to content

fix: simplify cliproxyapi backup spec preprocessing - #457

Merged
shunkakinoki merged 1 commit into
mainfrom
fix/cliproxyapi-backup-spec
Dec 27, 2025
Merged

fix: simplify cliproxyapi backup spec preprocessing#457
shunkakinoki merged 1 commit into
mainfrom
fix/cliproxyapi-backup-spec

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Dec 27, 2025

Copy link
Copy Markdown
Owner

Refactors the cliproxyapi backup spec to preprocess scripts once at describe-time instead of using nix_script_preprocess helpers. This ensures preprocessed paths are available before any tests run.


Note

Refactors the backup script specs to preprocess target scripts once per suite and run tests against those preprocessed paths.

  • Preprocesses backup-auth.sh and backup-and-recover.sh at describe-time into a temp dir using sed (replacing @aws@, @rsync@, @bash@, @sed@ and wiring @backupAuthScript@), then marks them executable
  • Removes nix_script_preprocess/nix_script_preprocess_with_deps and related cleanup; updates When run ... to invoke the preprocessed scripts directly
  • Cleans up test env usage (sets HOME inline), maintains aws/rsync mocks, and adds AfterAll to delete the temp preprocessed directory
  • Test assertions unchanged: R2 pull/skip-push behavior, push when auth exists, and .env sourcing + backup flow

Written by Cursor Bugbot for commit 2703814. Configure here.


Summary by cubic

Preprocess the cliproxyapi backup scripts once at describe-time so tests use stable, real paths before any test runs. Removes nix_script_preprocess helpers to cut setup overhead and reduce flakiness.

  • Refactors
    • Preprocess backup-auth.sh and backup-and-recover.sh into a mktemp dir with sed and make them executable.
    • Replace @backupAuthScript@ with the preprocessed backup-auth path in backup-and-recover.sh.
    • Update tests to call the preprocessed scripts directly and set HOME inline.
    • Remove nix_script_preprocess/_with_deps usage and related cleanup; add AfterAll to delete the temp dir.

Written for commit 2703814. Summary will update automatically on new commits.

Copilot AI review requested due to automatic review settings December 27, 2025 07:35
@mesa-dot-dev

mesa-dot-dev Bot commented Dec 27, 2025

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@coderabbitai

coderabbitai Bot commented Dec 27, 2025

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Enhanced test setup procedures for backup script validation by implementing a more efficient preprocessing approach and improved cleanup handling, reducing setup overhead and improving test reliability.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Moves backup script preprocessing from per-test setup to describe-time initialization. Creates a temporary directory and preprocesses backup-auth.sh and backup-and-recover.sh by substituting placeholders and injecting processed script paths. Updates test invocations to reference the pre-generated scripts. Removes per-test preprocessing calls and adds cleanup to remove the temporary directory after all tests complete.

Changes

Cohort / File(s) Summary
Backup Script Test Preprocessing
spec/cliproxyapi_backup_spec.sh
Relocates preprocessing from per-test setup to describe-time initialization; creates temporary directory for preprocessed scripts; preprocesses backup-auth.sh and backup-and-recover.sh with placeholder substitutions and path injection; replaces test invocations to use __BACKUP_AUTH_SCRIPT and __BACKUP_RECOVER_SCRIPT variables; removes in-test nix_script_preprocess and nix_script_preprocess_with_deps calls; adds AfterAll cleanup block

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Hop! The scripts preprocess up front,
No slow setup for each test's hunt,
Temp dirs dance, then vanish clean—
Faster tests have never been seen!

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/cliproxyapi-backup-spec

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4cec2bb and 2703814.

📒 Files selected for processing (1)
  • spec/cliproxyapi_backup_spec.sh

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.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @shunkakinoki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the testing strategy for cliproxyapi backup scripts by centralizing the script preprocessing step. Instead of performing preprocessing within each test's setup phase, the scripts are now processed once at the beginning of the test description block. This change aims to streamline test execution, improve the reliability of test environments by ensuring consistent script availability, and simplify the overall test setup by removing redundant preprocessing calls.

Highlights

  • Preprocessing Logic Refactor: The script preprocessing logic has been moved from individual setup() functions to execute once at the describe-time for the entire test suite. This ensures preprocessed paths are available before any tests run.
  • Removal of Helper Functions: The nix_script_preprocess and nix_script_preprocess_with_deps helper functions have been removed, replaced by direct sed commands for placeholder substitution.
  • Temporary Directory Management: A temporary directory (__PREPROCESSED_DIR) is now created at describe-time to store the preprocessed scripts, and an AfterAll hook is added to ensure its cleanup.
  • Test Command Updates: Test execution commands (When run bash -c ...) have been updated to directly reference the paths of the newly preprocessed scripts, __BACKUP_AUTH_SCRIPT and __BACKUP_RECOVER_SCRIPT.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@shunkakinoki
shunkakinoki merged commit df81151 into main Dec 27, 2025
32 of 33 checks passed
@shunkakinoki
shunkakinoki deleted the fix/cliproxyapi-backup-spec branch December 27, 2025 07:36
@mesa-dot-dev

mesa-dot-dev Bot commented Dec 27, 2025

Copy link
Copy Markdown

Mesa Description

TL;DR

Simplified cliproxyapi backup spec preprocessing by moving script preprocessing to describe-time, ensuring paths are available before tests.

What changed?

File-level changes are not available.

Description generated by Mesa. Update settings

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the backup spec tests to preprocess scripts once at the beginning, which is a great improvement for efficiency. The changes look good overall. I've added a couple of suggestions to improve the maintainability and robustness of the new preprocessing and cleanup logic.

Comment on lines +109 to +111
cleanup_preprocessed() {
rm -rf "$__PREPROCESSED_DIR"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

For improved safety, it's a good practice to add a check to ensure that __PREPROCESSED_DIR is a non-empty string and an existing directory before attempting to remove it recursively. This prevents accidental deletion of unintended files or directories if the variable were to be unexpectedly empty or unset.

Suggested change
cleanup_preprocessed() {
rm -rf "$__PREPROCESSED_DIR"
}
cleanup_preprocessed() {
if [[ -n "$__PREPROCESSED_DIR" && -d "$__PREPROCESSED_DIR" ]]; then
rm -rf "$__PREPROCESSED_DIR"
fi
}

Comment on lines +9 to +30
__PREPROCESSED_DIR=$(mktemp -d)
__BACKUP_AUTH_SCRIPT="$__PREPROCESSED_DIR/backup-auth.sh"
__BACKUP_RECOVER_SCRIPT="$__PREPROCESSED_DIR/backup-and-recover.sh"

# Preprocess backup-auth.sh
sed \
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
"$SCRIPTS_DIR/backup-auth.sh" >"$__BACKUP_AUTH_SCRIPT"
chmod +x "$__BACKUP_AUTH_SCRIPT"

# Preprocess backup-and-recover.sh with path to preprocessed backup-auth.sh
sed \
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
-e "s|@backupAuthScript@|$__BACKUP_AUTH_SCRIPT|g" \
"$SCRIPTS_DIR/backup-and-recover.sh" >"$__BACKUP_RECOVER_SCRIPT"
chmod +x "$__BACKUP_RECOVER_SCRIPT"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability and reduce code duplication, you can define the common sed arguments in an array and reuse it. Also, consider using mktemp -d -t <template> to create temporary directories with a more descriptive name, which can aid in debugging.

Suggested change
__PREPROCESSED_DIR=$(mktemp -d)
__BACKUP_AUTH_SCRIPT="$__PREPROCESSED_DIR/backup-auth.sh"
__BACKUP_RECOVER_SCRIPT="$__PREPROCESSED_DIR/backup-and-recover.sh"
# Preprocess backup-auth.sh
sed \
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
"$SCRIPTS_DIR/backup-auth.sh" >"$__BACKUP_AUTH_SCRIPT"
chmod +x "$__BACKUP_AUTH_SCRIPT"
# Preprocess backup-and-recover.sh with path to preprocessed backup-auth.sh
sed \
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
-e "s|@backupAuthScript@|$__BACKUP_AUTH_SCRIPT|g" \
"$SCRIPTS_DIR/backup-and-recover.sh" >"$__BACKUP_RECOVER_SCRIPT"
chmod +x "$__BACKUP_RECOVER_SCRIPT"
__PREPROCESSED_DIR=$(mktemp -d -t cliproxy-spec-XXXXXXXX)
__BACKUP_AUTH_SCRIPT="$__PREPROCESSED_DIR/backup-auth.sh"
__BACKUP_RECOVER_SCRIPT="$__PREPROCESSED_DIR/backup-and-recover.sh"
COMMON_SED_ARGS=(
-e 's|@aws@|aws|g'
-e 's|@rsync@|rsync|g'
-e 's|@bash@|bash|g'
-e 's|@sed@|sed|g'
)
# Preprocess backup-auth.sh
sed "${COMMON_SED_ARGS[@]}" "$SCRIPTS_DIR/backup-auth.sh" >"$__BACKUP_AUTH_SCRIPT"
chmod +x "$__BACKUP_AUTH_SCRIPT"
# Preprocess backup-and-recover.sh with path to preprocessed backup-auth.sh
sed "${COMMON_SED_ARGS[@]}" \
-e "s|@backupAuthScript@|$__BACKUP_AUTH_SCRIPT|g" \
"$SCRIPTS_DIR/backup-and-recover.sh" >"$__BACKUP_RECOVER_SCRIPT"
chmod +x "$__BACKUP_RECOVER_SCRIPT"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the cliproxyapi_backup_spec.sh test file to preprocess script placeholders once at describe-time rather than during each test setup. This ensures preprocessed script paths are available before any tests run, eliminating the need for the nix_script_preprocess helper functions.

Key Changes:

  • Moved script preprocessing from test setup to describe-time, creating preprocessed scripts once in a temporary directory
  • Replaced nix_script_preprocess and nix_script_preprocess_with_deps calls with direct sed commands
  • Added AfterAll cleanup hook to remove the preprocessed directory after all tests complete

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


# Preprocess scripts once at describe-time (not in setup)
# This ensures the preprocessed paths are available before any tests run
__PREPROCESSED_DIR=$(mktemp -d)

Copilot AI Dec 27, 2025

Copy link

Choose a reason for hiding this comment

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

The temporary directory created at describe-time is not cleaned up if the test suite is interrupted before reaching the AfterAll hook. This could lead to accumulating temporary directories in /tmp. Consider using a trap or ensuring the cleanup happens even on early exit or test failure.

Suggested change
__PREPROCESSED_DIR=$(mktemp -d)
__PREPROCESSED_DIR=$(mktemp -d)
__cleanup_preprocessed_dir() {
if [ -n "$__PREPROCESSED_DIR" ] && [ -d "$__PREPROCESSED_DIR" ]; then
rm -rf "$__PREPROCESSED_DIR"
fi
}
# Ensure the preprocessed directory is cleaned up even if the test suite is interrupted
trap '__cleanup_preprocessed_dir' EXIT INT TERM

Copilot uses AI. Check for mistakes.
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \

Copilot AI Dec 27, 2025

Copy link

Choose a reason for hiding this comment

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

The sed replacement for @Sed@ placeholder is unnecessary here because the backup-auth.sh script does not use @Sed@. Looking at the actual script content, only @aws@ and @rsync@ placeholders are present in backup-auth.sh. Including unnecessary replacements can be confusing and may mask issues if the wrong script is accidentally preprocessed.

Suggested change
-e 's|@sed@|sed|g' \

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +27
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \

Copilot AI Dec 27, 2025

Copy link

Choose a reason for hiding this comment

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

The sed replacements for @aws@, @rsync@, and @Sed@ are unnecessary for backup-and-recover.sh. Looking at the actual script content, it only uses @bash@ and @backupAuthScript@ placeholders. Including unnecessary replacements makes the preprocessing logic harder to maintain and understand.

Suggested change
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
-e 's|@bash@|bash|g' \

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +30
sed \
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
"$SCRIPTS_DIR/backup-auth.sh" >"$__BACKUP_AUTH_SCRIPT"
chmod +x "$__BACKUP_AUTH_SCRIPT"

# Preprocess backup-and-recover.sh with path to preprocessed backup-auth.sh
sed \
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
-e "s|@backupAuthScript@|$__BACKUP_AUTH_SCRIPT|g" \
"$SCRIPTS_DIR/backup-and-recover.sh" >"$__BACKUP_RECOVER_SCRIPT"
chmod +x "$__BACKUP_RECOVER_SCRIPT"

Copilot AI Dec 27, 2025

Copy link

Choose a reason for hiding this comment

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

The preprocessing sed commands do not check for errors. If the source script files don't exist or if writing to the output fails, the test will continue with potentially empty or corrupted script files, leading to confusing test failures. Consider adding error checking after these preprocessing operations.

Suggested change
sed \
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
"$SCRIPTS_DIR/backup-auth.sh" >"$__BACKUP_AUTH_SCRIPT"
chmod +x "$__BACKUP_AUTH_SCRIPT"
# Preprocess backup-and-recover.sh with path to preprocessed backup-auth.sh
sed \
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
-e "s|@backupAuthScript@|$__BACKUP_AUTH_SCRIPT|g" \
"$SCRIPTS_DIR/backup-and-recover.sh" >"$__BACKUP_RECOVER_SCRIPT"
chmod +x "$__BACKUP_RECOVER_SCRIPT"
if ! sed \
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
"$SCRIPTS_DIR/backup-auth.sh" >"$__BACKUP_AUTH_SCRIPT"; then
echo "Error: failed to preprocess backup-auth.sh from $SCRIPTS_DIR" >&2
exit 1
fi
if ! chmod +x "$__BACKUP_AUTH_SCRIPT"; then
echo "Error: failed to make preprocessed backup-auth.sh executable at $__BACKUP_AUTH_SCRIPT" >&2
exit 1
fi
# Preprocess backup-and-recover.sh with path to preprocessed backup-auth.sh
if ! sed \
-e 's|@aws@|aws|g' \
-e 's|@rsync@|rsync|g' \
-e 's|@bash@|bash|g' \
-e 's|@sed@|sed|g' \
-e "s|@backupAuthScript@|$__BACKUP_AUTH_SCRIPT|g" \
"$SCRIPTS_DIR/backup-and-recover.sh" >"$__BACKUP_RECOVER_SCRIPT"; then
echo "Error: failed to preprocess backup-and-recover.sh from $SCRIPTS_DIR" >&2
exit 1
fi
if ! chmod +x "$__BACKUP_RECOVER_SCRIPT"; then
echo "Error: failed to make preprocessed backup-and-recover.sh executable at $__BACKUP_RECOVER_SCRIPT" >&2
exit 1
fi

Copilot uses AI. Check for mistakes.
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.

2 participants