fix(cli): recover flags consumed by -E option and prompt for recipient

This commit is contained in:
LIghtJUNction
2026-03-17 18:48:19 +08:00
parent 976398d1f2
commit 458e8e0db8
2 changed files with 103 additions and 1 deletions

View File

@@ -211,3 +211,23 @@ def test_export_gpg_missing(mock_exporter, mock_kb_manager):
assert result.exit_code != 0
assert "GPG tool not found" in result.output
def test_export_gpg_recipient_recovery(mock_exporter, mock_kb_manager, mock_gpg_tools):
"""Test recovery when -E consumes a flag"""
_, mock_exec = mock_gpg_tools
runner = CliRunner()
with patch("pathlib.Path.unlink"), patch("pathlib.Path.exists", return_value=True):
# input="user@example.com\n" provides the recipient when prompted
result = runner.invoke(bk, ["export", "-E", "-S"], input="user@example.com\n")
assert result.exit_code == 0
assert "Warning: Flag '-S' was interpreted as the recipient" in result.output
assert "Recovered flag -S (Sign)" in result.output
# Verify GPG command has both sign and encrypt with correct recipient
args = mock_exec.call_args[0]
assert "--sign" in args
assert "--encrypt" in args
assert "user@example.com" in args