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
@@ -7,43 +7,56 @@ EXACTEMENT son comportement d'avant (une seule comparaison) — c'est ce que
|
||||
vérifient les tests de non-régression ci-dessous, en plus des tests dédiés
|
||||
à la nouvelle fonctionnalité.
|
||||
"""
|
||||
|
||||
import json
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
from conftest import play_js_bundle # type: ignore[import-not-found] # resolu par pytest, pas mypy
|
||||
from flask.testing import FlaskClient
|
||||
|
||||
import db
|
||||
|
||||
from conftest import play_js_bundle
|
||||
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 _create_object_two_fields(client, slug):
|
||||
def _create_object_two_fields(client: FlaskClient, slug: str) -> Any:
|
||||
"""Crée un objet "Partie" avec deux champs numériques et une ligne."""
|
||||
def_id = db.create_definition(slug, "Partie", [
|
||||
{"name": "reputation", "type": "nombre_entier"},
|
||||
{"name": "niveau", "type": "nombre_entier"},
|
||||
])
|
||||
definition = db.get_definition(slug, def_id)
|
||||
def_id = db.create_definition(
|
||||
slug,
|
||||
"Partie",
|
||||
[
|
||||
{"name": "reputation", "type": "nombre_entier"},
|
||||
{"name": "niveau", "type": "nombre_entier"},
|
||||
],
|
||||
)
|
||||
definition = not_none(db.get_definition(slug, def_id))
|
||||
db.insert_row(slug, definition, {"reputation": "5", "niveau": "3"})
|
||||
return def_id
|
||||
|
||||
|
||||
def test_legacy_single_clause_condition_still_works_without_cond_clauses(client, game):
|
||||
def test_legacy_single_clause_condition_still_works_without_cond_clauses(client: FlaskClient, game: str) -> None:
|
||||
"""Non-régression : un nœud Condition créé SANS cond_clauses (comme avant
|
||||
2.4) doit toujours fonctionner à l'identique."""
|
||||
screen_id = _create_screen(client, game)
|
||||
def_id = _create_object_two_fields(client, game)
|
||||
resp = client.post(
|
||||
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
|
||||
data=json.dumps({
|
||||
"node_type": "condition",
|
||||
"cond_definition_id": def_id, "cond_row_id": 1,
|
||||
"cond_field": "reputation", "cond_field_type": "nombre_entier",
|
||||
"cond_operator": "superieur", "cond_value": "10",
|
||||
}),
|
||||
data=json.dumps(
|
||||
{
|
||||
"node_type": "condition",
|
||||
"cond_definition_id": def_id,
|
||||
"cond_row_id": 1,
|
||||
"cond_field": "reputation",
|
||||
"cond_field_type": "nombre_entier",
|
||||
"cond_operator": "superieur",
|
||||
"cond_value": "10",
|
||||
}
|
||||
),
|
||||
content_type="application/json",
|
||||
)
|
||||
node = resp.get_json()
|
||||
@@ -53,22 +66,42 @@ def test_legacy_single_clause_condition_still_works_without_cond_clauses(client,
|
||||
assert "cond_clauses" in js
|
||||
|
||||
|
||||
def test_condition_node_persists_clauses_and_combinator(client, game):
|
||||
def test_condition_node_persists_clauses_and_combinator(client: FlaskClient, game: str) -> None:
|
||||
screen_id = _create_screen(client, game)
|
||||
def_id = _create_object_two_fields(client, game)
|
||||
clauses = [
|
||||
{"definition_id": def_id, "row_id": 1, "field": "reputation", "field_type": "nombre_entier", "operator": "inferieur", "value": "20"},
|
||||
{"definition_id": def_id, "row_id": 1, "field": "niveau", "field_type": "nombre_entier", "operator": "superieur_egal", "value": "3"},
|
||||
{
|
||||
"definition_id": def_id,
|
||||
"row_id": 1,
|
||||
"field": "reputation",
|
||||
"field_type": "nombre_entier",
|
||||
"operator": "inferieur",
|
||||
"value": "20",
|
||||
},
|
||||
{
|
||||
"definition_id": def_id,
|
||||
"row_id": 1,
|
||||
"field": "niveau",
|
||||
"field_type": "nombre_entier",
|
||||
"operator": "superieur_egal",
|
||||
"value": "3",
|
||||
},
|
||||
]
|
||||
resp = client.post(
|
||||
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
|
||||
data=json.dumps({
|
||||
"node_type": "condition",
|
||||
"cond_definition_id": def_id, "cond_row_id": 1,
|
||||
"cond_field": "reputation", "cond_field_type": "nombre_entier",
|
||||
"cond_operator": "inferieur", "cond_value": "20",
|
||||
"cond_clauses": json.dumps(clauses), "cond_combinator": "ou",
|
||||
}),
|
||||
data=json.dumps(
|
||||
{
|
||||
"node_type": "condition",
|
||||
"cond_definition_id": def_id,
|
||||
"cond_row_id": 1,
|
||||
"cond_field": "reputation",
|
||||
"cond_field_type": "nombre_entier",
|
||||
"cond_operator": "inferieur",
|
||||
"cond_value": "20",
|
||||
"cond_clauses": json.dumps(clauses),
|
||||
"cond_combinator": "ou",
|
||||
}
|
||||
),
|
||||
content_type="application/json",
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
@@ -80,26 +113,31 @@ def test_condition_node_persists_clauses_and_combinator(client, game):
|
||||
assert stored_clauses[1]["field"] == "niveau"
|
||||
|
||||
|
||||
def test_condition_combinator_defaults_to_et_when_absent(client, game):
|
||||
def test_condition_combinator_defaults_to_et_when_absent(client: FlaskClient, game: str) -> None:
|
||||
"""cond_combinator a une valeur par défaut 'et' en base même si on ne la
|
||||
précise jamais (jeux migrés depuis avant 2.4)."""
|
||||
screen_id = _create_screen(client, game)
|
||||
def_id = _create_object_two_fields(client, game)
|
||||
resp = client.post(
|
||||
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
|
||||
data=json.dumps({
|
||||
"node_type": "condition",
|
||||
"cond_definition_id": def_id, "cond_row_id": 1,
|
||||
"cond_field": "reputation", "cond_field_type": "nombre_entier",
|
||||
"cond_operator": "superieur", "cond_value": "10",
|
||||
}),
|
||||
data=json.dumps(
|
||||
{
|
||||
"node_type": "condition",
|
||||
"cond_definition_id": def_id,
|
||||
"cond_row_id": 1,
|
||||
"cond_field": "reputation",
|
||||
"cond_field_type": "nombre_entier",
|
||||
"cond_operator": "superieur",
|
||||
"cond_value": "10",
|
||||
}
|
||||
),
|
||||
content_type="application/json",
|
||||
)
|
||||
node = resp.get_json()
|
||||
assert node["cond_combinator"] == "et"
|
||||
|
||||
|
||||
def test_play_page_exposes_combinator_logic(client, game):
|
||||
def test_play_page_exposes_combinator_logic(client: FlaskClient, game: str) -> None:
|
||||
js = play_js_bundle()
|
||||
assert "cond_combinator" in js
|
||||
assert "'ou'" in js
|
||||
|
||||
Reference in New Issue
Block a user