hermes-agent/tests/test_packaging_build_guard.py
ethernet d84e11af4d
rip out brew + pip/PyPI wheel support (#68217)
Removes Homebrew and PyPI wheel/sdist as Hermes distribution paths while
preserving the supported source, Docker, and Nix workflows.

Changes:
- Removes the Homebrew formula, PyPI publish workflow, sdist manifest
  (MANIFEST.in), and wheel/sdist release-attachment logic from scripts/release.py.
- Keeps setuptools metadata and entry points required by editable installs
  and Docker/Nix builds, but adds a setup.py guard that rejects wheel/sdist
  builds outside a sealed Nix derivation (HERMES_NIX_BUILD=1).
- Removes pip/Homebrew install detection, PyPI update checks, the pip
  self-update path, the deprecation-banner state, the postinstall subcommand,
  wheel data-directory fallbacks in agent/i18n.py and hermes_constants.py,
  and the ACP Registry manifest/version-lockstep release logic.
- Adds /nix/store/ path detection so `nix run` / `nix profile install`
  installs (which don't set HERMES_MANAGED) are correctly identified as
  "nix" rather than falling through to "git"/"unknown".
- Retired install-method values ("pip", "homebrew") in existing
  .install_method stamps (both code-scoped and home-scoped) are ignored by
  the allowlist reader and fall through to "unknown" instead of resurrecting
  a retired enum value.
- Updates Nix packaging to ship bare runtime data (locales, optional-mcps)
  through store symlinks and wrapper env vars instead of wheel data-files.
- Removes the ACP Registry manifest/icon and their version-lockstep tests.
- Deletes or rewrites packaging, pip-update, Homebrew, and ACP Registry
  tests; adds parametrized coverage for the packaging build guard covering
  BOTH sdist and wheel paths (the guards live in separate cmdclass entries
  — a passing sdist test proves nothing about the wheel path).
- Updates installation/platform documentation and related user-facing copy.
- Adjusts the supply-chain scan so deleted install-hook files do not trigger
  a finding, while additions or modifications still require the existing
  ci-reviewed label gate.

Supported installation paths (unchanged):
- git installer (install.sh)
- Docker
- Nix/NixOS
- editable development installs (uv sync, uv pip install -e ., pip install -e .)
2026-07-22 16:51:01 -04:00

72 lines
2.4 KiB
Python

"""Behavioral regression coverage for the wheel/sdist distribution guard."""
import os
import subprocess
import sys
from pathlib import Path
import pytest
PROJECT_ROOT = Path(__file__).resolve().parents[1]
def _build_artifact(kind: str, tmp_path, *, nix_build: bool) -> subprocess.CompletedProcess[str]:
"""Invoke the real PEP 517 hook (build_sdist / build_wheel) as a subprocess.
The wheel and sdist guards live in SEPARATE cmdclass entries in setup.py
(the bdist_wheel one behind a try/except ImportError), so each hook needs
its own regression coverage — a passing sdist test proves nothing about
the wheel path.
"""
env = os.environ.copy()
# nix develop exports this too, so it must not grant permission to build
# a distributable artifact.
env["NIX_BUILD_TOP"] = "/build/devshell"
if nix_build:
env["HERMES_NIX_BUILD"] = "1"
else:
env.pop("HERMES_NIX_BUILD", None)
# Redirect setuptools' scratch dirs (build/, *.egg-info) into tmp_path so
# the allowed-marker build doesn't litter the real worktree.
scratch = tmp_path / "scratch"
scratch.mkdir()
extra_cfg = tmp_path / "dist-extra.cfg"
extra_cfg.write_text(
f"[build]\nbuild_base = {scratch / 'build'}\n\n[egg_info]\negg_base = {scratch}\n",
encoding="utf-8",
)
env["DIST_EXTRA_CONFIG"] = str(extra_cfg)
return subprocess.run(
[
sys.executable,
"-c",
"from setuptools.build_meta import build_{kind}; build_{kind}(r'{out}')".format(
kind=kind, out=tmp_path
),
],
cwd=PROJECT_ROOT,
env=env,
text=True,
capture_output=True,
check=False,
)
@pytest.mark.parametrize("kind", ["sdist", "wheel"])
def test_artifact_build_rejects_nix_development_shell_environment(kind, tmp_path):
result = _build_artifact(kind, tmp_path, nix_build=False)
assert result.returncode != 0
assert "Building wheels or sdists for hermes-agent is not supported" in result.stderr
@pytest.mark.parametrize(
("kind", "artifact_glob"),
[("sdist", "hermes_agent-*.tar.gz"), ("wheel", "hermes_agent-*.whl")],
)
def test_artifact_build_allows_explicit_nix_package_build_marker(kind, artifact_glob, tmp_path):
result = _build_artifact(kind, tmp_path, nix_build=True)
assert result.returncode == 0, result.stderr
assert list(tmp_path.glob(artifact_glob))