File size: 1,908 Bytes
a74a718 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 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)
|