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
@@ -3,19 +3,24 @@ une ligne VIDE, dont l'id devient LAST_INSERTED_ROW_ID pour un nœud
|
||||
"Modifier une donnée" enchaîné dans le MÊME flow — verrouille le
|
||||
mécanisme complet (route -> DB -> répéteur) plutôt que juste la fonction
|
||||
Python isolée."""
|
||||
|
||||
import json
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
from flask.testing import FlaskClient
|
||||
|
||||
import db
|
||||
import screens
|
||||
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 _add_flow_node(client, slug, screen_id, **fields):
|
||||
def _add_flow_node(client: FlaskClient, slug: str, screen_id: int, **fields: Any) -> Any:
|
||||
resp = client.post(
|
||||
f"/game/{slug}/screens/{screen_id}/flow/nodes/add",
|
||||
data=json.dumps(fields),
|
||||
@@ -25,15 +30,20 @@ def _add_flow_node(client, slug, screen_id, **fields):
|
||||
return resp.get_json()["id"]
|
||||
|
||||
|
||||
def _create_inventory_object(client, slug):
|
||||
def _create_inventory_object(client: FlaskClient, slug: str) -> Any:
|
||||
return db.create_definition(slug, "Inventaire", [{"name": "objet", "type": "texte"}])
|
||||
|
||||
|
||||
def test_run_add_row_route_creates_an_empty_row(client, game):
|
||||
def test_run_add_row_route_creates_an_empty_row(client: FlaskClient, game: str) -> None:
|
||||
definition_id = _create_inventory_object(client, game)
|
||||
screen_id = _create_screen(client, game)
|
||||
node_id = _add_flow_node(
|
||||
client, game, screen_id, node_type="action", action_type="ajouter_ligne", target_definition_id=definition_id,
|
||||
client,
|
||||
game,
|
||||
screen_id,
|
||||
node_type="action",
|
||||
action_type="ajouter_ligne",
|
||||
target_definition_id=definition_id,
|
||||
)
|
||||
resp = client.post(f"/game/{game}/flow/nodes/{node_id}/run-add-row")
|
||||
assert resp.status_code == 200
|
||||
@@ -41,14 +51,14 @@ def test_run_add_row_route_creates_an_empty_row(client, game):
|
||||
assert body["ok"] is True
|
||||
assert isinstance(body["row_id"], int)
|
||||
|
||||
definition = db.get_definition(game, definition_id)
|
||||
definition = not_none(db.get_definition(game, definition_id))
|
||||
rows = db.list_rows(game, definition)
|
||||
assert len(rows) == 1
|
||||
assert rows[0]["id"] == body["row_id"]
|
||||
assert rows[0]["objet"] is None
|
||||
|
||||
|
||||
def test_run_add_row_route_rejects_wrong_action_type(client, game):
|
||||
def test_run_add_row_route_rejects_wrong_action_type(client: FlaskClient, game: str) -> None:
|
||||
screen_id = _create_screen(client, game)
|
||||
node_id = _add_flow_node(client, game, screen_id, node_type="action", action_type="attendre", data_value="1")
|
||||
resp = client.post(f"/game/{game}/flow/nodes/{node_id}/run-add-row")
|
||||
@@ -56,7 +66,7 @@ def test_run_add_row_route_rejects_wrong_action_type(client, game):
|
||||
assert resp.get_json()["ok"] is False
|
||||
|
||||
|
||||
def test_chained_ajouter_ligne_then_modifier_donnee_sets_the_new_row_fields(client, game):
|
||||
def test_chained_ajouter_ligne_then_modifier_donnee_sets_the_new_row_fields(client: FlaskClient, game: str) -> None:
|
||||
"""Le scénario réel : "Ajouter une ligne" crée une ligne vide, puis un
|
||||
"Modifier une donnée" ciblant LAST_INSERTED_ROW_ID (transmis par le
|
||||
client via last_inserted_row_id, voir static/js/play/actions.js) la
|
||||
@@ -64,12 +74,24 @@ def test_chained_ajouter_ligne_then_modifier_donnee_sets_the_new_row_fields(clie
|
||||
definition_id = _create_inventory_object(client, game)
|
||||
screen_id = _create_screen(client, game)
|
||||
add_node_id = _add_flow_node(
|
||||
client, game, screen_id, node_type="action", action_type="ajouter_ligne", target_definition_id=definition_id,
|
||||
client,
|
||||
game,
|
||||
screen_id,
|
||||
node_type="action",
|
||||
action_type="ajouter_ligne",
|
||||
target_definition_id=definition_id,
|
||||
)
|
||||
set_node_id = _add_flow_node(
|
||||
client, game, screen_id, node_type="action", action_type="modifier_donnee",
|
||||
target_definition_id=definition_id, target_row_id=screens.LAST_INSERTED_ROW_ID,
|
||||
target_field="objet", data_operation="definir_texte", data_value="épée",
|
||||
client,
|
||||
game,
|
||||
screen_id,
|
||||
node_type="action",
|
||||
action_type="modifier_donnee",
|
||||
target_definition_id=definition_id,
|
||||
target_row_id=screens.LAST_INSERTED_ROW_ID,
|
||||
target_field="objet",
|
||||
data_operation="definir_texte",
|
||||
data_value="épée",
|
||||
)
|
||||
|
||||
add_resp = client.post(f"/game/{game}/flow/nodes/{add_node_id}/run-add-row")
|
||||
@@ -82,8 +104,6 @@ def test_chained_ajouter_ligne_then_modifier_donnee_sets_the_new_row_fields(clie
|
||||
)
|
||||
assert set_resp.get_json()["ok"] is True
|
||||
|
||||
definition = db.get_definition(game, definition_id)
|
||||
row = db.get_row(game, definition, new_row_id)
|
||||
definition = not_none(db.get_definition(game, definition_id))
|
||||
row = not_none(db.get_row(game, definition, new_row_id))
|
||||
assert row["objet"] == "épée"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user