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
+12 -8
View File
@@ -1,5 +1,6 @@
import json
import os
from typing import Any
# Bibliothèque de sprites animaux CraftPix — RÉSERVÉE au rôle admin (voir
# routes/screens/screen_edit.py, routes/scenes/scene_edit_view.py, et les
@@ -13,14 +14,17 @@ import os
# les packs — pas de table figée comme _SEQUENCE_ANIMATIONS pour Kenney).
_MANIFEST_PATH = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
"static", "characters", "animals", "manifest.json",
"static",
"characters",
"animals",
"manifest.json",
)
def _load_manifest():
def _load_manifest() -> dict[str, Any]:
try:
with open(_MANIFEST_PATH, encoding="utf-8") as f:
return json.load(f)
return dict(json.load(f))
except FileNotFoundError:
# Poste de dev sans les assets animaux copiés (script pas encore
# lancé), ou paquet exporté pour un jeu qui n'utilise aucun
@@ -29,25 +33,25 @@ def _load_manifest():
return {}
def _slug(animal, nn):
def _slug(animal: str, nn: str) -> str:
return f"animal-{animal}-{nn}"
def _label(family_label, nn):
def _label(family_label: str, nn: str) -> str:
n = int(nn)
return f"{family_label} (variante {n})" if n > 1 else f"{family_label} (de base)"
def _animations_for(animal, nn, poses):
def _animations_for(animal: str, nn: str, poses: dict[str, int]) -> dict[str, list[str]]:
return {
pose: [f"/static/characters/animals/{animal}/{nn}/{pose}{i}.png" for i in range(count)]
for pose, count in poses.items()
}
def _build_library():
def _build_library() -> dict[str, dict[str, Any]]:
manifest = _load_manifest()
library = {}
library: dict[str, dict[str, Any]] = {}
for animal, pack in manifest.items():
family_label = pack["label"]
for nn, poses in pack["variants"].items():
+8 -5
View File
@@ -1,5 +1,6 @@
import json
import os
from typing import Any
# Bibliothèque d'images de fond CraftPix — RÉSERVÉE au rôle admin (voir
# core/sprite_gate.py, routes/scenes/scene_object_add.py), même règle que
@@ -14,14 +15,16 @@ import os
# modifiable ensuite comme n'importe quel objet (panneau "Position & taille").
_MANIFEST_PATH = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
"static", "backgrounds", "manifest.json",
"static",
"backgrounds",
"manifest.json",
)
def _load_manifest():
def _load_manifest() -> dict[str, Any]:
try:
with open(_MANIFEST_PATH, encoding="utf-8") as f:
return json.load(f)
return dict(json.load(f))
except FileNotFoundError:
# Poste de dev sans les images de fond copiées (script pas encore
# lancé), ou paquet exporté pour un jeu qui n'utilise aucun fond
@@ -31,9 +34,9 @@ def _load_manifest():
return {}
def _build_library():
def _build_library() -> dict[str, dict[str, Any]]:
manifest = _load_manifest()
library = {}
library: dict[str, dict[str, Any]] = {}
for pack_slug, pack in manifest.items():
pack_label = pack["label"]
for image_name, dims in pack["images"].items():
+6 -3
View File
@@ -1,4 +1,7 @@
def sprite_gallery_families(sprite_library):
from typing import Any
def sprite_gallery_families(sprite_library: dict[str, dict[str, Any]]) -> list[tuple[str, dict[str, Any]]]:
"""Un tile par FAMILLE pour la galerie d'ajout/de changement de
personnage — les personnages Kenney (pas de clé "family", voir
screens/labels/sprite_library.py) sont chacun leur propre famille ;
@@ -9,8 +12,8 @@ def sprite_gallery_families(sprite_library):
panneau de propriétés (voir render_variant_gallery, templates/
screen_edit.html) plutôt que d'encombrer cette galerie de 15 tiles
quasi identiques par animal."""
seen_families = set()
families = []
seen_families: set[str] = set()
families: list[tuple[str, dict[str, Any]]] = []
for slug, character in sprite_library.items():
family = character.get("family")
if family:
+31 -11
View File
@@ -23,22 +23,43 @@ CHARACTERS = {
# pour les 6 personnages (confirmé sur disque), donc une seule définition
# suffit pour tous.
_SEQUENCE_ANIMATIONS = {
"walk": 8, # cycle de marche
"run": 3, # course
"walk": 8, # cycle de marche
"run": 3, # course
"attack": 3, # attaque
"cheer": 2, # acclamation
"climb": 2, # escalade
"cheer": 2, # acclamation
"climb": 2, # escalade
"switch": 2, # bascule/actionner
}
_SINGLE_POSES = [
"idle", "jump", "fall", "duck", "hit", "back", "slide", "interact",
"kick", "side", "shove", "shoveBack", "talk", "attackKick", "hang",
"hold", "hurt", "behindBack", "down", "drag", "fallDown", "rope",
"show", "think", "wide",
"idle",
"jump",
"fall",
"duck",
"hit",
"back",
"slide",
"interact",
"kick",
"side",
"shove",
"shoveBack",
"talk",
"attackKick",
"hang",
"hold",
"hurt",
"behindBack",
"down",
"drag",
"fallDown",
"rope",
"show",
"think",
"wide",
]
def _animations_for(slug):
def _animations_for(slug: str) -> dict[str, list[str]]:
animations = {
name: [f"/static/characters/{slug}/{name}{i}.png" for i in range(count)]
for name, count in _SEQUENCE_ANIMATIONS.items()
@@ -54,6 +75,5 @@ def _animations_for(slug):
# screens/labels/animal_sprite_library.py et le plan "Bibliothèque de
# sprites animaux CraftPix").
PUBLIC_SPRITE_LIBRARY = {
slug: {"label": label, "animations": _animations_for(slug)}
for slug, label in CHARACTERS.items()
slug: {"label": label, "animations": _animations_for(slug)} for slug, label in CHARACTERS.items()
}