fix(cli): sanitize bracketed paste markers during setup

Strip bracketed-paste control sequences from setup prompt input so pasted API keys work on Linux and WSL terminals, and add regression tests for normal/password prompts.

Closes #16491
This commit is contained in:
MaHaoHao-ch 2026-04-28 10:43:53 +08:00 committed by Teknium
parent 8ebb81fd76
commit 02147cc850
2 changed files with 35 additions and 1 deletions

View file

@ -1,6 +1,28 @@
from hermes_cli import setup as setup_mod
def test_prompt_strips_bracketed_paste_markers(monkeypatch):
monkeypatch.setattr(
"builtins.input",
lambda _prompt="": "\x1b[200~sk-ant-api-key\x1b[201~",
)
value = setup_mod.prompt("API key")
assert value == "sk-ant-api-key"
def test_password_prompt_strips_bracketed_paste_markers(monkeypatch):
monkeypatch.setattr(
"getpass.getpass",
lambda _prompt="": "\x1b[200~secret-token\x1b[201~",
)
value = setup_mod.prompt("API key", password=True)
assert value == "secret-token"
def test_prompt_choice_uses_curses_helper(monkeypatch):
monkeypatch.setattr(setup_mod, "_curses_prompt_choice", lambda question, choices, default=0, description=None: 1)