Files
hermes-agent/tests/hermes_cli/test_prompt_compose_command.py
ethernet 9b8ad35ee6 refactor(tests): platforms() fully replaces the linux_only/macos_only/windows_only trio
No shims, one marker system. The full mechanical sweep:

- 165 test files converted: every @pytest.mark.<os>_only decorator and
  pytestmark assignment is now platforms("<os>"). Docstring/comment
  prose mentioning the trio rewritten to the platforms() vocabulary.
- conftest: _OS_MARKS, the legacy skip loop, the double-mark reject for
  the trio, and the selector-tagging shim are deleted. The single
  platforms() gate does all host gating; _reject_contradictory_platform_
  marks replaces the old reject (one platforms() marker per test — a
  module-level pytestmark stacked on a per-test marker is the historic
  skipped-everywhere-green-everywhere failure and stays a hard error).
- pyproject: only the platforms marker is registered.
- list_os_marked_tests.py: rewritten for the single vocabulary — takes
  a platform name (linux/macos/windows), matches quoted platforms(...)
  specs including negated and any-of forms, exits nonzero on empty
  selection. Its test file rewritten to match (bare identifiers must
  not match; the spec must appear inside the string literal).
- tests.yml macOS lane: marker: macos feeds the lister; the pytest
  selection is -m "platforms and not integration" — the marker name is
  the selector, the conftest's per-test host skips are the gate.
- test_os_marker_gating.py rewritten for the new reject (the old file
  tested deleted machinery).
- AGENTS.md / CONTRIBUTING.md updated to the single vocabulary.

Verified: full-tree compile; marker unit tests (36); lister tests;
macOS-lane simulation (21 files, 180 collected / 429 deselected on a
windows host); broad xdist slices through scripts/run_tests.sh
(367 + 1674 passed, zero refactor-attributable failures — the 6 red
tests in the second slice fail identically with the changes stashed).
2026-08-31 17:53:44 -04:00

64 lines
2.0 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"
@pytest.mark.platforms("linux")
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
@pytest.mark.platforms("linux")
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