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:
co-authored by
Claude Sonnet 5
parent
7db4803b93
commit
c57420c8c9
+24
-16
@@ -4,16 +4,19 @@ quoi que ce soit — désormais un seul type, "rpg" (jeu RPG 2D), les types
|
||||
Quiz/Embranchement/"Créer mon jeu de A à Z" ayant été retirés avec le
|
||||
moteur d'écran "document". Réutilise les fixtures de test_auth.py
|
||||
(inscription/2FA)."""
|
||||
|
||||
import os
|
||||
|
||||
from flask.testing import FlaskClient
|
||||
|
||||
import auth
|
||||
import db
|
||||
import screens
|
||||
|
||||
from tests.test_auth import _register, _confirm_2fa, _complete_onboarding, _cleanup_project, anon_client # noqa: F401
|
||||
from tests.conftest import not_none
|
||||
from tests.test_auth import _cleanup_project, _complete_onboarding, _confirm_2fa, _register, anon_client # noqa: F401
|
||||
|
||||
|
||||
def test_account_without_a_project_is_redirected_to_onboarding(anon_client):
|
||||
def test_account_without_a_project_is_redirected_to_onboarding(anon_client: FlaskClient) -> None: # noqa: F811 - anon_client est un fixture pytest (voir tests.test_auth), pas une vraie redefinition - pyflakes ne comprend pas l'injection de fixture par parametre
|
||||
_register(anon_client, "needsonboarding@example.com")
|
||||
_confirm_2fa(anon_client)
|
||||
try:
|
||||
@@ -28,13 +31,13 @@ def test_account_without_a_project_is_redirected_to_onboarding(anon_client):
|
||||
_cleanup_project("needsonboarding@example.com")
|
||||
|
||||
|
||||
def test_rpg_dashboard_shows_scene_preview_and_forces_jeu2d_on_new_screens(anon_client):
|
||||
def test_rpg_dashboard_shows_scene_preview_and_forces_jeu2d_on_new_screens(anon_client: FlaskClient) -> None: # noqa: F811 - anon_client est un fixture pytest (voir tests.test_auth), pas une vraie redefinition - pyflakes ne comprend pas l'injection de fixture par parametre
|
||||
_register(anon_client, "rpguser@example.com")
|
||||
_confirm_2fa(anon_client)
|
||||
try:
|
||||
resp = _complete_onboarding(anon_client, name="Mon RPG", onboarding_type="rpg")
|
||||
assert resp.status_code == 302
|
||||
slug = auth.get_user_by_email("rpguser@example.com")["project_slug"]
|
||||
slug = not_none(auth.get_user_by_email("rpguser@example.com"))["project_slug"]
|
||||
assert resp.headers["Location"] == f"/game/{slug}"
|
||||
assert db.get_onboarding_type(slug) == "rpg"
|
||||
screen_list = screens.list_screens(slug)
|
||||
@@ -48,7 +51,9 @@ def test_rpg_dashboard_shows_scene_preview_and_forces_jeu2d_on_new_screens(anon_
|
||||
# "+ Ajouter un écran" ne propose pas de choix de type — imposé
|
||||
# jeu_2d par le projet, même en tentant de forcer "document" via
|
||||
# un POST direct (défense en profondeur, pas seulement l'UI).
|
||||
anon_client.post(f"/game/{slug}/screens/new", data={"name": "Scène 2", "kind": "document"}, follow_redirects=False)
|
||||
anon_client.post(
|
||||
f"/game/{slug}/screens/new", data={"name": "Scène 2", "kind": "document"}, follow_redirects=False
|
||||
)
|
||||
new_screen_list = screens.list_screens(slug)
|
||||
assert len(new_screen_list) == 2
|
||||
assert new_screen_list[1]["kind"] == "jeu_2d"
|
||||
@@ -59,18 +64,18 @@ def test_rpg_dashboard_shows_scene_preview_and_forces_jeu2d_on_new_screens(anon_
|
||||
_cleanup_project("rpguser@example.com")
|
||||
|
||||
|
||||
def test_onboarding_rejects_unknown_type(anon_client):
|
||||
def test_onboarding_rejects_unknown_type(anon_client: FlaskClient) -> None: # noqa: F811 - anon_client est un fixture pytest (voir tests.test_auth), pas une vraie redefinition - pyflakes ne comprend pas l'injection de fixture par parametre
|
||||
_register(anon_client, "badtype@example.com")
|
||||
_confirm_2fa(anon_client)
|
||||
try:
|
||||
resp = anon_client.post("/onboarding", data={"onboarding_type": "n_importe_quoi", "name": "Test"})
|
||||
assert resp.status_code == 200
|
||||
assert auth.get_user_by_email("badtype@example.com")["project_slug"] is None
|
||||
assert not_none(auth.get_user_by_email("badtype@example.com"))["project_slug"] is None
|
||||
finally:
|
||||
_cleanup_project("badtype@example.com")
|
||||
|
||||
|
||||
def test_onboarding_rejects_removed_types(anon_client):
|
||||
def test_onboarding_rejects_removed_types(anon_client: FlaskClient) -> None: # noqa: F811 - anon_client est un fixture pytest (voir tests.test_auth), pas une vraie redefinition - pyflakes ne comprend pas l'injection de fixture par parametre
|
||||
"""Les anciens types (quiz/embranchement/custom) ne sont plus des choix
|
||||
valides — voir db/games/game_type_catalog.py, ONBOARDING_TYPES ne
|
||||
contient plus que "rpg"."""
|
||||
@@ -80,35 +85,37 @@ def test_onboarding_rejects_removed_types(anon_client):
|
||||
for removed_type in ("quiz", "embranchement", "custom"):
|
||||
resp = anon_client.post("/onboarding", data={"onboarding_type": removed_type, "name": "Test"})
|
||||
assert resp.status_code == 200
|
||||
assert auth.get_user_by_email("removedtype@example.com")["project_slug"] is None
|
||||
assert not_none(auth.get_user_by_email("removedtype@example.com"))["project_slug"] is None
|
||||
finally:
|
||||
_cleanup_project("removedtype@example.com")
|
||||
|
||||
|
||||
def test_revisiting_onboarding_after_completion_redirects_without_recreating(anon_client):
|
||||
def test_revisiting_onboarding_after_completion_redirects_without_recreating(anon_client: FlaskClient) -> None: # noqa: F811 - anon_client est un fixture pytest (voir tests.test_auth), pas une vraie redefinition - pyflakes ne comprend pas l'injection de fixture par parametre
|
||||
_register(anon_client, "revisit@example.com")
|
||||
_confirm_2fa(anon_client)
|
||||
try:
|
||||
first = _complete_onboarding(anon_client, name="Premier jeu", onboarding_type="rpg")
|
||||
first_slug = auth.get_user_by_email("revisit@example.com")["project_slug"]
|
||||
first_slug = not_none(auth.get_user_by_email("revisit@example.com"))["project_slug"]
|
||||
|
||||
resp = anon_client.get("/onboarding", follow_redirects=False)
|
||||
assert resp.status_code == 302
|
||||
assert resp.headers["Location"] == first.headers["Location"]
|
||||
|
||||
again = anon_client.post("/onboarding", data={"onboarding_type": "rpg", "name": "Second jeu"}, follow_redirects=False)
|
||||
assert auth.get_user_by_email("revisit@example.com")["project_slug"] == first_slug
|
||||
again = anon_client.post(
|
||||
"/onboarding", data={"onboarding_type": "rpg", "name": "Second jeu"}, follow_redirects=False
|
||||
)
|
||||
assert not_none(auth.get_user_by_email("revisit@example.com"))["project_slug"] == first_slug
|
||||
assert again.headers["Location"] == first.headers["Location"]
|
||||
finally:
|
||||
_cleanup_project("revisit@example.com")
|
||||
|
||||
|
||||
def test_admin_is_never_redirected_to_onboarding(client, game):
|
||||
def test_admin_is_never_redirected_to_onboarding(client: FlaskClient, game: str) -> None:
|
||||
resp = client.get("/", follow_redirects=False)
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
def test_admin_can_create_several_games_via_onboarding(client):
|
||||
def test_admin_can_create_several_games_via_onboarding(client: FlaskClient) -> None:
|
||||
"""Comportement systématique à CHAQUE création de jeu, pas une
|
||||
formalité réservée à la toute première inscription (voir le plan) —
|
||||
un admin, illimité (pas de project_slug dédié), doit pouvoir repasser
|
||||
@@ -133,6 +140,7 @@ def test_admin_can_create_several_games_via_onboarding(client):
|
||||
assert slug2 != slug1
|
||||
|
||||
import tests.conftest as conftest_module
|
||||
|
||||
slugs = {g["slug"] for g in db.list_games(str(conftest_module._TEST_ADMIN_ID))}
|
||||
assert slug1 in slugs
|
||||
assert slug2 in slugs
|
||||
|
||||
Reference in New Issue
Block a user