-
Notifications
You must be signed in to change notification settings - Fork 0
fix: simplify cliproxyapi backup spec preprocessing #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,14 +4,37 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Describe 'cliproxyapi backup scripts' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SCRIPTS_DIR="$PWD/home-manager/services/cliproxyapi/scripts" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Preprocess scripts once at describe-time (not in setup) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # This ensures the preprocessed paths are available before any tests run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __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' \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -e 's|@sed@|sed|g' \ |
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
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.
| -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' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| __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
Dec 27, 2025
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| cleanup_preprocessed() { | |
| rm -rf "$__PREPROCESSED_DIR" | |
| } | |
| cleanup_preprocessed() { | |
| if [[ -n "$__PREPROCESSED_DIR" && -d "$__PREPROCESSED_DIR" ]]; then | |
| rm -rf "$__PREPROCESSED_DIR" | |
| fi | |
| } |
There was a problem hiding this comment.
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.