"""Tests for the CHANGELOG parser used by Slack App Home.""" from pathlib import Path from shared.changelog import latest_entry, parse_changelog, version_entries ROOT = Path(__file__).resolve().parents[2] # A faithful slice of the real file: preamble prose, a plain version entry, a # legacy combined entry, and date-only historical headers with no version. SAMPLE = """# Changelog What's changed in the **After-Hours Shift Manager**. Newest first. Versions are `MAJOR.MINOR.PATCH`. --- ## v1.10.0 — June 11, 2026 **Release notes now announce themselves.** Big new feature line. ## v1.9.2 — June 1, 2026 **Setup-guide fix.** A patch. ## v1.9.0 / v1.9.1 — June 1, 2026 **Last-minute drops blocked.** Combined entry. *(v1.9.1 was a library update.)* --- ## May 2026 — Phone-system automation - Live phone routing follows the schedule. ## April 3, 2026 — Launch 🎉 The first version. """ def test_package_copy_matches_root_changelog(): root = (ROOT / "CHANGELOG.md").read_text() package = (ROOT / "src" / "slack-bot" / "CHANGELOG.md").read_text() assert package == root def test_preamble_is_not_an_entry(): # The "# Changelog" h1 and prose before the first "##" must not parse as entries. entries = parse_changelog(SAMPLE) assert all("Changelog" not in e.title for e in entries) def test_latest_entry_fields(): entry = latest_entry(SAMPLE) assert entry.version == "1.10.0" assert entry.date_label == "June 11, 2026" assert "announce themselves" in entry.body def test_combined_header_reports_higher_version(): combined = next(e for e in parse_changelog(SAMPLE) if "v1.9.0" in e.title) assert combined.versions == ("1.9.0", "1.9.1") assert combined.version == "1.9.1" # the higher of the two def test_body_excludes_thematic_break_rules(): # The "---" rule separating eras must not bleed into the combined entry's notes. combined = next(e for e in parse_changelog(SAMPLE) if "v1.9.0" in e.title) assert "---" not in combined.body def test_date_only_headers_carry_no_version(): titles = {e.title for e in parse_changelog(SAMPLE) if not e.versions} assert "May 2026 — Phone-system automation" in titles assert "April 3, 2026 — Launch 🎉" in titles def test_version_entries_excludes_date_only(): versions = [e.version for e in version_entries(SAMPLE)] assert versions == ["1.10.0", "1.9.2", "1.9.1"] def test_empty_changelog_has_no_latest_entry(): assert latest_entry("# Changelog\n") is None