"""Config-correctness tests for the CI version-bump/tag/changelog automation (gitea #50). The workflow YAML itself can only be exercised by a real push to master, so these check the two config files it drives (.bumpversion.toml, cliff.toml) against real repo content instead. """ import re import shutil import subprocess import tomllib from pathlib import Path import pytest _ROOT = Path(__file__).resolve().parents[1] def test_bumpversion_search_pattern_matches_pyproject(): bump_config = tomllib.loads((_ROOT / ".bumpversion.toml").read_text())["tool"]["bumpversion"] current_version = bump_config["current_version"] search = bump_config["files"][0]["search"].format(current_version=current_version) pyproject = (_ROOT / "pyproject.toml").read_text() assert search in pyproject, ( f"bumpversion search pattern {search!r} (rendered from .bumpversion.toml's " f"current_version={current_version!r}) not found in pyproject.toml — " "the bump would silently edit nothing" ) @pytest.mark.skipif(shutil.which("git-cliff") is None, reason="git-cliff binary not on PATH") def test_cliff_config_groups_and_links_commits(tmp_path): repo = tmp_path / "repo" repo.mkdir() subprocess.run(["git", "init", "-q"], cwd=repo, check=True) subprocess.run(["git", "config", "user.name", "test"], cwd=repo, check=True) subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=repo, check=True) _commit(repo, "Add class-balanced secondary particle-type loss (gitea #44)") _commit(repo, "Fix leaking secondary energy budget") _commit(repo, "Merge pull request 'Add X' (#1) from fix/issue-1 into master") _commit(repo, "chore: bump version 0.3.3 -> 0.3.4 [skip ci]") result = subprocess.run( [ "git-cliff", "--config", str(_ROOT / "cliff.toml"), "--repository", str(repo), "--tag", "v0.3.4", "--unreleased", ], capture_output=True, text=True, check=True, ) changelog = result.stdout assert "## [0.3.4]" in changelog assert "### Added" in changelog assert "### Fixed" in changelog assert re.search( r"\[gitea #44\]\(https://git\.larsbogner\.de/lars/giant/issues/44\)", changelog, ) assert "Add class-balanced secondary particle-type loss" in changelog assert "Fix leaking secondary energy budget" in changelog assert "Merge pull request" not in changelog assert "skip ci" not in changelog def _commit(repo: Path, message: str) -> None: (repo / "f.txt").write_text(message) subprocess.run(["git", "add", "f.txt"], cwd=repo, check=True) subprocess.run(["git", "commit", "-q", "-m", message], cwd=repo, check=True)