Skip to content
Merged
Changes from all commits
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
79 changes: 77 additions & 2 deletions tests/e2e/lib/test-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,75 @@ log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}

# Dump file content to stderr for debugging failed assertions.
# Truncates to first and last 50 lines if the file is large.
_dump_file_context() {
local file="$1"
if [ ! -e "$file" ]; then
log_error " ↳ File does not exist: $file"
local parent
parent="$(dirname "$file")"
if [ -d "$parent" ]; then
log_error " ↳ Parent directory contents ($(basename "$parent")/):"
# shellcheck disable=SC2012
ls -la "$parent" | while IFS= read -r line; do
log_error " $line"
done
else
log_error " ↳ Parent directory also missing: $parent"
fi
return
fi
if [ ! -s "$file" ]; then
log_error " ↳ File exists but is empty (0 bytes): $file"
return
fi
local total_lines
total_lines=$(wc -l < "$file")
local max_lines=100
log_error " ↳ File content ($total_lines lines):"
if [ "$total_lines" -le "$max_lines" ]; then
while IFS= read -r line; do
log_error " $line"
done < "$file"
else
log_error " --- first 50 lines ---"
head -n 50 "$file" | while IFS= read -r line; do
log_error " $line"
done
log_error " --- ... truncated $(( total_lines - 100 )) lines ... ---"
log_error " --- last 50 lines ---"
tail -n 50 "$file" | while IFS= read -r line; do
log_error " $line"
done
fi
}

# Dump directory listing for debugging failed assertions.
_dump_dir_context() {
local dir="$1"
if [ ! -e "$dir" ]; then
log_error " ↳ Directory does not exist: $dir"
local parent
parent="$(dirname "$dir")"
if [ -d "$parent" ]; then
log_error " ↳ Parent directory contents ($(basename "$parent")/):"
# shellcheck disable=SC2012
ls -la "$parent" | while IFS= read -r line; do
log_error " $line"
done
else
log_error " ↳ Parent directory also missing: $parent"
fi
return
fi
log_error " ↳ Directory listing:"
# shellcheck disable=SC2012
ls -la "$dir" | while IFS= read -r line; do
log_error " $line"
done
}
Comment on lines +28 to +93

Choose a reason for hiding this comment

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

Action required

1. Dump helpers trigger errexit 🐞 Bug ⛯ Reliability

The new _dump_file_context/_dump_dir_context run wc/head/tail/ls without guarding failures; under
set -euo pipefail this can abort the validator early (especially when the path exists but isn’t a
readable regular file/dir), skipping remaining checks and masking the original failure.
Agent Prompt
### Issue description
The new debug dump helpers can cause the E2E validation scripts to exit prematurely under `set -euo pipefail` when `wc/head/tail/ls` fail (e.g., unreadable path, path is a directory, permission denied).

### Issue Context
These helpers run during assertion failures; they must be *best-effort* and must not change control flow of the validation scripts.

### Fix Focus Areas
- tests/e2e/lib/test-utils.sh[26-90]

### Notes for implementation
- In `_dump_file_context`, add guards like `if [ ! -f "$file" ] || [ ! -r "$file" ]; then ...; return; fi`.
- Wrap/guard commands so they cannot trip errexit/pipefail, e.g.:
  - `total_lines=$(wc -l <"$file" 2>/dev/null || echo "?")`
  - `ls -la "$dir" 2>&1 | while ...; done || true`
  - `head ... 2>/dev/null | while ...; done || true`
  - `tail ... 2>/dev/null | while ...; done || true`

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


# Detect if we're running on an OpenShift cluster
is_openshift() {
# Check if the cluster has OpenShift-specific API resources
Expand All @@ -37,6 +106,7 @@ check_file_exists() {
log_info "✓ Found $description: $file"
else
log_error "✗ Missing $description: $file"
_dump_file_context "$file"
((ERRORS++))
fi
}
Expand All @@ -48,6 +118,7 @@ check_dir_exists() {
log_info "✓ Found $description: $dir"
else
log_error "✗ Missing $description: $dir"
_dump_dir_context "$dir"
((ERRORS++))
fi
}
Expand All @@ -60,6 +131,7 @@ check_file_not_empty() {
log_info "✓ Found non-empty $description: $file"
else
log_error "✗ $description is empty: $file"
_dump_file_context "$file"
((ERRORS++))
fi
}
Expand All @@ -70,6 +142,7 @@ check_file_valid_json() {
check_file_exists "$file" "$description"
if ! jq . "$file" >/dev/null 2>&1; then
log_error "✗ $description is not valid JSON: $file"
_dump_file_context "$file"
((ERRORS++))
fi
}
Expand All @@ -78,10 +151,11 @@ check_dir_not_empty() {
local dir="$1"
local description="$2"
check_dir_exists "$dir" "$description"
if [ -n "$(ls -A "$dir")" ]; then
if [ -d "$dir" ] && [ -n "$(ls -A "$dir" 2>/dev/null)" ]; then
log_info "✓ Found non-empty $description: $dir"
else
log_error "✗ $description is empty"
_dump_dir_context "$dir"
((ERRORS++))
fi
}
Expand All @@ -91,10 +165,11 @@ check_file_contains() {
local content="$2"
local description="$3"
check_file_exists "$file" "$description"
if grep -q "$content" "$file"; then
if [ -f "$file" ] && grep -q "$content" "$file"; then
log_info "✓ Found $content in $file"
else
log_error "✗ $description does not contain '$content': $file"
_dump_file_context "$file"
((ERRORS++))
fi
}
Expand Down