Skip to content

test(shell-completion): stabilize flaky zpty zsh completion tests#436

Open
dqn wants to merge 2 commits into
mainfrom
test/zpty-zsh-stabilize
Open

test(shell-completion): stabilize flaky zpty zsh completion tests#436
dqn wants to merge 2 commits into
mainfrom
test/zpty-zsh-stabilize

Conversation

@dqn
Copy link
Copy Markdown
Collaborator

@dqn dqn commented May 21, 2026

Summary

The zpty-based zsh interactive completion tests were intermittently
failing (~10–20%) with NMATCHES:-1. Root cause: a TAB-vs-ZLE race in
the test harness — TAB was sent before zsh's line editor finished
consuming the command, so it was inserted as a literal character instead
of triggering completion. Waiting for the command to be echoed back
(i.e. ZLE ingested the input) and letting ZLE settle before sending TAB
removes the race; no timeout extensions or retry logic were needed.

Main changes

  • Wait for the command echo from zpty before sending TAB, plus a 0.1s
    ZLE settle delay
  • Use the correct lowercase compprefuncs array; the previously used
    camelCase comppreFuncs is not a real zsh hook, so the pre-hook was
    silently inactive
  • Add a _test_pre / _test_cap split using compprefuncs and
    comppostfuncs so diagnostics distinguish "TAB never triggered
    completion" (test infra race) from "completion ran but produced no
    matches" (potential politty bug)

Verification

  • 20/20 consecutive runs of the zpty suite pass after the fix
  • Full npm test (1290 tests) green

Notes

  • The import-order tweak at the top of zsh.test.ts is an automatic
    reorder by lefthook's organize-imports-cli pre-commit hook. The hook
    only touches staged files, so older files drift out of sync until they
    are next edited — unrelated to the stabilization itself.

Code Metrics Report

main (57b091d) #436 (16100f3) +/-
Coverage 87.8% 87.8% 0.0%
Test Execution Time 11s 11s 0s
Details
  |                     | main (57b091d) | #436 (16100f3) | +/-  |
  |---------------------|----------------|----------------|------|
  | Coverage            |          87.8% |          87.8% | 0.0% |
  |   Files             |             51 |             51 |    0 |
  |   Lines             |           4272 |           4272 |    0 |
  |   Covered           |           3753 |           3753 |    0 |
  | Test Execution Time |            11s |            11s |   0s |

Reported by octocov

The zpty-based zsh interactive completion tests were intermittently
failing (~10-20%) with `NMATCHES:-1`. Root cause was a TAB-vs-ZLE race
in the test harness: TAB was sent before zsh's line editor finished
consuming the command, so it was inserted as a literal character
instead of triggering completion.

Changes:
- Wait for the command echo from zpty before sending TAB, plus a 0.1s
  ZLE settle delay
- Use the correct lowercase `compprefuncs` array (the camelCase
  `comppreFuncs` is not a real zsh hook and was silently inactive)
- Add a `_test_pre` / `_test_cap` split using `compprefuncs` and
  `comppostfuncs` so diagnostics distinguish "TAB never triggered
  completion" (test infra race) from "completion ran but produced no
  matches" (potential politty bug)

Verified 20/20 consecutive zpty suite runs pass.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 21, 2026

Open in StackBlitz

npm i https://pkg.pr.new/politty@436

commit: a77c376

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant