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>
144 lines
5.0 KiB
Python
144 lines
5.0 KiB
Python
"""Tests des conditions combinées ET/OU (2.4).
|
|
|
|
Un nœud Condition peut porter plusieurs clauses (cond_clauses, JSON) combinées
|
|
par cond_combinator ('et'/'ou'), en plus de sa clause "historique" unique
|
|
(cond_definition_id/cond_field/...). Un nœud sans cond_clauses doit garder
|
|
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 tests.conftest import not_none
|
|
|
|
|
|
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(not_none(re.search(r"/screens/(\d+)/edit", resp.headers["Location"])).group(1))
|
|
|
|
|
|
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 = 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: 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",
|
|
}
|
|
),
|
|
content_type="application/json",
|
|
)
|
|
node = resp.get_json()
|
|
assert node["cond_clauses"] is None
|
|
js = play_js_bundle()
|
|
assert "evaluateConditionClause" in js
|
|
assert "cond_clauses" in js
|
|
|
|
|
|
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",
|
|
},
|
|
]
|
|
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",
|
|
}
|
|
),
|
|
content_type="application/json",
|
|
)
|
|
assert resp.status_code == 200
|
|
node = resp.get_json()
|
|
assert node["cond_combinator"] == "ou"
|
|
stored_clauses = json.loads(node["cond_clauses"])
|
|
assert len(stored_clauses) == 2
|
|
assert stored_clauses[0]["field"] == "reputation"
|
|
assert stored_clauses[1]["field"] == "niveau"
|
|
|
|
|
|
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",
|
|
}
|
|
),
|
|
content_type="application/json",
|
|
)
|
|
node = resp.get_json()
|
|
assert node["cond_combinator"] == "et"
|
|
|
|
|
|
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
|