Repository navigation
feat(output-filter): collapse pytest progress lines and preserve failure root-cause headers - #104
Conversation
INK-Q
left a comment
There was a problem hiding this comment.
Thanks @lnb-git for the clean pytest output-filter enhancement — your ^\S+\.py::\S+\s+PASSED pattern is much safer than greedy .+ matching (avoids ReDoS and avoids folding FAILED ... PASSED lines)!
A few P0/P1 items need to be addressed before merging:
P0 (Must Fix)
- Retarget base branch from
maintodev(CONTRIBUTING.md):- Feature and fix PRs must target
dev(only release PRs fromdevor urgenthotfix/*targetmain). Please change the PR base todev, rebase onto latestorigin/dev, and runnpm run build.
- Feature and fix PRs must target
P1 (Must Fix)
- Dot-progress folding gaps (
src/utils/output-filter.ts:542):/^\S+\.py\s+\.{3,}(?:\s+\[\s*\d+%\])?$/requires>= 3dots, so passing test files with 1–2 tests (tests/test_a.py . [10%],.. [20%]) won't fold and will break contiguous foldable runs. Lowering to\.+is equally safe since only.is matched (neverF/E/x/s).- Because dot-progress lines are only in
GREEN_BUILD_OR_PASS_PATTERNS(notUNAMBIGUOUS_TEST_PASS_PATTERNS), passing files whose names contain domain words likeerror,timeout, orfailure(e.g.tests/test_error_handling.py .... [ 50%]) get blocked byhasFoldDangerTokenand won't fold. Adding the dot-progress regex toUNAMBIGUOUS_TEST_PASS_PATTERNSfixes this safely.
- Parametrized verbose pytest node IDs with spaces (
src/utils/output-filter.ts:541,562):^\S+\.py::\S+\s+PASSEDmisses realpytest -vparametrized lines containing spaces inside[...], e.g.tests/test_api.py::test_parse[hello world] PASSED [ 10%]. Allowing bracketed parameter text (while still ensuring no failure verdict tokens precedePASSED) will cover parametrized suites cleanly.
- Generalize pytest
E ...root-cause headers (src/utils/output-filter.ts:468):- Hardcoding 10 built-in Python exception names misses very common pytest root-cause lines such as
E assert 1 == 2,E FileNotFoundError,E ZeroDivisionError,E pydantic.ValidationError, and custom*Error/*Exceptionclasses. Consider generalizing to^E\s{2,}(?:assert\b|[A-Za-z_][\w.]*(?:Error|Exception)\b).
- Hardcoding 10 built-in Python exception names misses very common pytest root-cause lines such as
Checklist
- Rebase onto
origin/devand change base branch todev - Update dot-progress regex to
\.+and include it inUNAMBIGUOUS_TEST_PASS_PATTERNS - Support spaced parametrized
[...]node IDs for verbosePASSEDlines and generalize^E\s{2,}root-cause headers - Add unit test cases for 1–2 dot files,
test_error_*.py ..., spaced[param]PASSED lines, andE assert .../ custom*Error, then runnpm run typecheck && npm run build && npm test
6c1afa9 to
bd20e3a
Compare
|
Thanks @INK-Q for the thorough review! All P0/P1 items have been addressed:
|
INK-Q
left a comment
There was a problem hiding this comment.
Thanks @lnb-git for retargeting dev and addressing the dot-progress and spaced parametrized pytest IDs! Re-review caught two 1-line P1 regex bugs to fix before running CI and merging:
P1 (Must fix)
-
Quadratic
$O(N^2)$ ReDoS backtracking inPYTEST_VERBOSE_PASS_PATTERN(src/utils/output-filter.ts:522-523)-
/^\S+\.py::[^\s\[]+(?:\[(?:[^\[\]\r\n]|\[[^\[\]\r\n]*\])+\])?\s+PASSED(?:\s+\[\s*\d+%\])?$/allows both\S+and[^\s\[]+to consume.py::, causing quadratic backtracking on non-matching lines with repeated.py::tokens (verified in Node:"a.py::".repeat(8000) + " FAIL"— 48 KB — takes 233.6 ms, scaling to ~9 s at 300 KB). -
Fix: Disallow
:in the file-path prefix except an optional Windows drive letter:/^(?:[A-Za-z]:)?[^\s:]+\.py::[^\s\[]+.../(drops the same 48 KB input to 0.18 ms while still matchingC:\repo\tests\test_a.py::TestCls::test_ok[a b] PASSED [100%]), and add a repeated-.py::adversarial test.
-
-
PYTEST_ROOT_CAUSE_LINE_PATTERNmisses bareE Exception:/E Error:and Python 3.11+ExceptionGroup(src/utils/output-filter.ts:473)-
/^E\s{2,}(?:assert\b|[A-Za-z_][\w.]*(?:Error|Exception)\b)/requires at least 1 character beforeError/Exception, soE Exception: boom,E Error: ..., andE ExceptionGroup: ...all returnfalseand miss root-cause header promotion. -
Fix: Change to
/^E\s{2,}(?:assert\b|(?:[A-Za-z_][\w.]*)?(?:Error|Exception)(?:Group)?\b)/(still rejectsE error = 1,E my_error_var = 1,E + where, and lowercasee assert) and add unit test coverage.
-
P2 (Nice to have)
- Please update the PR description to match the actual diff (it still mentions collapsing
=== test session starts ===/platform .../rootdir:/collected N itemsand matchingTraceback/FAILED ...::..., which aren't in the patch).
Checklist
…ralized root-cause headers
…rror/Exception/ExceptionGroup headers
bd20e3a to
ebdd4a6
Compare
|
Thanks @INK-Q for the re-review and exact ReDoS repro! Rebased cleanly onto latest
|
INK-Q
left a comment
There was a problem hiding this comment.
Thanks @lnb-git for the quick fixes in ebdd4a6! Re-verified locally and via CI:
PYTEST_VERBOSE_PASS_PATTERNstays strictly linear-time across repeated.py::, repeated.py, dot-flood, and nested-bracket adversarial inputs (<4 ms).PYTEST_ROOT_CAUSE_LINE_PATTERNaccurately promotes bareError/Exception/ExceptionGroupheaders without false positives on lowercase/non-exceptionElines.- All 8 CI checks (Linux/macOS/Windows + stress) are green and merging onto latest
devkeepsdist/clean with 0 B schema overhead.
LGTM — merging now!
Summary
path/to/test.py::test_name[params] PASSED [ 10%], including Windows drive letters, spaced/single-nested[...]params, and domain-word filenames) and per-file passing dot-progress lines (tests/test_a.py . [10%],tests/test_error_handling.py .... [50%]) underGREEN_BUILD_OR_PASS_PATTERNSandUNAMBIGUOUS_TEST_PASS_PATTERNSwhile never folding failure verdicts (FAILED,..F.,.E).^=== FAILURES ===$,^=== ERRORS ===$, and case-sensitive^E\s{2,}(?:assert\b|(?:[A-Za-z_][\w.]*)?(?:Error|Exception)(?:Group)?\b)) under tight output budgets viaisRootCauseHeaderLine.test/output-filter.test.tscovering verbose/dot pass folding, Windows paths, generalized root-cause headers, negative non-root cases, and linear-time adversarial inputs (unbalanced brackets and repeated.py::).Verification
npm run typechecknpm run build && git diff --exit-code -- dist/sh -n install.shnpm test(212/212 passed)npm run validate