fix(test): dump file and directory context on E2E assertion failures#77
fix(test): dump file and directory context on E2E assertion failures#77rm3l merged 1 commit intoredhat-developer:mainfrom
Conversation
Review Summary by QodoEnhance E2E test debugging with file and directory context dumps
WalkthroughsDescription• Add helper functions to dump file and directory context on E2E assertion failures • Improve debugging by displaying file contents and directory listings in CI logs • Handle edge cases like missing files, missing parents, and large files • Harden existing check functions to prevent errors on nonexistent paths Diagramflowchart LR
A["E2E Test Assertion Failure"] --> B["_dump_file_context or _dump_dir_context"]
B --> C["Check if path exists"]
C -->|Exists| D["Display content/listing in CI log"]
C -->|Missing| E["Show parent directory contents"]
D --> F["Truncate large files to first/last 50 lines"]
E --> F
F --> G["Enhanced CI log for troubleshooting"]
File Changes1. tests/e2e/lib/test-utils.sh
|
Code Review by Qodo
1. Dump helpers trigger errexit
|
| _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")/):" | ||
| 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")/):" | ||
| 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:" | ||
| ls -la "$dir" | while IFS= read -r line; do | ||
| log_error " $line" | ||
| done | ||
| } |
There was a problem hiding this comment.
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
When an E2E validation check fails (e.g. file missing, file empty, file not containing expected content, invalid JSON, directory missing or empty), the error message alone is not enough to diagnose CI failures — especially in nightly runs where the environment is ephemeral. Add _dump_file_context and _dump_dir_context helpers that are called on every assertion failure. They print the actual file content (or directory listing) inline in the CI log, and handle edge cases like missing files, missing parent directories, and large files (truncated to first/last 50 lines). This eliminates the need to download the must-gather artifact just to understand why a check failed. Also harden check_dir_not_empty and check_file_contains to guard against errors when the path doesn't exist (the prior code would error on ls/grep of a nonexistent path after check_dir_exists/ check_file_exists already reported the failure). Assisted-by: Cursor Made-with: Cursor
Description
This makes it easier to troubleshoot the failures seen for example in https://github.com/redhat-developer/rhdh-must-gather/actions/runs/22925718339/job/66535452232#step:5:267
Which issue(s) does this PR fix or relate to
—
PR acceptance criteria
How to test changes / Special notes to the reviewer