Skip to content

tests: add Escape-cancel coverage for confirm, text, and path prompts#1170

Merged
muddlebee merged 1 commit intoTracer-Cloud:mainfrom
DsThakurRawat:fix/1117-escape-cancel-tests
May 1, 2026
Merged

tests: add Escape-cancel coverage for confirm, text, and path prompts#1170
muddlebee merged 1 commit intoTracer-Cloud:mainfrom
DsThakurRawat:fix/1117-escape-cancel-tests

Conversation

@DsThakurRawat
Copy link
Copy Markdown
Contributor

@DsThakurRawat DsThakurRawat commented May 1, 2026

PrImage Fixes #1117

Describe the changes you have made in this PR -

Added unit test coverage for the "Escape To cancel" functionality in the CLI. Specifically ,added tests for confirm,text,and path prompts to ensure they return None when the Escape key is pressed,Preventing the CLI from hanging
PR_CODE

Demo/Screenshot for feature changes and bug fixes -


Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • No, I wrote all the code myself
  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:

The problem was missing test coverage for the Escape-cancel feature across all CLI prompt types — only select was covered.

I followed the existing test_stock_questionary_select_escape_cancels pattern already present in the file:

  1. Call install_questionary_escape_cancel() to activate the Escape-cancel patch before each test.
  2. Use create_pipe_input() from prompt_toolkit as a context manager to simulate a real terminal input.
  3. Create the prompt (confirm, text, or path) with the pipe as its input.
  4. Send the Escape byte (b"\x1b") to simulate the user pressing Escape.
  5. Assert that app.run() returns None — confirming the prompt was cancelled cleanly.

No alternative approaches were considered since the existing pattern in the file was clear and correct. AI assistance was used only to add the docstrings/comments to the test functions.


Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

Note: Please check Allow edits from maintainers if you would like us to assist in the PR.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 1, 2026

Greptile Summary

This PR adds three new unit tests covering the Escape-to-cancel behavior for questionary.confirm, questionary.text, and questionary.path prompts, complementing the existing select test introduced for Issue #1117. The tests correctly follow the established pattern: install the escape patch, pipe \x1b into the application before running it, and assert that app.run() returns None.

Confidence Score: 5/5

Safe to merge — test-only change with no production code impact.

All three new tests faithfully mirror the existing select-escape test, are logically correct, and the only remaining feedback is a P2 style suggestion about parameterization and missing coverage for checkbox/password.

No files require special attention.

Important Files Changed

Filename Overview
tests/cli/test_prompt_support.py Adds three new Escape-cancel tests for confirm, text, and path prompts, mirroring the existing select test pattern exactly; tests are correct and well-structured.

Sequence Diagram

sequenceDiagram
    participant T as Test
    participant PS as prompt_support
    participant Q as questionary.<prompt>
    participant App as Application

    T->>PS: install_questionary_escape_cancel()
    PS-->>T: (idempotent if already installed)
    T->>Q: create prompt(input=pipe_input)
    Q->>App: build Application with merged key bindings
    T->>App: pipe_input.send_bytes(b"\x1b")
    T->>App: app.run()
    App->>App: Escape binding fires → exit(result=None)
    App-->>T: returns None
    T->>T: assert result is None ✓
Loading

Reviews (1): Last reviewed commit: "tests: add Escape-cancel coverage for co..." | Re-trigger Greptile

Comment on lines +41 to +98
def test_stock_questionary_confirm_escape_cancels() -> None:
"""Verify that pressing Escape cancels a confirm prompt (Issue #1117).

Sends the Escape byte (\\x1b) to a questionary.confirm application
and asserts that it returns None instead of hanging.
"""
install_questionary_escape_cancel()
with create_pipe_input() as pipe_input:
q = questionary.confirm(
"Are you sure?",
input=pipe_input,
output=DummyOutput(),
)
pipe_input.send_bytes(b"\x1b")
app = q.application
app.input = pipe_input
app.output = DummyOutput()
assert app.run() is None


def test_stock_questionary_text_escape_cancels() -> None:
"""Verify that pressing Escape cancels a text input prompt (Issue #1117).

Sends the Escape byte (\\x1b) to a questionary.text application
and asserts that it returns None.
"""
install_questionary_escape_cancel()
with create_pipe_input() as pipe_input:
q = questionary.text(
"Name",
input=pipe_input,
output=DummyOutput(),
)
pipe_input.send_bytes(b"\x1b")
app = q.application
app.input = pipe_input
app.output = DummyOutput()
assert app.run() is None


def test_stock_questionary_path_escape_cancels() -> None:
"""Verify that pressing Escape cancels a path selection prompt (Issue #1117).

Sends the Escape byte (\\x1b) to a questionary.path application
and asserts that it returns None.
"""
install_questionary_escape_cancel()
with create_pipe_input() as pipe_input:
q = questionary.path(
"Path",
input=pipe_input,
output=DummyOutput(),
)
pipe_input.send_bytes(b"\x1b")
app = q.application
app.input = pipe_input
app.output = DummyOutput()
assert app.run() is None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Consider parameterizing or adding checkbox/password coverage

The three new tests are structurally identical to each other and to test_stock_questionary_select_escape_cancels. Both checkbox and password are also patched by install_questionary_escape_cancel() but have no escape-cancel test yet. Parameterizing all five prompt types with @pytest.mark.parametrize would reduce duplication and make it easier to add new prompt types in the future without repeating the boilerplate setup.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@muddlebee
Copy link
Copy Markdown
Collaborator

@DsThakurRawat pls check review comments

@muddlebee
Copy link
Copy Markdown
Collaborator

@DsThakurRawat merging this for now, but going forward pls take care of review comments

@muddlebee muddlebee merged commit 3c107e2 into Tracer-Cloud:main May 1, 2026
10 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

🚀 Houston, we have a merge. @DsThakurRawat your PR is in orbit. Thanks for launching this one!


👋 Join us on Discord - OpenSRE : hang out, contribute, or hunt for features and issues. Everyone's welcome.

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.

Add Escape-cancel coverage for confirm, text, and path prompts

2 participants