Skip to content
Merged
Changes from 1 commit
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
70 changes: 70 additions & 0 deletions .agents/scripts/tests/test-pr-3885-recovery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)"

QUALITY_FILE="${REPO_ROOT}/.agents/scripts/quality-cli-manager.sh"
STUCK_FILE="${REPO_ROOT}/.agents/scripts/stuck-detection-helper.sh"
WORKTREE_FILE="${REPO_ROOT}/.agents/scripts/worktree-helper.sh"
GITIGNORE_FILE="${REPO_ROOT}/.gitignore"

TESTS_RUN=0
TESTS_FAILED=0

pass() {
local message="$1"
TESTS_RUN=$((TESTS_RUN + 1))
echo "PASS ${message}"
return 0
}

fail() {
local message="$1"
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_FAILED=$((TESTS_FAILED + 1))
echo "FAIL ${message}"
return 0
}

assert_contains() {
local file_path="$1"
local pattern="$2"
local message="$3"

if rg -Fq -- "$pattern" "$file_path"; then
pass "$message"
return 0
fi

fail "$message"
return 1
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The current setup with set -e causes the script to exit on the first failed assertion, preventing a full test run. While the intent to run all checks is clear, suggesting return 0 for a failed assertion in assert_contains would mask the actual failure, which contradicts the rule: 'In shell scripts, functions that wrap a command should propagate its exit code to the caller. Avoid masking potential errors with a hardcoded return 0.' Instead, assert_contains should still return a non-zero exit code on failure. To allow the script to continue, consider wrapping calls to assert_contains with || true or temporarily disabling set -e around the test execution (set +e ... set -e). The script can then collect failures and exit with a non-zero status at the very end if any tests failed.

References
  1. In shell scripts, functions that wrap a command should propagate its exit code to the caller. Avoid masking potential errors with a hardcoded return 0. Instead, use return $? or capture the exit code and return it (e.g., local rc=$?; return $rc).

}

run_checks() {
assert_contains "$QUALITY_FILE" '"qlty")' "quality-cli-manager has qlty dispatcher case"
assert_contains "$QUALITY_FILE" 'script=".agents/scripts/qlty-cli.sh"' "quality-cli-manager routes qlty through wrapper"
assert_contains "$QUALITY_FILE" "execute_cli_command \"qlty\" \"check\" \"\$args\"" "quality-cli-manager runs qlty check without positional org arg"
assert_contains "$STUCK_FILE" 'unique_by([.issue, .repo])' "stuck-detection helper uses collision-safe jq dedup key"
assert_contains "$WORKTREE_FILE" "refs/remotes/*/\$branch" "worktree helper checks remote branch presence across all remotes"
assert_contains "$GITIGNORE_FILE" 'hostinger' "gitignore includes hostinger base pattern"
assert_contains "$GITIGNORE_FILE" 'hostinger.*' "gitignore includes hostinger wildcard extension pattern"
assert_contains "$GITIGNORE_FILE" 'hostinger_*' "gitignore retains hostinger underscore pattern"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
return 0
}

main() {
run_checks
echo ""
echo "Tests run: ${TESTS_RUN}"
echo "Tests failed: ${TESTS_FAILED}"

if [[ $TESTS_FAILED -gt 0 ]]; then
return 1
fi

return 0
}

main "$@"
Loading