diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..54c3bd2 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,65 @@ +name: Testy + +# Odpala się przy każdym pushu (dowolna gałąź) oraz dla pull requestów do master. +on: + push: + pull_request: + branches: [master] + +jobs: + logic-tests: + name: Testy warstwy logicznej (silnik) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Python 3.12 (jak w obrazach Dockera) + uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: pip + cache-dependency-path: services/logic/requirements-dev.txt + + # Jądro efemeryd JPL (de421.bsp, ~17 MB). Cache'ujemy je między runami. + - name: Cache jądra efemeryd + uses: actions/cache@v4 + with: + path: services/logic/.ephemeris + key: ephemeris-de421 + + # Pobieramy jawnie (a nie licząc na auto-pobranie przez Skyfield), żeby + # brak jądra był twardym błędem, a nie cichym pomijaniem testów. + - name: Pobierz jądro efemeryd (gdy brak w cache) + run: | + mkdir -p services/logic/.ephemeris + if [ ! -s services/logic/.ephemeris/de421.bsp ]; then + curl -fSL --retry 3 --max-time 300 \ + -o services/logic/.ephemeris/de421.bsp \ + https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de421.bsp + fi + ls -lh services/logic/.ephemeris/de421.bsp + + - name: Instalacja zależności + run: pip install -r services/logic/requirements-dev.txt + + # CI=true (ustawiane przez GitHub) sprawia, że brak silnika = błąd, + # a nie pominięcie — patrz tests/conftest.py. + - name: Testy (pytest) + working-directory: services/logic + env: + PYTHONPATH: . + EPHEMERIS_DIR: ${{ github.workspace }}/services/logic/.ephemeris + run: pytest tests -q -rs + + compile-all: + name: Kontrola składni wszystkich warstw + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + # Sam kompilator — bez instalowania zależności warstw (w tym AGPL-owego + # silnika swisseph, który nie wchodzi do produktu). + - name: py_compile + run: python -m compileall -q services diff --git a/services/logic/tests/conftest.py b/services/logic/tests/conftest.py index 627c59b..f6a6b88 100644 --- a/services/logic/tests/conftest.py +++ b/services/logic/tests/conftest.py @@ -7,6 +7,7 @@ służą jako wyrocznia (LOG-25). from __future__ import annotations import datetime as dt +import os import pytest @@ -28,4 +29,8 @@ def own_engine(): try: return SkyfieldEngine() except Exception as e: # brak efemeryd / brak sieci + # Lokalnie pomijamy (dev bez pobranego jądra), ale w CI to musi być błąd — + # inaczej testy referencyjne (walidacja względem astro.com) cicho znikają. + if os.getenv("CI"): + pytest.fail(f"CI: silnik efemeryd niedostępny — testy referencyjne muszą działać: {e}") pytest.skip(f"Nie można wczytać efemeryd: {e}") diff --git a/test b/test new file mode 100644 index 0000000..e69de29