hermes-agent/tests/hermes_cli/test_bundles.py
kshitijk4poor 66827f8947 chore: prune unused imports and duplicate import redefinitions
Remove unused imports (F401) and duplicate/shadowed import
redefinitions (F811) across the codebase using ruff's safe
autofixes. No behavioral changes -- imports only.

- ~1400 safe autofixes applied across 644 files (net -1072 lines)
- __init__.py re-exports preserved (excluded from F401 removal so
  public re-export surfaces stay intact)
- Re-exports that are imported or monkeypatched by tests but look
  unused in their defining module are kept with explicit # noqa:
  F401 (gateway/run.py load_dotenv; run_agent re-exports from
  agent.message_sanitization, agent.context_compressor,
  agent.retry_utils, agent.prompt_builder, agent.process_bootstrap,
  agent.codex_responses_adapter)
- Unsafe F841 (unused-variable) fixes deliberately skipped -- those
  can change behavior when the RHS has side effects
- ruff lints remain disabled in pyproject.toml (only PLW1514 is
  selected); this is a one-time cleanup, not a config change

Verification:
- python -m compileall: clean
- pytest --collect-only: all 27161 tests collect (zero import errors)
- core entry points import clean (run_agent, model_tools, cli,
  toolsets, hermes_state, batch_runner, gateway)
- static scan: every name any test imports directly from an edited
  module still resolves
2026-05-28 22:26:25 -07:00

92 lines
3.3 KiB
Python

"""Tests for hermes_cli/bundles.py — the `hermes bundles` CLI subcommand."""
import argparse
import pytest
from hermes_cli.bundles import (
bundles_command,
register_cli,
)
@pytest.fixture
def bundles_env(tmp_path, monkeypatch):
bundles_dir = tmp_path / "skill-bundles"
monkeypatch.setenv("HERMES_BUNDLES_DIR", str(bundles_dir))
# Reset module-level cache between tests.
import agent.skill_bundles as mod
mod._bundles_cache = {}
mod._bundles_cache_mtime = None
return bundles_dir
def _parse(argv):
parser = argparse.ArgumentParser()
register_cli(parser)
return parser.parse_args(argv)
class TestBundlesCli:
def test_create_and_list(self, bundles_env, capsys):
args = _parse(["create", "my-bundle", "--skill", "a", "--skill", "b", "-d", "desc"])
bundles_command(args)
out = capsys.readouterr().out
assert "Created bundle" in out
# File should exist
assert (bundles_env / "my-bundle.yaml").exists()
args = _parse(["list"])
bundles_command(args)
out = capsys.readouterr().out
assert "my-bundle" in out
def test_show(self, bundles_env, capsys):
bundles_command(_parse(["create", "x", "--skill", "s1", "--skill", "s2"]))
capsys.readouterr() # clear
bundles_command(_parse(["show", "x"]))
out = capsys.readouterr().out
assert "/x" in out
assert "s1" in out
assert "s2" in out
def test_delete(self, bundles_env, capsys):
bundles_command(_parse(["create", "doomed", "--skill", "s1"]))
capsys.readouterr()
bundles_command(_parse(["delete", "doomed"]))
out = capsys.readouterr().out
assert "Deleted bundle" in out
assert not (bundles_env / "doomed.yaml").exists()
def test_create_refuses_overwrite(self, bundles_env, capsys):
bundles_command(_parse(["create", "dup", "--skill", "s1"]))
capsys.readouterr()
with pytest.raises(SystemExit) as ei:
bundles_command(_parse(["create", "dup", "--skill", "s2"]))
assert ei.value.code == 1
out = capsys.readouterr().out
assert "already exists" in out.lower() or "--force" in out.lower()
def test_create_force_overwrites(self, bundles_env, capsys):
bundles_command(_parse(["create", "dup", "--skill", "s1"]))
capsys.readouterr()
bundles_command(_parse(["create", "dup", "--skill", "s2", "--force"]))
out = capsys.readouterr().out
assert "Created bundle" in out
def test_create_requires_skills(self, bundles_env, capsys, monkeypatch):
# Simulate user pressing Ctrl-D immediately at the interactive prompt.
monkeypatch.setattr("builtins.input", lambda *_a, **_kw: (_ for _ in ()).throw(EOFError()))
with pytest.raises(SystemExit):
bundles_command(_parse(["create", "empty"]))
def test_show_missing(self, bundles_env, capsys):
with pytest.raises(SystemExit) as ei:
bundles_command(_parse(["show", "ghost"]))
assert ei.value.code == 1
def test_reload(self, bundles_env, capsys):
# Reload on an empty dir reports no changes.
bundles_command(_parse(["reload"]))
out = capsys.readouterr().out
assert "No changes" in out or "0" in out