diff --git a/bin/customize.sh b/bin/customize.sh index d167523..23e2aa7 100755 --- a/bin/customize.sh +++ b/bin/customize.sh @@ -139,6 +139,15 @@ done echo "==> Checking for stale 'placeholder' references" STALE="$(grep -rn 'placeholder' "$PACKAGE" pyproject.toml .releaserc.yaml || true)" +# The author/email and description options are intentionally optional. When a +# caller omits one of them, the corresponding template default remains until +# the generated plugin is edited; those expected defaults are not stale paths. +if [[ -z "$AUTHOR" || -z "$EMAIL" ]]; then + STALE="$(printf '%s\n' "$STALE" | grep -vE 'pyproject\.toml:[0-9]+:authors =' || true)" +fi +if [[ -z "$DESCRIPTION" ]]; then + STALE="$(printf '%s\n' "$STALE" | grep -vE 'pyproject\.toml:[0-9]+:description =' || true)" +fi if [[ -n "$STALE" ]]; then echo "Error: stale 'placeholder' references found in customized files:" >&2 printf '%s\n' "$STALE" >&2 diff --git a/tests/test_customize_script.py b/tests/test_customize_script.py new file mode 100644 index 0000000..8286945 --- /dev/null +++ b/tests/test_customize_script.py @@ -0,0 +1,62 @@ +"""End-to-end tests for the template customization script.""" + +from __future__ import annotations + +import shutil +import subprocess +from pathlib import Path + + +REPO_ROOT = Path(__file__).resolve().parent.parent + + +def _make_scaffold(tmp_path: Path, extra_pyproject: str = "") -> Path: + root = tmp_path / "scaffold" + (root / "bin").mkdir(parents=True) + (root / "placeholder").mkdir() + (root / "placeholder" / "module.py").write_text( + "from placeholder.feature_groups import manifest\n", encoding="utf-8" + ) + shutil.copy2(REPO_ROOT / "bin" / "customize.sh", root / "bin" / "customize.sh") + shutil.copy2(REPO_ROOT / "pyproject.toml", root / "pyproject.toml") + shutil.copy2(REPO_ROOT / ".releaserc.yaml", root / ".releaserc.yaml") + if extra_pyproject: + pyproject = root / "pyproject.toml" + pyproject.write_text( + pyproject.read_text(encoding="utf-8") + extra_pyproject, + encoding="utf-8", + ) + return root + + +def _run_customize(root: Path, *args: str) -> subprocess.CompletedProcess[str]: + return subprocess.run( + ["bash", "bin/customize.sh", *args], + cwd=root, + capture_output=True, + check=False, + text=True, + ) + + +def test_optional_fields_can_be_left_for_manual_editing(tmp_path: Path) -> None: + """Omitting optional flags does not make the scaffold command fail.""" + root = _make_scaffold(tmp_path) + + result = _run_customize(root, "acme") + + assert result.returncode == 0, result.stdout + result.stderr + assert (root / "acme").is_dir() + + +def test_unexpected_entry_point_placeholder_still_fails(tmp_path: Path) -> None: + """The stale-reference check still rejects a missed entry-point rename.""" + root = _make_scaffold( + tmp_path, + '\n[project.entry-points."mloda.feature_groups.extra"]\nleftover = "placeholder.unrelated:FEATURE_GROUPS"\n', + ) + + result = _run_customize(root, "acme") + + assert result.returncode == 1 + assert "stale 'placeholder' references" in result.stderr