Files
hermes-agent/tests/hermes_cli/test_update_version_report.py
Teknium 64cfa38fa6 Port from PrimeIntellect-ai/prime-agent#630: report version transition after hermes update
'✓ Update complete!' now shows what the update actually delivered:
'✓ Update complete! (v0.19.4 → v0.20.0)' when the pyproject version
changed, '(v0.20.0)' when commits landed within one release, and the
plain message when the version cannot be read. Reads the on-disk
pyproject.toml (not importlib.metadata, which still describes the old
install after a pull). Applied to both the git and Windows-ZIP paths.
2026-08-16 22:07:09 -07:00

68 lines
2.1 KiB
Python

"""Version transition reporting after ``hermes update``.
Ported from PrimeIntellect-ai/prime-agent#630: a successful self-update
reports both versions (``v0.19.4 → v0.20.0``) when the pyproject version
changed, and degrades gracefully when either side is unknown.
"""
from pathlib import Path
import pytest
from hermes_cli import update_cmd
def _write_pyproject(root: Path, version: str) -> None:
(root / "pyproject.toml").write_text(
f'[project]\nname = "hermes-agent"\nversion = "{version}"\n',
encoding="utf-8",
)
@pytest.fixture()
def fake_root(tmp_path, monkeypatch):
class _FakeMain:
PROJECT_ROOT = tmp_path
monkeypatch.setattr(update_cmd, "_m", lambda: _FakeMain)
return tmp_path
class TestReadProjectVersion:
def test_reads_version(self, fake_root):
_write_pyproject(fake_root, "0.20.0")
assert update_cmd._read_project_version() == "0.20.0"
def test_missing_file_returns_none(self, fake_root):
assert update_cmd._read_project_version() is None
def test_malformed_toml_returns_none(self, fake_root):
(fake_root / "pyproject.toml").write_text("not [ toml", encoding="utf-8")
assert update_cmd._read_project_version() is None
class TestUpdateCompleteMessage:
def test_reports_transition_when_version_changed(self, fake_root):
_write_pyproject(fake_root, "0.20.0")
assert (
update_cmd._update_complete_message("0.19.4")
== "✓ Update complete! (v0.19.4 → v0.20.0)"
)
def test_same_version_reports_single_version(self, fake_root):
_write_pyproject(fake_root, "0.20.0")
assert (
update_cmd._update_complete_message("0.20.0")
== "✓ Update complete! (v0.20.0)"
)
def test_unknown_pre_version_still_shows_current(self, fake_root):
_write_pyproject(fake_root, "0.20.0")
assert (
update_cmd._update_complete_message(None)
== "✓ Update complete! (v0.20.0)"
)
def test_unknown_post_version_falls_back_to_plain(self, fake_root):
assert update_cmd._update_complete_message("0.19.4") == "✓ Update complete!"