Phase 3 : hardening qualite de code - typage strict, securite, dead code, a11y

Config strictement stricte partout (ruff, mypy --strict, bandit, vulture,
import-linter, eslint, stylelint), aucune regle desactivee "pour ne pas
casser le build" - l'existant a ete corrige pour la satisfaire plutot que
l'inverse. Hooks pre-commit locaux (language: system) bloquants.

- Typage mypy --strict propage a tout le moteur (db, screens, auth, core,
  ai, routes, puis publish/scripts/tests/app.py/build_css.py).
- Securite : fuite de handle fichier Windows corrigee dans l'export SCORM
  (routes/publish/export_scorm.py), CSRF/RNG non-crypto/xAPI documentes
  (# nosec, # NOSONAR justifies), nouveau db.json_for_script() (echappe
  "</script>" dans le JSON embarque en <script>, 25 sites).
- Architecture : imports circulaires/F811 nettoyes, contrats
  import-linter respectes, code mort retire (vulture).
- Accessibilite : 69 champs de formulaire sans label correctement
  associe corriges (for/id ou aria-label) sur 11 templates.
- ESLint/Stylelint : lot mecanique JS/CSS, regles ajustees puis
  appliquees (aucune desactivee sans verification individuelle).
- Tests : isolation du compte admin partage (nettoyage ponctuel +
  fixture de teardown automatique en filet de securite), suite complete
  verte (591 tests Python, 241 tests JS).
- SonarQube Community Build self-heberge (Docker + PostgreSQL) : rapport
  complet analyse point par point, faux positifs documentes.
- .gitattributes ajoute (LF force) : core.autocrlf=true sur cette machine
  faisait echouer ESLint (linebreak-style) via un bug connu de git
  (checkout "en place" qui ignore l'eol force sur un fichier deja
  present sur disque - contourne en supprimant puis recreant chaque
  fichier suivi).

