Skip to content

Conversation

@Celina1801
Copy link

@Celina1801 Celina1801 commented Jan 27, 2025

What is the problem that this PR addresses?

Closes #312
The confirm prompt currently allows users to bypass input by pressing "Enter," which automatically selects the default value. This behavior is problematic for critical confirmations (e.g., deleting files), where explicit user input (e.g., "y" or "n") should be required to ensure intentionality.

How did you solve it?

I introduced a mandatory parameter to the confirm prompt. When mandatory=True, the prompt enforces explicit user input ("y" or "n") and rejects empty or invalid inputs. The implementation modifies the key bindings to re-prompt the user until a valid response is provided.

Unit tests were added to ensure that:

Empty inputs are rejected when mandatory=True.
Valid responses ("y," "n," "Y," "N") are accepted.
Invalid inputs re-prompt the user for confirmation.

Checklist

  • I have read the Contributor's Guide.
  • I will check that all automated PR checks pass before the PR gets reviewed.

from tests.utils import feed_cli_with_input


def test_confirm_enter_default_yes():
Copy link
Owner

Choose a reason for hiding this comment

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

Any reason you removed these tests? The default behaviour should stay the same

@tmbo
Copy link
Owner

tmbo commented Aug 28, 2025

I think this is a good addition, do you want to follow up on the comment I made on the removed tests? If you re-add them I think we are good to merge @Celina1801

style: Optional[Style] = None,
auto_enter: bool = True,
instruction: Optional[str] = None,
mandatory: bool = True,
Copy link

Choose a reason for hiding this comment

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

I would strongly suggest defaulting mandatory to False to preserve the default behaviour and avoid breaking people's code.

That will also resolve the issue with deletion of test cases. When mandatory defaults to false all existing test cases can remain the same and you only have to add new ones for mandatory=True case

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.

Require typed answer for confirm question

3 participants