b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
77 lines
2.5 KiB
Python
77 lines
2.5 KiB
Python
"""Tests for the CLI `/prompt` editor-compose command.
|
|
|
|
`/prompt` opens `$VISUAL`/`$EDITOR` on a temp markdown file so the user can
|
|
hand-edit a multi-line prompt, then queues the saved buffer as the next
|
|
agent turn via the one-shot `_pending_agent_seed` (same path `/blueprint`
|
|
uses). These drive a fake editor subprocess to verify read-back, header
|
|
stripping, seeding, and the empty-buffer cancel path.
|
|
"""
|
|
|
|
import os
|
|
import stat
|
|
import tempfile
|
|
|
|
import pytest
|
|
|
|
from hermes_cli.cli_commands_mixin import CLICommandsMixin
|
|
from hermes_cli.commands import resolve_command
|
|
|
|
|
|
class _Stub(CLICommandsMixin):
|
|
def __init__(self):
|
|
self._pending_agent_seed = None
|
|
|
|
|
|
def _fake_editor(body: str, mode: str = "append") -> str:
|
|
"""Write a tiny shell 'editor' that mutates the file it is handed."""
|
|
f = tempfile.NamedTemporaryFile("w", suffix=".sh", delete=False)
|
|
if mode == "append":
|
|
f.write("#!/usr/bin/env bash\n")
|
|
f.write(f"cat >> \"$1\" <<'EOF'\n{body}\nEOF\n")
|
|
else: # clear
|
|
f.write("#!/usr/bin/env bash\n: > \"$1\"\n")
|
|
f.close()
|
|
os.chmod(f.name, os.stat(f.name).st_mode | stat.S_IEXEC)
|
|
return f.name
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _no_visual(monkeypatch):
|
|
monkeypatch.delenv("VISUAL", raising=False)
|
|
|
|
|
|
def test_command_registered():
|
|
cd = resolve_command("prompt")
|
|
assert cd and cd.name == "prompt"
|
|
assert resolve_command("compose").name == "prompt"
|
|
|
|
|
|
def test_compose_reads_and_strips_header(monkeypatch):
|
|
monkeypatch.setenv("EDITOR", _fake_editor("Refactor the auth module.\nUse pytest."))
|
|
out = _Stub()._compose_in_editor("")
|
|
assert "Refactor the auth module." in out
|
|
assert "Use pytest." in out
|
|
assert "#!" not in out # the instructional header is stripped
|
|
|
|
|
|
def test_prompt_sets_pending_seed(monkeypatch):
|
|
monkeypatch.setenv("EDITOR", _fake_editor("Write a haiku about caching."))
|
|
s = _Stub()
|
|
s._handle_prompt_compose_command("/prompt")
|
|
assert s._pending_agent_seed
|
|
assert "haiku about caching" in s._pending_agent_seed
|
|
|
|
|
|
def test_initial_text_is_seeded(monkeypatch):
|
|
# The fake editor appends, so the initial text leads the buffer.
|
|
monkeypatch.setenv("EDITOR", _fake_editor("rest of prompt"))
|
|
out = _Stub()._compose_in_editor("DRAFT: ")
|
|
assert out.startswith("DRAFT:")
|
|
|
|
|
|
def test_empty_buffer_does_not_seed(monkeypatch):
|
|
monkeypatch.setenv("EDITOR", _fake_editor("", mode="clear"))
|
|
s = _Stub()
|
|
s._handle_prompt_compose_command("/prompt")
|
|
assert s._pending_agent_seed is None
|