From 6a76ee26afaa0c863165c029f1968dfbdde35b21 Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 3 Nov 2026 08:28:08 -0700 Subject: [PATCH] ci: Run the test suite before building release images (v2.7.1) Add a 'test' stage to the Containerfile (production base image plus pytest) and build it in the release workflow before the push step, so a failing test stops the release. Fix the eight tests that were failing: media validation returns a PIL Image since v1.5.0, and the migration test needs TESTING to skip production config checks. Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/build-container.yml | 6 +++++- CHANGELOG.md | 10 ++++++++++ Containerfile | 22 +++++++++++++++++++++- starpunk/__init__.py | 4 ++-- tests/test_media_upload.py | 23 +++++++++-------------- tests/test_migration_race_condition.py | 2 +- 6 files changed, 48 insertions(+), 19 deletions(-) diff --git a/.gitea/workflows/build-container.yml b/.gitea/workflows/build-container.yml index e923100..cb70731 100644 --- a/.gitea/workflows/build-container.yml +++ b/.gitea/workflows/build-container.yml @@ -1,5 +1,5 @@ # Gitea Actions workflow for StarPunk -# Builds and pushes container images on version tags. +# Runs the tests, then builds and pushes container images on version tags. # # The runner has no Docker daemon (that would give workflows root on the # server). Images are built by the rootless BuildKit container next to it, @@ -30,6 +30,10 @@ jobs: run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u "${{ github.repository_owner }}" --password-stdin - name: Use the BuildKit socket run: docker buildx create --name ci --driver remote "$BUILDKIT" --use + # Builds the Containerfile's test stage, which runs pytest; a failure + # stops the workflow before anything is pushed + - name: Run tests + run: docker buildx build --target test --progress plain -f Containerfile . - name: Build and push run: | image="$REGISTRY/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dec0a8..39349f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.7.1] - 2026-11-03 + +### Changed + +- Releases run the full test suite first: CI builds the Containerfile's new `test` stage (same Python image as production) and stops before pushing an image if any test fails + +### Fixed + +- Eight tests that had been failing: the image validation tests still expected bytes (validation has returned an image object since v1.5.0), and a migration test started the app in production mode + ## [2.7.0] - 2026-11-03 Webmention now follows the [W3C Recommendation](https://www.w3.org/TR/webmention/) throughout. diff --git a/Containerfile b/Containerfile index 047c6b0..27d06cb 100644 --- a/Containerfile +++ b/Containerfile @@ -23,7 +23,27 @@ RUN uv venv /opt/venv && \ uv pip install --no-cache -r requirements.txt # ============================================================================ -# Runtime Stage - Minimal production image +# Test Stage - Runs the test suite (CI builds it with --target test) +# ============================================================================ +FROM python:3.11-slim AS test + +COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv +COPY --from=builder /opt/venv /opt/venv +RUN uv pip install --no-cache --python /opt/venv/bin/python pytest pytest-mock + +ENV PATH="/opt/venv/bin:$PATH" \ + PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + SESSION_SECRET=ci-test-secret \ + SITE_URL=http://localhost:5000 \ + ADMIN_ME=https://test.example.com + +WORKDIR /app +COPY . . +RUN python -m pytest -q -p no:cacheprovider tests + +# ============================================================================ +# Runtime Stage - Minimal production image (default target: keep it last) # ============================================================================ FROM python:3.11-slim diff --git a/starpunk/__init__.py b/starpunk/__init__.py index 0eb7fd9..e4979af 100644 --- a/starpunk/__init__.py +++ b/starpunk/__init__.py @@ -459,5 +459,5 @@ def create_app(config=None): # Package version (Semantic Versioning 2.0.0) # See docs/standards/versioning-strategy.md for details -__version__ = "2.7.0" -__version_info__ = (2, 7, 0) +__version__ = "2.7.1" +__version_info__ = (2, 7, 1) diff --git a/tests/test_media_upload.py b/tests/test_media_upload.py index 3c2fd01..91dd71c 100644 --- a/tests/test_media_upload.py +++ b/tests/test_media_upload.py @@ -110,7 +110,7 @@ class TestImageValidation: assert mime_type == 'image/jpeg' assert width == 800 assert height == 600 - assert file_data == image_data # No conversion + assert isinstance(file_data, Image.Image) # validate_image returns a PIL Image (v1.5.0) def test_valid_png(self): """Test validation of valid PNG image""" @@ -120,7 +120,7 @@ class TestImageValidation: assert mime_type == 'image/png' assert width == 800 assert height == 600 - assert file_data == image_data # No conversion + assert isinstance(file_data, Image.Image) # validate_image returns a PIL Image (v1.5.0) def test_valid_gif(self): """Test validation of valid GIF image""" @@ -130,7 +130,7 @@ class TestImageValidation: assert mime_type == 'image/gif' assert width == 800 assert height == 600 - assert file_data == image_data # No conversion + assert isinstance(file_data, Image.Image) # validate_image returns a PIL Image (v1.5.0) def test_valid_webp(self): """Test validation of valid WebP image""" @@ -140,7 +140,7 @@ class TestImageValidation: assert mime_type == 'image/webp' assert width == 800 assert height == 600 - assert file_data == image_data # No conversion + assert isinstance(file_data, Image.Image) # validate_image returns a PIL Image (v1.5.0) def test_file_too_large(self): """Test rejection of >10MB file (per Q6)""" @@ -183,11 +183,8 @@ class TestHEICSupport: assert mime_type == 'image/jpeg' assert width == 800 assert height == 600 - # file_data should be different (converted to JPEG) - assert file_data != heic_data - # Verify it's actually JPEG by opening it - img = Image.open(io.BytesIO(file_data)) - assert img.format == 'JPEG' + # Converted to JPEG (validate_image returns a PIL Image) + assert file_data.format == 'JPEG' def test_heic_with_rgba_mode(self): """Test HEIC with alpha channel is converted to RGB JPEG""" @@ -209,8 +206,7 @@ class TestHEICSupport: # Should be converted to JPEG (no alpha) assert mime_type == 'image/jpeg' # Verify it's RGB (no alpha) - img = Image.open(io.BytesIO(file_data)) - assert img.mode == 'RGB' + assert file_data.mode == 'RGB' def test_heic_dimensions_preserved(self): """Test HEIC conversion preserves dimensions""" @@ -273,9 +269,8 @@ class TestMPOSupport: assert mime_type == 'image/jpeg' assert width == 800 assert height == 600 - # Verify it's actually JPEG by opening it - img = Image.open(io.BytesIO(file_data)) - assert img.format == 'JPEG' + # Converted to JPEG (validate_image returns a PIL Image) + assert file_data.format == 'JPEG' # Note: MPO with single frame may have identical bytes to JPEG # The important part is the format detection and MIME type correction diff --git a/tests/test_migration_race_condition.py b/tests/test_migration_race_condition.py index b85aecc..7365f18 100644 --- a/tests/test_migration_race_condition.py +++ b/tests/test_migration_race_condition.py @@ -43,7 +43,7 @@ class TestRetryLogic: from starpunk.database import init_db from starpunk import create_app - app = create_app({'DATABASE_PATH': str(temp_db)}) + app = create_app({'DATABASE_PATH': str(temp_db), 'TESTING': True}) init_db(app) # Verify migrations table exists and has records