Initial import of NousResearch/hermes-agent
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Docker / shell lint / Lint Dockerfile (hadolint) (push) Has been cancelled
Docker / shell lint / Lint docker/ shell scripts (shellcheck) (push) Has been cancelled
Docker Build and Publish / build-amd64 (push) Has been cancelled
Docker Build and Publish / build-arm64 (push) Has been cancelled
Lint (ruff + ty) / ruff + ty diff (push) Has been cancelled
Lint (ruff + ty) / ruff enforcement (blocking) (push) Has been cancelled
Lint (ruff + ty) / Windows footguns (blocking) (push) Has been cancelled
Nix Lockfile Fix / auto-fix-main (push) Has been cancelled
Nix Lockfile Fix / fix (push) Has been cancelled
Nix / nix (macos-latest) (push) Has been cancelled
Nix / nix (ubuntu-latest) (push) Has been cancelled
OSV-Scanner / Scan lockfiles (push) Has been cancelled
Build Skills Index / build-index (push) Has been cancelled
Tests / test (1) (push) Has been cancelled
Tests / test (2) (push) Has been cancelled
Tests / test (3) (push) Has been cancelled
Tests / test (4) (push) Has been cancelled
Tests / test (5) (push) Has been cancelled
Tests / test (6) (push) Has been cancelled
Tests / e2e (push) Has been cancelled
uv.lock check / uv lock --check (push) Has been cancelled
Docker Build and Publish / merge (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
Tests / save-durations (push) Has been cancelled
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Docker / shell lint / Lint Dockerfile (hadolint) (push) Has been cancelled
Docker / shell lint / Lint docker/ shell scripts (shellcheck) (push) Has been cancelled
Docker Build and Publish / build-amd64 (push) Has been cancelled
Docker Build and Publish / build-arm64 (push) Has been cancelled
Lint (ruff + ty) / ruff + ty diff (push) Has been cancelled
Lint (ruff + ty) / ruff enforcement (blocking) (push) Has been cancelled
Lint (ruff + ty) / Windows footguns (blocking) (push) Has been cancelled
Nix Lockfile Fix / auto-fix-main (push) Has been cancelled
Nix Lockfile Fix / fix (push) Has been cancelled
Nix / nix (macos-latest) (push) Has been cancelled
Nix / nix (ubuntu-latest) (push) Has been cancelled
OSV-Scanner / Scan lockfiles (push) Has been cancelled
Build Skills Index / build-index (push) Has been cancelled
Tests / test (1) (push) Has been cancelled
Tests / test (2) (push) Has been cancelled
Tests / test (3) (push) Has been cancelled
Tests / test (4) (push) Has been cancelled
Tests / test (5) (push) Has been cancelled
Tests / test (6) (push) Has been cancelled
Tests / e2e (push) Has been cancelled
uv.lock check / uv lock --check (push) Has been cancelled
Docker Build and Publish / merge (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
Tests / save-durations (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import pytest
|
||||
|
||||
from hermes_cli.secret_prompt import _collect_masked_input, masked_secret_prompt
|
||||
|
||||
|
||||
def _run_collect(chars: str):
|
||||
output: list[str] = []
|
||||
iterator = iter(chars)
|
||||
|
||||
def read_char() -> str:
|
||||
return next(iterator, "")
|
||||
|
||||
def write(text: str) -> None:
|
||||
output.append(text)
|
||||
|
||||
value = _collect_masked_input(
|
||||
read_char,
|
||||
write,
|
||||
"API key: ",
|
||||
)
|
||||
return value, "".join(output)
|
||||
|
||||
|
||||
def test_collect_masked_input_shows_feedback_without_echoing_secret():
|
||||
value, output = _run_collect("secret\n")
|
||||
|
||||
assert value == "secret"
|
||||
assert output == "API key: ******\n"
|
||||
assert "secret" not in output
|
||||
|
||||
|
||||
def test_collect_masked_input_handles_backspace():
|
||||
value, output = _run_collect("sec\x7fret\r")
|
||||
|
||||
assert value == "seret"
|
||||
assert output == "API key: ***\b \b***\n"
|
||||
assert "secret" not in output
|
||||
|
||||
|
||||
def test_collect_masked_input_raises_keyboard_interrupt():
|
||||
output: list[str] = []
|
||||
|
||||
with pytest.raises(KeyboardInterrupt):
|
||||
_collect_masked_input(
|
||||
lambda: "\x03",
|
||||
output.append,
|
||||
"API key: ",
|
||||
)
|
||||
|
||||
assert "".join(output) == "API key: \n"
|
||||
|
||||
|
||||
def test_masked_secret_prompt_falls_back_to_getpass_for_non_tty(monkeypatch):
|
||||
class NonTty:
|
||||
def isatty(self):
|
||||
return False
|
||||
|
||||
monkeypatch.setattr("sys.stdin", NonTty())
|
||||
monkeypatch.setattr("sys.stdout", NonTty())
|
||||
monkeypatch.setattr("getpass.getpass", lambda prompt: f"value from {prompt}")
|
||||
|
||||
assert masked_secret_prompt("API key: ") == "value from API key: "
|
||||
Reference in New Issue
Block a user