fix(test): surface error lines for generic runners#2427
Conversation
Signed-off-by: axelray-dev <110029405+axelray-dev@users.noreply.github.com>
hgunduzoglu
left a comment
There was a problem hiding this comment.
Checked this out and tested locally (macOS arm64). The core behavior is right and the truncation hint (... +N more) is a nice touch:
| generic runner output | before | this PR |
|---|---|---|
| error at top, then 6 passing lines | last 5 lines (error hidden) | [FAIL] ERRORS: surfaces the error ✓ |
| no error lines | last 5 lines | last 5 lines ✓ (fallback preserved) |
cargo fmt/clippy/test clean, 16 runner tests pass. Scoping it to is_generic (leaving cargo/pytest/jest/go untouched) is the right call.
One real edge case worth handling: false positives on passing runs. ERROR_PATTERNS is substring-based and broad — r"(?i)^.*failed.*$", .*failure.*, .*warning.*, .*exception.* match those words anywhere on a line, including benign summary lines. So a runner that passes (exit 0) but prints a summary surfaces a misleading FAIL header:
$ rtk test ./runner.sh # script prints "Summary: 0 failed, 10 passed", exit 0
[FAIL] ERRORS:
Summary: 0 failed, 10 passedAn agent reading [FAIL] ERRORS: … 0 failed, 10 passed would conclude the suite failed when it passed — the opposite of the accurate-signal goal. Before this PR that same run showed a neutral OUTPUT (last 5 lines):, so it's a behavior change specifically in the passing case.
Since #2420 is really about surfacing failures when the runner fails, gating the error-surfacing on a non-zero exit code would fix both the original issue and this false positive. extract_test_summary doesn't currently receive the exit code, but runner.rs already has a RunMode::FilteredWithExit variant, so it can be threaded through without much churn — then: non-zero exit → [FAIL] ERRORS: (with the pattern scan), exit 0 → the existing tail fallback.
Core fix is solid; this is the one thing I'd tighten before merge. Could also add a test for the exit-0-with-"failed"-in-summary case to lock it down.
ERROR_PATTERNS are substring-based and can match benign summary lines (e.g. 'Summary: 0 failed, 10 passed') in passing runners. Only scan for error patterns when the exit code is non-zero to avoid false-positive [FAIL] ERRORS: headers on successful runs.
|
Good catch, thanks. Pushed a fix that gates the error-pattern scan on non-zero exit code. Now uses Added a test for the exact false-positive case you described (exit 0 with "0 failed, 10 passed" in output). All 2153 tests pass. |
|
Thanks @axelray-dev for picking this one up, and good call gating the scan on the exit code. I pulled the branch and ran the exact repro from the issue (script prints So the Adding one pattern covers it: Regex::new(r"(?i)^.*\bfail\b.*$").unwrap(),With that, the repro surfaces |
| Regex::new(r"(?i)^.*\berr\b.*$").unwrap(), | ||
| Regex::new(r"(?i)^.*warning[\s:\[].*$").unwrap(), | ||
| Regex::new(r"(?i)^.*\bwarn\b.*$").unwrap(), | ||
| Regex::new(r"(?i)^.*failed.*$").unwrap(), |
There was a problem hiding this comment.
Concretely, this is the one-line addition that covers it. Putting it just above
the failed pattern keeps that one intact:
| Regex::new(r"(?i)^.*\bfail\b.*$").unwrap(), | |
| Regex::new(r"(?i)^.*failed.*$").unwrap(), |
Add Regex pattern for 'fail' as a whole word before the existing 'failed' pattern to catch more error cases while keeping the existing pattern intact.
|
Pushed the word-boundary pattern as suggested. Added a regression test using the exact repro line ("FAIL: something went wrong" with exit 1) to lock it down. All runner tests pass. |
What
Fixes #2420
For unrecognized test runners (anything besides cargo/pytest/jest/go),
extract_test_summary()previously showed only the last 5 lines of output. If failures appeared earlier in the output, they were hidden.Now it scans all lines against the existing
ERROR_PATTERNSregexes (errors, failures, panics, tracebacks, etc.) and surfaces matching lines under a[FAIL] ERRORS:header. When no error lines are found, the original "last 5 lines" fallback is preserved.Follow-up: error-pattern scanning is now gated on non-zero exit code.
ERROR_PATTERNSare substring-based and can match benign summary lines (e.g. "Summary: 0 failed, 10 passed") in passing runners. Passing runners (exit 0) always get the tail fallback regardless of keyword matches.Changes
src/cmds/rust/runner.rs: Inextract_test_summary(), the generic runner fallback now appliesERROR_PATTERNSmatching before falling back to tail output, but only when the exit code is non-zero. Switchedrun_testfromrun_filteredtorun_filtered_with_exitto receive the exit code. Added 3 tests covering error surfacing, no-error fallback, and the false-positive case.Tests
All 2153 tests pass. The three new tests verify:
[FAIL] ERRORS:Notes
ERROR_PATTERNSlazy_static, no new patterns added.