From d4b02a76c655fda86d7e0a4890f81d4c3789ac61 Mon Sep 17 00:00:00 2001 From: Imugiii Date: Tue, 16 Jun 2026 10:40:09 +0000 Subject: [PATCH] ci: run DB integration tests against an ephemeral MariaDB service Avant ce commit, le job static-tests lancait phpunit sans base ni WAKDO_DB_TESTS=1 : les 7 tests d'integration tests/Integration/*DbTest s'auto-skippaient (13 skips), et le SQL porteur de securite n'etait valide par AUCUN test en CI -- upsert atomique du throttle (login + PIN), predicat RBAC AND r.is_active=1, audit_log dans la meme transaction, FK RESTRICT/CASCADE. Une regression dans ce SQL passait la CI au vert (le double FakeDatabase n'execute pas le SQL). Ce commit provisionne un service MariaDB 11.4 ephemere, applique le schema (db/migrations) puis le seed (db/seeds), et lance phpunit avec WAKDO_DB_TESTS=1 + DB_*, ajoute le pilote pdo_mysql (php-mysql) et le client mariadb. L'option --fail-on-skipped garantit qu'un skip silencieux d'un *DbTest fait desormais echouer la CI au lieu de la laisser verte. Recette validee localement sur une MariaDB 11.4 vierge : migrations + seeds appliques proprement (22 tables, 5 roles, 53 produits), phpunit = 188 tests / 525 assertions / 0 skip / 0 echec (vs 188 / 448 / 13 skip sans base). --- .forgejo/workflows/ci.yml | 53 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index b2a6530..02ddf7a 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -61,9 +61,32 @@ jobs: # COMPOSER-LESS (decision 4 / 5, PROJECT_CONTEXT.md) : PHPStan et PHPUnit # tournent depuis leur .phar autonome telecharge ici, jamais via Composer. # Versions epinglees pour des CI reproductibles (pas de "latest"). + # + # Service MariaDB ephemere : le schema (db/migrations) et le seed (db/seeds) + # y sont appliques, puis PHPUnit tourne avec WAKDO_DB_TESTS=1 pour que les + # tests d'integration (tests/Integration/*DbTest) s'executent REELLEMENT. + # Sans base, ils s'auto-skippent et le SQL porteur de securite (throttle, + # RBAC is_active, audit in-transaction, FK) n'est jamais valide en CI. + # Identifiants ci-dessous : ephemeres, CI uniquement, jamais des secrets. + services: + mariadb: + image: mariadb:11.4 + env: + MARIADB_ROOT_PASSWORD: root + MARIADB_DATABASE: wakdo_test + MARIADB_USER: wakdo + MARIADB_PASSWORD: wakdo env: PHPUNIT_VERSION: "11.5.2" PHPSTAN_VERSION: "1.12.27" + # Connexion des tests d'integration au service `mariadb` ci-dessus + # (Database lit ces DB_* via getenv ; cf. src/app/Core/Database.php). + WAKDO_DB_TESTS: "1" + DB_HOST: mariadb + DB_PORT: "3306" + DB_NAME: wakdo_test + DB_USER: wakdo + DB_PASSWORD: wakdo steps: - uses: actions/checkout@v4 - name: PHPStan (guarded) @@ -82,7 +105,7 @@ jobs: php phpstan.phar --version # memory_limit=-1 : l'analyse parallele depasse les 128M par defaut du php-cli. php -d memory_limit=-1 phpstan.phar analyse --no-progress --error-format=raw - - name: PHPUnit (guarded) + - name: PHPUnit (guarded, avec tests d'integration DB) run: | set -eu if [ ! -d tests ] || [ ! -f phpunit.xml ]; then @@ -90,10 +113,34 @@ jobs: exit 0 fi echo "phpunit.xml + tests/ detected - running PHPUnit ${PHPUNIT_VERSION} via .phar" - apt-get update -qq && apt-get install -y -qq php-cli php-xml php-mbstring curl ca-certificates >/dev/null + # php-mysql = pilote pdo_mysql requis par les *DbTest ; mariadb-client + # pour appliquer schema + seed au service mariadb. + apt-get update -qq && apt-get install -y -qq php-cli php-xml php-mbstring php-mysql mariadb-client curl ca-certificates >/dev/null + # Attente active que le service MariaDB reponde (en plus du lien de service). + echo "Attente du service MariaDB ${DB_HOST}:${DB_PORT} ..." + ready=0 + for i in $(seq 1 30); do + if mariadb -h"${DB_HOST}" -P"${DB_PORT}" -u"${DB_USER}" -p"${DB_PASSWORD}" -e "SELECT 1" "${DB_NAME}" >/dev/null 2>&1; then + echo "MariaDB pret (tentative ${i})."; ready=1; break + fi + sleep 2 + done + [ "${ready}" = 1 ] || { echo "ERREUR: MariaDB injoignable apres 60s"; exit 1; } + # Schema (db/migrations) puis seed (db/seeds), ordre lexicographique. + for f in db/migrations/*.sql; do + echo "migrate $(basename "$f")" + mariadb -h"${DB_HOST}" -P"${DB_PORT}" -u"${DB_USER}" -p"${DB_PASSWORD}" "${DB_NAME}" < "$f" + done + for f in db/seeds/*.sql; do + echo "seed $(basename "$f")" + mariadb -h"${DB_HOST}" -P"${DB_PORT}" -u"${DB_USER}" -p"${DB_PASSWORD}" "${DB_NAME}" < "$f" + done curl -sSL "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" -o phpunit.phar php phpunit.phar --version - php phpunit.phar -c phpunit.xml + # --fail-on-skipped : si un *DbTest s'auto-skippe (base injoignable), la + # CI echoue au lieu de masquer le trou derriere un vert. C'est le coeur + # du correctif : plus aucun skip silencieux des chemins securite. + php phpunit.phar -c phpunit.xml --fail-on-skipped auto-merge: # Fusion automatique OPT-IN : poser le label `auto-merge` sur la PR. -- 2.45.3