Files
hermes-agent/tests/scripts/test_commit_stamp_identity.py
ethernet 4e2648106f feat(release): commit.<stamp>-vX.Y.Z claim tags and their version helpers
A commit build's claim tag has the canary claim shape with the commit kind;
its version is X.Y.Z+commit.<stamp> (Termux X.Y.Z~commit.<stamp>-1; APT repo
staging keeps refusing commit claims). release_version/tag_core/releaseVersion/
releaseTagVersion/deb_version accept it; tag_kind names the kind.

Install stamps and icon generation of a commit build may carry its own claim tag
and still say source commit-build, so every updater keeps refusing it; a commit
tag without HERMES_BUILD_COMMIT is refused by the stamp writers and product
identity rather than falling through to the stable identity and its latest feed.

Salvaged from 98ee7de7c6, f8a42b0cc9, d9ead4e507, f161e6618d and 0f11098f12
in #145680, keeping stage_apt_repo closed to commit claims.

Co-authored-by: BearHuddleston <bear@bearhuddleston.dev>
2026-11-22 22:17:58 -08:00

88 lines
4.4 KiB
Python

"""The Python stamp writer binds tagless identity to the built checkout."""
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
ROOT = Path(__file__).resolve().parents[2]
def test_stamp_uses_built_commit_even_with_dispatch_sha_and_refuses_mismatch(tmp_path):
repo = tmp_path / 'repo'
repo.mkdir()
for relative in ('scripts/write_install_stamp.py',
'hermes_cli/__init__.py', 'hermes_cli/update_channel.py', 'hermes_cli/release_channels.py',
'pm/paths.py', 'pm/environments.py', 'hermes_cli/steward.py', 'hermes_constants.py'):
dest = repo / relative
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(ROOT / relative, dest)
# commit_build/distance -> versioning -> semver import each other; copy the
# whole package so a new sibling import cannot break the fixture.
shutil.copytree(ROOT / 'scripts/releases', repo / 'scripts/releases',
ignore=shutil.ignore_patterns('__pycache__'))
def git(*args):
return subprocess.run(['git', *args], cwd=repo, check=True, capture_output=True,
text=True, encoding='utf-8', timeout=30).stdout.strip()
git('init', '-q', '-b', 'main')
git('config', 'user.name', 'Fixture')
git('config', 'user.email', 'fixture@example.invalid')
git('add', '.')
git('commit', '-qm', 'main')
main = git('rev-parse', 'HEAD')
git('checkout', '-qb', 'feature')
(repo / 'feature').write_text('feature\n', encoding='utf-8')
git('add', 'feature')
git('commit', '-qm', 'feature')
feature = git('rev-parse', 'HEAD')
out = tmp_path / 'stamp.json'
env = {k: v for k, v in os.environ.items() if not k.startswith(('GITHUB_', 'HERMES_BUILD_', 'HERMES_PAYLOAD_'))}
env.update({'GITHUB_SHA': main, 'GITHUB_REF_NAME': 'main',
'HERMES_BUILD_COMMIT': feature, 'HERMES_DESKTOP_VARIANT': 'bundled',
'HERMES_HOME': str(tmp_path / 'home')})
command = [sys.executable, '-I', '-S', str(repo / 'scripts/write_install_stamp.py'),
'--output', str(out), '--base-version', '0.28.0', '--distance', '0',
'--update-mechanism', 'app-installer']
def run(*args, override=None):
return subprocess.run([*command, *args], cwd=tmp_path, env={**env, **(override or {})},
capture_output=True, text=True, encoding='utf-8', timeout=30, check=False)
result = run()
assert result.returncode == 0, result.stderr
data = json.loads(out.read_text(encoding='utf-8'))
assert data['commit'] == feature and data['source'] == 'commit-build'
assert data['baseVersion'] == data['displayVersion'] == '0.28.0'
assert data['branch'] is None and data['tag'] is None and data['updateMechanism'] == 'external'
result = run('--commit', feature)
assert result.returncode == 0, result.stderr
before = out.read_bytes()
git('checkout', '-q', 'main')
for args in ((), ('--commit', feature)):
result = run(*args)
assert result.returncode != 0 and 'checkout' in result.stderr.lower()
assert out.read_bytes() == before
git('checkout', '-q', 'feature')
for extra in ({'HERMES_BUILD_COMMIT': feature[:8]}, {'HERMES_PAYLOAD_TAG': 'v1.2.3'},
{'HERMES_BUILD_COMMIT': ' ' + feature}):
assert run(override=extra).returncode != 0
assert out.read_bytes() == before
# A commit build on the release pipeline carries its own claim tag and stays a commit build.
claim = 'commit.20261026T180000Z-v0.28.0'
result = run('--commit', feature, override={'HERMES_PAYLOAD_TAG': claim})
assert result.returncode == 0, result.stderr
claimed = json.loads(out.read_text(encoding='utf-8'))
assert claimed['tag'] == claim and claimed['source'] == 'commit-build'
assert claimed['updateMechanism'] == 'external' and claimed['branch'] is None
# Without HERMES_BUILD_COMMIT, a commit claim is refused rather than stamped as a release.
kept = out.read_bytes()
assert run('--commit', feature, override={'HERMES_BUILD_COMMIT': '', 'HERMES_PAYLOAD_TAG': claim}).returncode != 0
assert out.read_bytes() == kept
result = run('--commit', feature, override={'HERMES_BUILD_COMMIT': '', 'HERMES_PAYLOAD_TAG': 'v1.2.3'})
assert result.returncode == 0, result.stderr
assert json.loads(out.read_text(encoding='utf-8'))['tag'] == 'v1.2.3'