mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-09-30 17:13:12 +00:00
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
|
|
"""Tests for the release tooling scripts (CI guard + changelog CLI)."""
|
||
|
|
|
||
|
|
import importlib.util
|
||
|
|
import json
|
||
|
|
import pathlib
|
||
|
|
import sys
|
||
|
|
|
||
|
|
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
||
|
|
|
||
|
|
|
||
|
|
def _load(name, relpath):
|
||
|
|
spec = importlib.util.spec_from_file_location(name, ROOT / relpath)
|
||
|
|
mod = importlib.util.module_from_spec(spec)
|
||
|
|
sys.modules[name] = mod
|
||
|
|
spec.loader.exec_module(mod)
|
||
|
|
return mod
|
||
|
|
|
||
|
|
|
||
|
|
check = _load("check_changelog", "scripts/check_changelog.py")
|
||
|
|
cli = _load("changelog_cli", "scripts/changelog_cli.py")
|
||
|
|
|
||
|
|
|
||
|
|
class TestGuardEvaluate:
|
||
|
|
def test_clean_minor_bump_passes(self):
|
||
|
|
assert check.evaluate("1.10.0", "v1.9.2", True, True) == []
|
||
|
|
|
||
|
|
def test_bad_bump_flagged(self):
|
||
|
|
problems = check.evaluate("1.11.0", "v1.9.2", True, True) # skips a minor
|
||
|
|
assert problems and "clean single-step" in problems[0]
|
||
|
|
|
||
|
|
def test_unchanged_changelog_is_not_version_checked(self):
|
||
|
|
# A docs/dependabot PR (no CHANGELOG edit) never trips the bump check.
|
||
|
|
assert check.evaluate("5.0.0", "v1.9.2", False, True) == []
|
||
|
|
|
||
|
|
def test_copy_drift_flagged_even_when_unchanged(self):
|
||
|
|
problems = check.evaluate("1.9.2", "v1.9.2", False, False)
|
||
|
|
assert any("out of sync" in p for p in problems)
|
||
|
|
|
||
|
|
def test_missing_top_version_flagged_when_changed(self):
|
||
|
|
problems = check.evaluate(None, "v1.9.2", True, True)
|
||
|
|
assert any("no version entry" in p for p in problems)
|
||
|
|
|
||
|
|
def test_first_release_from_no_tags(self):
|
||
|
|
assert check.evaluate("0.1.0", "", True, True) == []
|
||
|
|
|
||
|
|
|
||
|
|
class TestChangelogCli:
|
||
|
|
SAMPLE = "## v1.10.0 — June 11, 2026\n\n**Self-announcing** releases.\n"
|
||
|
|
|
||
|
|
def test_top_version(self, tmp_path, capsys):
|
||
|
|
f = tmp_path / "CHANGELOG.md"
|
||
|
|
f.write_text(self.SAMPLE)
|
||
|
|
cli.main(["x", "top-version", str(f)])
|
||
|
|
assert capsys.readouterr().out == "1.10.0"
|
||
|
|
|
||
|
|
def test_bump_kind(self, tmp_path, capsys):
|
||
|
|
f = tmp_path / "CHANGELOG.md"
|
||
|
|
f.write_text(self.SAMPLE)
|
||
|
|
cli.main(["x", "bump-kind", str(f), "v1.9.2"])
|
||
|
|
assert capsys.readouterr().out == "minor"
|
||
|
|
|
||
|
|
def test_payload(self, tmp_path, capsys):
|
||
|
|
f = tmp_path / "CHANGELOG.md"
|
||
|
|
f.write_text(self.SAMPLE)
|
||
|
|
cli.main(["x", "payload", str(f), "1.10.0"])
|
||
|
|
out = json.loads(capsys.readouterr().out)
|
||
|
|
assert out["version"] == "1.10.0"
|
||
|
|
assert out["date_label"] == "June 11, 2026"
|
||
|
|
# CLI emits raw markdown; Slack conversion happens later, in the Lambda.
|
||
|
|
assert "**Self-announcing**" in out["notes"]
|