djLint (H021, styles inline) volontairement saute pour ce commit -
backlog assume, deja documente, traite dans un lot separe.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
william
2026-09-15 16:06:15 +02:00
co-authored by Claude Sonnet 5
parent 7db4803b93
commit c57420c8c9
454 changed files with 16448 additions and 6967 deletions
+28 -13
View File
@@ -4,17 +4,22 @@ pour le même patron) sur les fonctions déjà existantes de db/global_vars/
(list/create/update/delete). Le nom est la clé stable lue par
static/js/play/conditions.js::readVariableValue — jamais modifiable après
création (voir db/global_vars/update_global_variable.py)."""
import re
from typing import Any
from flask.testing import FlaskClient
import db
from tests.conftest import not_none
def _create_screen(client, slug, name="Accueil"):
def _create_screen(client: FlaskClient, slug: str, name: str = "Accueil") -> Any:
resp = client.post(f"/game/{slug}/screens/new", data={"name": name}, follow_redirects=False)
return int(re.search(r"/screens/(\d+)/edit", resp.headers["Location"]).group(1))
return int(not_none(re.search(r"/screens/(\d+)/edit", resp.headers["Location"])).group(1))
def test_create_global_var_route_persists_and_redirects_to_the_variables_tab(client, game):
def test_create_global_var_route_persists_and_redirects_to_the_variables_tab(client: FlaskClient, game: str) -> None:
screen_id = _create_screen(client, game)
resp = client.post(
f"/game/{game}/variables/new",
@@ -29,16 +34,19 @@ def test_create_global_var_route_persists_and_redirects_to_the_variables_tab(cli
assert variables[0]["value"] == "0"
def test_create_global_var_is_idempotent_by_name(client, game):
def test_create_global_var_is_idempotent_by_name(client: FlaskClient, game: str) -> None:
screen_id = _create_screen(client, game)
client.post(f"/game/{game}/variables/new", data={"name": "score_total", "screen_id": screen_id})
client.post(f"/game/{game}/variables/new", data={"name": "score_total", "screen_id": screen_id})
assert len(db.list_global_variables(game)) == 1
def test_global_var_edit_route_updates_type_and_value(client, game):
def test_global_var_edit_route_updates_type_and_value(client: FlaskClient, game: str) -> None:
screen_id = _create_screen(client, game)
client.post(f"/game/{game}/variables/new", data={"name": "score_total", "type": "nombre_entier", "default_value": "0", "screen_id": screen_id})
client.post(
f"/game/{game}/variables/new",
data={"name": "score_total", "type": "nombre_entier", "default_value": "0", "screen_id": screen_id},
)
var_id = db.list_global_variables(game)[0]["id"]
resp = client.post(
@@ -54,7 +62,7 @@ def test_global_var_edit_route_updates_type_and_value(client, game):
assert variable["name"] == "score_total" # le nom ne change jamais
def test_global_var_delete_route_removes_it(client, game):
def test_global_var_delete_route_removes_it(client: FlaskClient, game: str) -> None:
screen_id = _create_screen(client, game)
client.post(f"/game/{game}/variables/new", data={"name": "score_total", "screen_id": screen_id})
var_id = db.list_global_variables(game)[0]["id"]
@@ -65,9 +73,12 @@ def test_global_var_delete_route_removes_it(client, game):
assert db.list_global_variables(game) == []
def test_variables_tab_lists_existing_variables_in_the_scene_edit_page(client, game):
def test_variables_tab_lists_existing_variables_in_the_scene_edit_page(client: FlaskClient, game: str) -> None:
screen_id = _create_screen(client, game)
client.post(f"/game/{game}/variables/new", data={"name": "score_total", "type": "nombre_entier", "default_value": "5", "screen_id": screen_id})
client.post(
f"/game/{game}/variables/new",
data={"name": "score_total", "type": "nombre_entier", "default_value": "5", "screen_id": screen_id},
)
html = client.get(f"/game/{game}/screens/{screen_id}/edit").get_data(as_text=True)
assert "score_total" in html
@@ -78,7 +89,8 @@ def test_variables_tab_lists_existing_variables_in_the_scene_edit_page(client, g
# demande explicite : plus de rechargement de page pour créer/modifier/
# supprimer une variable. ----------
def test_create_global_var_ajax_returns_the_row_html_without_redirecting(client, game):
def test_create_global_var_ajax_returns_the_row_html_without_redirecting(client: FlaskClient, game: str) -> None:
screen_id = _create_screen(client, game)
resp = client.post(
f"/game/{game}/variables/new",
@@ -92,9 +104,12 @@ def test_create_global_var_ajax_returns_the_row_html_without_redirecting(client,
assert 'data-var-row="' in body["row_html"]
def test_global_var_edit_ajax_returns_ok_without_redirecting(client, game):
def test_global_var_edit_ajax_returns_ok_without_redirecting(client: FlaskClient, game: str) -> None:
screen_id = _create_screen(client, game)
client.post(f"/game/{game}/variables/new", data={"name": "score_total", "type": "nombre_entier", "default_value": "0", "screen_id": screen_id})
client.post(
f"/game/{game}/variables/new",
data={"name": "score_total", "type": "nombre_entier", "default_value": "0", "screen_id": screen_id},
)
var_id = db.list_global_variables(game)[0]["id"]
resp = client.post(
@@ -107,7 +122,7 @@ def test_global_var_edit_ajax_returns_ok_without_redirecting(client, game):
assert db.list_global_variables(game)[0]["value"] == "beaucoup"
def test_global_var_delete_ajax_returns_ok_without_redirecting(client, game):
def test_global_var_delete_ajax_returns_ok_without_redirecting(client: FlaskClient, game: str) -> None:
screen_id = _create_screen(client, game)
client.post(f"/game/{game}/variables/new", data={"name": "score_total", "screen_id": screen_id})
var_id = db.list_global_variables(game)[0]["id"]