"""Tests for build script version utilities."""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "build" / "scripts"))

from version_utils import get_release_notes


class TestReleaseNotes:
    """Test release note extraction for published releases."""

    def test_get_release_notes_from_changelog(self, tmp_path):
        """Extract only the selected version section from the changelog."""
        changelog = tmp_path / "CHANGELOG.md"
        changelog.write_text(
            """## [0.9.1] - 2026-04-15

### Added
- Better update text
- New installer checks

### Fixed
- Upload retries

## [0.9.0] - 2026-04-01

### Added
- Older changes
""",
            encoding="utf-8",
        )

        notes = get_release_notes("0.9.1", project_root=tmp_path)

        assert "Better update text" in notes
        assert "New installer checks" in notes
        assert "Older changes" not in notes

    def test_get_release_notes_uses_fallback_when_missing(self, tmp_path):
        """Return a readable fallback when no changelog entry exists."""
        notes = get_release_notes("0.9.1", project_root=tmp_path)

        assert "WebDrop Bridge v0.9.1" in notes
        assert "release package" in notes.lower()
