Files
hermes-agent/tests/hermes_cli/test_source_stamp.py
ethernet c13ea774e6 refactor: make install-stamp.json the single runtime version identity
Runtime identity resolved through hermes_cli.__version__ (a static 0.0.0
on source installs, rewritten by release stamping) leaked v0.0.0 into
About, /api/health, User-Agents, and plugin compat, and source updates
showed "couldn't reach update server" because identity and channel
authority disagreed with the checkout.

Now: get_version_info() resolves install stamp -> live git -> unknown,
never pyproject metadata, never a package constant. Source checkouts
derive identity from their reachable release tag; the completion tail of
every successful install/update/historical takeover atomically rewrites
install-stamp.json with that identity; a stale source stamp whose commit
no longer matches HEAD defers to live git. ACP/TUI use derived_version
for display and base_version for protocol fields; all ~44 runtime
__version__ consumers migrated; hermes_cli.__version__ and generated
_version.py are gone; release stamping only touches the native manifests
external builders consume (nix/tauri/cargo) and passes release identity
straight into write_install_stamp.py; pyproject.toml stays inert 0.0.0.
Desktop no longer synthesizes a competing install-stamp.json: the
checkout owns its stamp, and desktop-bootstrap classification keys on
the bootstrap-complete marker. verify-bootstrap-version-stamp.py now
cross-checks the checkout's stamp (baseVersion + commit == HEAD).

Validation: 31-file focused suite green (version identity, stamping,
adoption, providers, gateway, acp/tui runtime identity, api server via
extras env, release graph); desktop tsc + 25 vitest green; real-repo
probe: base=unknown derived=git.0635606.dirty source=git on this
checkout; clean-env imports resolve entirely from this tree; windows
footgun + compat-pointer scans clean.
2026-09-23 11:41:01 -04:00

70 lines
2.5 KiB
Python

"""Source checkout identity is written only from the checkout itself."""
import json
import os
from pathlib import Path
import subprocess
def _git(repo: Path, *args: str) -> str:
result = subprocess.run(
["git", *args], cwd=repo, text=True, capture_output=True, check=True,
env={"HOME": str(repo.parent), "PATH": os.environ["PATH"]},
)
return result.stdout.strip()
def test_write_source_stamp_records_live_checkout_identity_atomically(tmp_path):
from hermes_cli.source_stamp import write_source_stamp
repo = tmp_path / "repo"
repo.mkdir()
_git(repo, "init", "-q")
_git(repo, "config", "user.name", "Hermes Test")
_git(repo, "config", "user.email", "hermes@example.invalid")
(repo / "tracked").write_text("release\n", encoding="utf-8")
_git(repo, "add", "tracked")
_git(repo, "commit", "-qm", "release")
_git(repo, "tag", "v0.21.4")
(repo / "tracked").write_text("next\n", encoding="utf-8")
_git(repo, "commit", "-qam", "next")
written = write_source_stamp(repo)
stored = json.loads((repo / "install-stamp.json").read_text(encoding="utf-8-sig"))
assert stored == written
assert stored["commit"] == _git(repo, "rev-parse", "HEAD")
assert stored["baseVersion"] == "0.21.4"
assert stored["displayVersion"].startswith("0.21.4+1.g")
assert stored["source"] == "git"
assert stored["distribution"] is None
assert stored["updateMechanism"] == "self"
assert not list(repo.glob(".install-stamp.*.tmp"))
def test_stale_source_stamp_defers_to_live_checkout(tmp_path, monkeypatch):
from hermes_cli.source_stamp import write_source_stamp
from hermes_cli.version_info import _reset_version_info_cache, get_version_info
repo = tmp_path / "repo"
repo.mkdir()
_git(repo, "init", "-q")
_git(repo, "config", "user.name", "Hermes Test")
_git(repo, "config", "user.email", "hermes@example.invalid")
(repo / "tracked").write_text("release\n", encoding="utf-8")
_git(repo, "add", "tracked")
_git(repo, "commit", "-qm", "release")
_git(repo, "tag", "v0.21.4")
write_source_stamp(repo)
(repo / "tracked").write_text("manual pull\n", encoding="utf-8")
_git(repo, "commit", "-qam", "manual pull")
monkeypatch.setenv("HERMES_INSTALL_ROOT", str(repo))
monkeypatch.setattr("hermes_cli.version_info._resolve_repo_dir", lambda: repo)
_reset_version_info_cache()
info = get_version_info()
assert info.commit == _git(repo, "rev-parse", "HEAD")
assert info.derived_version.startswith("0.21.4+1.g")
assert info.source == "git"