Hermex / tests /hermes_cli /test_hf_space_update.py
Hermes Space Updater
Add HF Space-safe Hermes update flow
a74a718
Raw
History Blame Contribute Delete
1.91 kB
from pathlib import Path
from hermes_cli import hf_space_update
def test_pick_target_ref_defaults_to_latest_tag(monkeypatch):
monkeypatch.setattr(hf_space_update, "list_remote_tags", lambda *_args, **_kwargs: ["v2026.4.16", "v2026.4.13"])
assert hf_space_update.pick_target_ref(None) == "v2026.4.16"
def test_pick_target_ref_preserves_explicit_ref():
assert hf_space_update.pick_target_ref("v2026.4.8") == "v2026.4.8"
def test_apply_space_repo_update_writes_ref_and_pushes(monkeypatch, tmp_path):
repo_dir = tmp_path / "repo"
docker_dir = repo_dir / "docker"
docker_dir.mkdir(parents=True)
ref_file = docker_dir / "HERMES_UPSTREAM_REF"
ref_file.write_text("v2026.4.13\n", encoding="utf-8")
calls = []
def fake_run(cmd, **kwargs):
calls.append((cmd, kwargs))
if cmd[:2] == ["git", "clone"]:
return None
if cmd[:3] == ["git", "config", "user.email"]:
return None
if cmd[:3] == ["git", "config", "user.name"]:
return None
if cmd[:2] == ["git", "add"]:
return None
if cmd[:2] == ["git", "commit"]:
return None
if cmd[:2] == ["git", "push"]:
return None
if cmd[:3] == ["git", "rev-parse", "HEAD"]:
class Result:
stdout = "abc123\n"
return Result()
raise AssertionError(f"unexpected command: {cmd}")
monkeypatch.setattr(hf_space_update, "run", fake_run)
monkeypatch.setattr(hf_space_update, "clone_space_repo", lambda *_args, **_kwargs: repo_dir)
commit_sha = hf_space_update.apply_space_repo_update(
space_id="cjovs/HermesAgent",
token="secret",
target_ref="v2026.4.16",
)
assert commit_sha == "abc123"
assert ref_file.read_text(encoding="utf-8") == "v2026.4.16\n"
assert any(cmd[:2] == ["git", "push"] for cmd, _ in calls)