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
@@ -4,35 +4,46 @@ Répéteur sur laquelle on vient de cliquer" plutôt qu'une ligne fixe -
|
||||
indispensable quand le déclencheur "Au clic" est posé sur un Répéteur,
|
||||
puisque chaque ligne exécute le même graphe et la ligne cliquée n'est
|
||||
jamais connue à l'avance dans l'éditeur."""
|
||||
|
||||
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 _create_email_object(client, slug):
|
||||
def _create_email_object(client: FlaskClient, slug: str) -> Any:
|
||||
def_id = db.create_definition(slug, "Email", [{"name": "is_opened", "type": "booleen"}])
|
||||
definition = db.get_definition(slug, def_id)
|
||||
definition = not_none(db.get_definition(slug, def_id))
|
||||
db.insert_row(slug, definition, {})
|
||||
db.insert_row(slug, definition, {})
|
||||
return def_id
|
||||
|
||||
|
||||
def test_modifier_donnee_targeting_clicked_row_updates_only_that_row(client, game):
|
||||
def test_modifier_donnee_targeting_clicked_row_updates_only_that_row(client: FlaskClient, game: str) -> None:
|
||||
def_id = _create_email_object(client, game)
|
||||
screen_id = _create_screen(client, game)
|
||||
resp = client.post(
|
||||
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
|
||||
data=json.dumps({
|
||||
"node_type": "action", "action_type": "modifier_donnee",
|
||||
"target_definition_id": def_id, "target_row_id": -1, "target_field": "is_opened",
|
||||
"data_operation": "definir_bool_vrai", "data_value": "",
|
||||
}),
|
||||
data=json.dumps(
|
||||
{
|
||||
"node_type": "action",
|
||||
"action_type": "modifier_donnee",
|
||||
"target_definition_id": def_id,
|
||||
"target_row_id": -1,
|
||||
"target_field": "is_opened",
|
||||
"data_operation": "definir_bool_vrai",
|
||||
"data_value": "",
|
||||
}
|
||||
),
|
||||
content_type="application/json",
|
||||
)
|
||||
node = resp.get_json()
|
||||
@@ -45,54 +56,72 @@ def test_modifier_donnee_targeting_clicked_row_updates_only_that_row(client, gam
|
||||
)
|
||||
assert resp.get_json() == {"ok": True}
|
||||
|
||||
definition = db.get_definition(game, def_id)
|
||||
row1 = db.get_row(game, definition, 1)
|
||||
row2 = db.get_row(game, definition, 2)
|
||||
definition = not_none(db.get_definition(game, def_id))
|
||||
row1 = not_none(db.get_row(game, definition, 1))
|
||||
row2 = not_none(db.get_row(game, definition, 2))
|
||||
assert not row1["is_opened"]
|
||||
assert row2["is_opened"]
|
||||
|
||||
|
||||
def test_modifier_donnee_targeting_clicked_row_without_a_click_is_a_noop(client, game):
|
||||
def test_modifier_donnee_targeting_clicked_row_without_a_click_is_a_noop(client: FlaskClient, game: str) -> None:
|
||||
"""Pas de ligne cliquée transmise (ex. déclenché autrement qu'un vrai
|
||||
clic sur une ligne de Répéteur) -> ne doit rien modifier, pas planter."""
|
||||
def_id = _create_email_object(client, game)
|
||||
screen_id = _create_screen(client, game)
|
||||
resp = client.post(
|
||||
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
|
||||
data=json.dumps({
|
||||
"node_type": "action", "action_type": "modifier_donnee",
|
||||
"target_definition_id": def_id, "target_row_id": -1, "target_field": "is_opened",
|
||||
"data_operation": "definir_bool_vrai", "data_value": "",
|
||||
}),
|
||||
data=json.dumps(
|
||||
{
|
||||
"node_type": "action",
|
||||
"action_type": "modifier_donnee",
|
||||
"target_definition_id": def_id,
|
||||
"target_row_id": -1,
|
||||
"target_field": "is_opened",
|
||||
"data_operation": "definir_bool_vrai",
|
||||
"data_value": "",
|
||||
}
|
||||
),
|
||||
content_type="application/json",
|
||||
)
|
||||
node = resp.get_json()
|
||||
|
||||
resp = client.post(f"/game/{game}/flow/nodes/{node['id']}/run-data", data=json.dumps({}), content_type="application/json")
|
||||
resp = client.post(
|
||||
f"/game/{game}/flow/nodes/{node['id']}/run-data", data=json.dumps({}), content_type="application/json"
|
||||
)
|
||||
assert resp.get_json() == {"ok": False}
|
||||
|
||||
definition = db.get_definition(game, def_id)
|
||||
assert not db.get_row(game, definition, 1)["is_opened"]
|
||||
assert not db.get_row(game, definition, 2)["is_opened"]
|
||||
definition = not_none(db.get_definition(game, def_id))
|
||||
assert not not_none(db.get_row(game, definition, 1))["is_opened"]
|
||||
assert not not_none(db.get_row(game, definition, 2))["is_opened"]
|
||||
|
||||
|
||||
def test_ordinary_fixed_row_target_is_unaffected(client, game):
|
||||
def test_ordinary_fixed_row_target_is_unaffected(client: FlaskClient, game: str) -> None:
|
||||
"""Non-régression : une action visant une ligne FIXE (pas -1) continue
|
||||
d'ignorer tout clicked_row_id transmis."""
|
||||
def_id = _create_email_object(client, game)
|
||||
screen_id = _create_screen(client, game)
|
||||
resp = client.post(
|
||||
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
|
||||
data=json.dumps({
|
||||
"node_type": "action", "action_type": "modifier_donnee",
|
||||
"target_definition_id": def_id, "target_row_id": 1, "target_field": "is_opened",
|
||||
"data_operation": "definir_bool_vrai", "data_value": "",
|
||||
}),
|
||||
data=json.dumps(
|
||||
{
|
||||
"node_type": "action",
|
||||
"action_type": "modifier_donnee",
|
||||
"target_definition_id": def_id,
|
||||
"target_row_id": 1,
|
||||
"target_field": "is_opened",
|
||||
"data_operation": "definir_bool_vrai",
|
||||
"data_value": "",
|
||||
}
|
||||
),
|
||||
content_type="application/json",
|
||||
)
|
||||
node = resp.get_json()
|
||||
client.post(f"/game/{game}/flow/nodes/{node['id']}/run-data", data=json.dumps({"clicked_row_id": 2}), content_type="application/json")
|
||||
client.post(
|
||||
f"/game/{game}/flow/nodes/{node['id']}/run-data",
|
||||
data=json.dumps({"clicked_row_id": 2}),
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
definition = db.get_definition(game, def_id)
|
||||
assert db.get_row(game, definition, 1)["is_opened"]
|
||||
assert not db.get_row(game, definition, 2)["is_opened"]
|
||||
definition = not_none(db.get_definition(game, def_id))
|
||||
assert not_none(db.get_row(game, definition, 1))["is_opened"]
|
||||
assert not not_none(db.get_row(game, definition, 2))["is_opened"]
|
||||
|
||||
Reference in New Issue
Block a user