Files
romm/.github/workflows/pytest.yml
Georges-Antoine Assi 2e90022dea fix(db): make virtual_collections and generated columns collation-agnostic
A MariaDB server configured with --character-set-server=utf8 makes the roms
table, string literals and JSON_TABLE columns utf8mb3, which breaks three
places that a default utf8mb4 server accepts:

- 0096/0101 pin `COLLATE utf8mb4_general_ci` on view output columns. An
  explicit utf8mb4 collation on a utf8mb3 value is rejected outright, so
  upgrading fails with "COLLATION 'utf8mb4_general_ci' is not valid for
  CHARACTER SET 'utf8mb3'". Each operand now goes through CONVERT(... USING
  utf8mb4) first, keeping the strong coercibility that 3758 needed.
- 0098 compares JSON_UNQUOTE output against string literals in NOT IN, REGEXP
  and NULLIF. JSON_UNQUOTE resolves under the connection charset while a
  literal in a generated-column expression takes the table's collation, so the
  two are an illegal mix. All of them now route through _maria_text, which
  wraps the value in CAST(... AS CHAR).

CI only ever exercised the default collation, so none of this was visible. The
migrations workflow now runs MariaDB as a matrix over utf8mb4_general_ci and
utf8mb3_unicode_ci. Service containers take docker create options and cannot
pass --character-set-server, so the server is started from a step instead.

MariaDB moves to 11.3.2 everywhere in CI, matching docker-compose. That image
dropped the mysqladmin symlink, so the service health checks move to the
image's own healthcheck.sh.

Verified on mariadb:11.3.2: alembic upgrade head reaches head under both
collations, and the generated_* columns and virtual_collections rows are
identical between them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 08:46:38 -04:00

100 lines
3.1 KiB
YAML

name: Run Pytest
on:
pull_request:
paths:
- "backend/**"
- ".github/workflows/pytest.yml"
- pyproject.toml
- uv.lock
- .python-version
push:
branches:
- "master"
paths:
- "backend/**"
- ".github/workflows/pytest.yml"
- pyproject.toml
- uv.lock
- .python-version
permissions: read-all
jobs:
pytest:
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
strategy:
fail-fast: false
matrix:
db: [mariadb, postgresql]
services:
mariadb:
image: mariadb:11.3.2
ports:
- 3306
env:
MYSQL_USER: romm_test
MYSQL_PASSWORD: passwd
MYSQL_DATABASE: romm_test
MYSQL_ROOT_PASSWORD: passwd
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=5s --health-timeout=2s --health-retries=3
postgresql:
image: postgres:16
ports:
- 5432
env:
POSTGRES_USER: romm_test
POSTGRES_PASSWORD: passwd
POSTGRES_DB: romm_test
options: --health-cmd="pg_isready" --health-interval=5s --health-timeout=2s --health-retries=3
valkey:
image: valkey/valkey:7.2
ports:
- 6379
options: >-
--health-cmd="redis-cli ping" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install mariadb connectors
run: |
sudo apt-get update
sudo apt-get install -y libmariadb3 libmariadb-dev 7zip
- name: Install uv
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
- name: Install python
run: |
uv python install
- name: Install dependencies
run: |
uv sync --extra test
- name: Initiate MariaDB database
if: matrix.db == 'mariadb'
run: |
# Grant on the `romm_test%` namespace so the test user can create the
# per-worker databases (romm_test_gw0, ...) used under pytest-xdist,
# without granting it global privileges. The backticks are escaped so
# the shell doesn't treat them as command substitution.
mysql --host 127.0.0.1 --port ${{ job.services.mariadb.ports['3306'] }} -uroot -ppasswd -e "GRANT ALL PRIVILEGES ON \`romm\_test%\`.* TO 'romm_test'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;"
- name: Run python tests
env:
DB_HOST: 127.0.0.1
DB_PORT: ${{ matrix.db == 'mariadb' && job.services.mariadb.ports['3306'] || job.services.postgresql.ports['5432'] }}
ROMM_DB_DRIVER: ${{ matrix.db }}
REDIS_HOST: 127.0.0.1
REDIS_PORT: ${{ job.services.valkey.ports['6379'] }}
HYPOTHESIS_PROFILE: ci
run: |
cd backend
# GitHub-hosted Linux runners have 4 vCPUs; run one worker per core.
uv run pytest -n 4 -vv --maxfail=10 --junitxml=pytest-report.xml --cov --cov-report xml:coverage.xml --cov-config=.coveragerc .