-
Notifications
You must be signed in to change notification settings - Fork 3
fix(test): dump file and directory context on E2E assertion failures #77
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Dump helpers trigger errexit 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
|
||
|
|
||
| # Detect if we're running on an OpenShift cluster | ||
| is_openshift() { | ||
| # Check if the cluster has OpenShift-specific API resources | ||
|
|
@@ -37,6 +106,7 @@ check_file_exists() { | |
| log_info "✓ Found $description: $file" | ||
| else | ||
| log_error "✗ Missing $description: $file" | ||
| _dump_file_context "$file" | ||
| ((ERRORS++)) | ||
| fi | ||
| } | ||
|
|
@@ -48,6 +118,7 @@ check_dir_exists() { | |
| log_info "✓ Found $description: $dir" | ||
| else | ||
| log_error "✗ Missing $description: $dir" | ||
| _dump_dir_context "$dir" | ||
| ((ERRORS++)) | ||
| fi | ||
| } | ||
|
|
@@ -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 | ||
| } | ||
|
|
@@ -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 | ||
| } | ||
|
|
@@ -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 | ||
| } | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.