Skip to content

The agent that grows with you

fix(termux): validate updater refusal by artifact identity

ethernetd81c0a3fcc41
diff --git a/scripts/termux/validate_installed.py b/scripts/termux/validate_installed.py
index 7a8d7881e6b..d145d782967 100644
--- a/scripts/termux/validate_installed.py
+++ b/scripts/termux/validate_installed.py
@@ -78,6 +78,17 @@ def tui_smoke(launcher: Path, env: dict[str, str], cwd: Path) -> None:
os.close(master)
+def validate_update_refusal(project_root: Path, result: subprocess.CompletedProcess) -> None:
+ from hermes_cli.update_contract import COMMIT_BUILD_UPDATE_MESSAGE, is_commit_build
+
+ # Commit artifacts have no update channel, even when installed through dpkg.
+ commit_build = is_commit_build(project_root)
+ expected = COMMIT_BUILD_UPDATE_MESSAGE if commit_build else "pkg upgrade hermes-agent"
+ if result.returncode != 2 or expected not in result.stdout + result.stderr:
+ raise RuntimeError(f"wrong updater refusal ({result.returncode}): {result.stdout}\n{result.stderr}")
+ print("COMMIT_BUILD_UPDATE_REFUSAL_OK" if commit_build else "APT_UPDATE_REFUSAL_OK", flush=True)
+
+
def main() -> None:
prefix = Path(os.environ["PREFIX"])
root = prefix / "lib/hermes-agent"
@@ -131,9 +142,7 @@ def main() -> None:
"assert not issues, issues; print('PM_RUNTIME_TOOLS_OK')",
], env, home)
result = subprocess.run([str(launcher), "update"], env=env, cwd=home, capture_output=True, text=True, timeout=60)
- if result.returncode == 0 or "pkg upgrade hermes-agent" not in result.stdout + result.stderr:
- raise RuntimeError(f"wrong updater refusal ({result.returncode}): {result.stdout}\n{result.stderr}")
- print("APT_UPDATE_REFUSAL_OK", flush=True)
+ validate_update_refusal(root / "app", result)
tui_smoke(launcher, env, home)
print("INSTALLED_BUNDLE_VALIDATION_OK", flush=True)
diff --git a/tests/scripts/test_termux_update_refusal.py b/tests/scripts/test_termux_update_refusal.py
new file mode 100644
index 00000000000..ad9eacaa386
--- /dev/null
+++ b/tests/scripts/test_termux_update_refusal.py
@@ -0,0 +1,66 @@
+"""The installed-package gate distinguishes commit builds from release packages."""
+from __future__ import annotations
+
+import json
+import subprocess
+from pathlib import Path
+from types import SimpleNamespace
+
+import pytest
+
+from hermes_cli.update_contract import COMMIT_BUILD_UPDATE_MESSAGE
+
+
[email protected](params=["bundle", "commit-build"])
+def artifact(tmp_path, request):
+ root = tmp_path / "app"
+ root.mkdir()
+ (root / "install-stamp.json").write_text(json.dumps({
+ "source": request.param,
+ "distribution": "apt-termux",
+ "payload": "bundled",
+ "updateMechanism": "external",
+ "commit": "a" * 40,
+ "tag": None if request.param == "commit-build" else "v1.2.3",
+ }), encoding="utf-8")
+ return root, request.param
+
+
+def test_validator_accepts_real_cli_refusal_for_installed_identity(artifact, monkeypatch, capsys, tmp_path):
+ from hermes_cli import main
+ from scripts.termux.validate_installed import validate_update_refusal
+
+ root, source = artifact
+ monkeypatch.setattr(main, "PROJECT_ROOT", root)
+ monkeypatch.setattr("hermes_cli.image_provenance.IMAGE_PROVENANCE_PATH", tmp_path / "absent")
+ monkeypatch.delenv("HERMES_MANAGED", raising=False)
+
+ def unexpected_update(*args, **kwargs):
+ pytest.fail("sealed package reached the mutation path")
+
+ monkeypatch.setattr(main, "_install_hangup_protection", unexpected_update)
+ with pytest.raises(SystemExit) as stopped:
+ main.cmd_update(SimpleNamespace())
+ output = capsys.readouterr()
+ status = stopped.value.code
+ assert isinstance(status, int) and status == 2
+ expected = COMMIT_BUILD_UPDATE_MESSAGE if source == "commit-build" else "pkg upgrade hermes-agent"
+ assert expected in output.out + output.err
+ result = subprocess.CompletedProcess(["hermes", "update"], status, output.out, output.err)
+ validate_update_refusal(root, result)
+ marker = "COMMIT_BUILD_UPDATE_REFUSAL_OK" if source == "commit-build" else "APT_UPDATE_REFUSAL_OK"
+ assert marker in capsys.readouterr().out
+
+
+def test_validator_rejects_wrong_refusal_or_exit_status(artifact):
+ from scripts.termux.validate_installed import validate_update_refusal
+
+ root, source = artifact
+ expected = COMMIT_BUILD_UPDATE_MESSAGE if source == "commit-build" else "pkg upgrade hermes-agent"
+ other = "pkg upgrade hermes-agent" if source == "commit-build" else COMMIT_BUILD_UPDATE_MESSAGE
+ for status, message in ((0, expected), (1, expected), (2, other), (2, "unrelated startup failure")):
+ result = subprocess.CompletedProcess(["hermes", "update"], status, message, "")
+ with pytest.raises(RuntimeError, match="wrong updater refusal"):
+ validate_update_refusal(root, result)