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>
189 lines
7.7 KiB
Python
189 lines
7.7 KiB
Python
"""Déplacement/animation automatiques d'un personnage posé sur une scène
|
|
2D (voir static/js/play/personnage-controller.js) : ZQSD + E par défaut,
|
|
sans le moindre nœud de flow à poser — le panneau "🕹️ Commandes"
|
|
(templates/scene_edit.html) permet seulement de les remapper/bloquer un
|
|
axe. Ce fichier teste la couche serveur (défauts, route de sauvegarde,
|
|
exposition dans full_game_payload) ; static/js/play/__tests__/
|
|
personnage-controller.test.js teste le comportement client (tick,
|
|
bornage, blocage d'axe)."""
|
|
|
|
import re
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
from flask.testing import FlaskClient
|
|
|
|
import screens
|
|
from tests.conftest import not_none
|
|
|
|
|
|
def _create_jeu2d_game(
|
|
client: FlaskClient, tmp_game_slug_cleanup: Callable[[str], str], name: str = "pytest_personnage_cmd"
|
|
) -> Any:
|
|
resp = client.post("/games/new", data={"name": name}, follow_redirects=False)
|
|
slug = tmp_game_slug_cleanup(resp.headers["Location"].rstrip("/").split("/")[-1])
|
|
screen_id = screens.create_screen(slug, "Scène 1", kind="jeu_2d")
|
|
return slug, screen_id
|
|
|
|
|
|
def _add_personnage(client: FlaskClient, slug: str, screen_id: int, forge_character: str = "zombie") -> Any:
|
|
resp = client.post(
|
|
f"/game/{slug}/screens/{screen_id}/scene-objects/add",
|
|
data={"kind": "personnage", "forge_character": forge_character},
|
|
follow_redirects=False,
|
|
)
|
|
assert resp.status_code == 302, resp.data
|
|
return int(not_none(re.search(r"selected=(\d+)", resp.headers["Location"])).group(1))
|
|
|
|
|
|
def test_freshly_placed_personnage_gets_default_zqsd_commands(
|
|
client: FlaskClient, tmp_game_slug_cleanup: Callable[[str], str]
|
|
) -> None:
|
|
slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup)
|
|
obj_id = _add_personnage(client, slug, screen_id)
|
|
obj = not_none(screens.get_scene_object(slug, obj_id))
|
|
assert screens.resolve_personnage_commands(obj) == screens.DEFAULT_PERSONNAGE_COMMANDS
|
|
|
|
|
|
def test_commands_route_persists_remapped_keys_and_axis_lock(
|
|
client: FlaskClient, tmp_game_slug_cleanup: Callable[[str], str]
|
|
) -> None:
|
|
slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup)
|
|
obj_id = _add_personnage(client, slug, screen_id)
|
|
|
|
resp = client.post(
|
|
f"/game/{slug}/scene-objects/{obj_id}/commandes",
|
|
data=(
|
|
'{"haut": "ArrowUp", "bas": "ArrowDown", "gauche": "ArrowLeft", "droite": "ArrowRight", '
|
|
'"interagir": " ", "axe": "horizontal", "vitesse": 8}'
|
|
),
|
|
content_type="application/json",
|
|
)
|
|
assert resp.status_code == 200
|
|
assert resp.get_json()["ok"] is True
|
|
|
|
obj = not_none(screens.get_scene_object(slug, obj_id))
|
|
commands = screens.resolve_personnage_commands(obj)
|
|
assert commands == {
|
|
"haut": "ArrowUp",
|
|
"bas": "ArrowDown",
|
|
"gauche": "ArrowLeft",
|
|
"droite": "ArrowRight",
|
|
"interagir": " ",
|
|
"axe": "horizontal",
|
|
"vitesse": 8,
|
|
"extra": [],
|
|
}
|
|
|
|
|
|
def test_commands_route_persists_extra_animation_bound_keys(
|
|
client: FlaskClient, tmp_game_slug_cleanup: Callable[[str], str]
|
|
) -> None:
|
|
"""Touches supplémentaires (sauter, attaquer...) — bug remonté par
|
|
l'utilisateur : au-delà des 4 touches de déplacement et de
|
|
"interagir", il manquait un moyen de lier une touche à N'IMPORTE
|
|
QUELLE autre pose du personnage."""
|
|
slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup)
|
|
obj_id = _add_personnage(client, slug, screen_id)
|
|
|
|
resp = client.post(
|
|
f"/game/{slug}/scene-objects/{obj_id}/commandes",
|
|
data='{"extra": [{"touche": "j", "animation": "jump"}, {"touche": "a", "animation": "attack"}]}',
|
|
content_type="application/json",
|
|
)
|
|
commands = resp.get_json()["commands"]
|
|
assert commands["extra"] == [{"touche": "j", "animation": "jump"}, {"touche": "a", "animation": "attack"}]
|
|
|
|
obj = not_none(screens.get_scene_object(slug, obj_id))
|
|
assert screens.resolve_personnage_commands(obj)["extra"] == commands["extra"]
|
|
|
|
|
|
def test_commands_route_drops_malformed_extra_entries(
|
|
client: FlaskClient, tmp_game_slug_cleanup: Callable[[str], str]
|
|
) -> None:
|
|
"""Une entrée sans touche/animation, un doublon de type, ou une liste
|
|
qui n'en est pas une : ignorée plutôt que de planter ou de polluer le
|
|
panneau avec une ligne inutilisable côté client."""
|
|
slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup)
|
|
obj_id = _add_personnage(client, slug, screen_id)
|
|
|
|
resp = client.post(
|
|
f"/game/{slug}/scene-objects/{obj_id}/commandes",
|
|
data=(
|
|
'{"extra": [{"touche": "j", "animation": "jump"}, {"touche": ""}, '
|
|
'{"animation": "attack"}, "pas un objet", 42]}'
|
|
),
|
|
content_type="application/json",
|
|
)
|
|
assert resp.get_json()["commands"]["extra"] == [{"touche": "j", "animation": "jump"}]
|
|
|
|
resp = client.post(
|
|
f"/game/{slug}/scene-objects/{obj_id}/commandes",
|
|
data='{"extra": "pas une liste"}',
|
|
content_type="application/json",
|
|
)
|
|
assert resp.get_json()["commands"]["extra"] == []
|
|
|
|
|
|
def test_commands_route_rejects_invalid_axis_and_clamps_speed(
|
|
client: FlaskClient, tmp_game_slug_cleanup: Callable[[str], str]
|
|
) -> None:
|
|
"""Un axe inconnu retombe sur "libre", une vitesse hors bornes est
|
|
ramenée dans [1, 20] — jamais une valeur qui planterait le calcul
|
|
d'un déplacement côté client (voir personnage-controller.js)."""
|
|
slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup)
|
|
obj_id = _add_personnage(client, slug, screen_id)
|
|
|
|
resp = client.post(
|
|
f"/game/{slug}/scene-objects/{obj_id}/commandes",
|
|
data='{"axe": "diagonal", "vitesse": 999}',
|
|
content_type="application/json",
|
|
)
|
|
commands = resp.get_json()["commands"]
|
|
assert commands["axe"] == "libre"
|
|
assert commands["vitesse"] == 20
|
|
|
|
|
|
def test_commands_route_falls_back_to_defaults_for_blank_or_missing_keys(
|
|
client: FlaskClient, tmp_game_slug_cleanup: Callable[[str], str]
|
|
) -> None:
|
|
""" "" (chaîne vide)/absent retombe sur le défaut — mais PAS " "
|
|
(Espace), une valeur ev.key parfaitement valide côté client pour
|
|
"interagir" (voir la note dans routes/scenes/scene_object_commands.py)."""
|
|
slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup)
|
|
obj_id = _add_personnage(client, slug, screen_id)
|
|
|
|
resp = client.post(
|
|
f"/game/{slug}/scene-objects/{obj_id}/commandes",
|
|
data='{"haut": "", "interagir": " "}',
|
|
content_type="application/json",
|
|
)
|
|
commands = resp.get_json()["commands"]
|
|
assert commands["haut"] == screens.DEFAULT_PERSONNAGE_COMMANDS["haut"]
|
|
assert commands["bas"] == screens.DEFAULT_PERSONNAGE_COMMANDS["bas"] # absent du body
|
|
assert commands["interagir"] == " "
|
|
|
|
|
|
def test_commands_route_404s_for_missing_object(client: FlaskClient, game: str) -> None:
|
|
resp = client.post(
|
|
f"/game/{game}/scene-objects/999999/commandes",
|
|
data="{}",
|
|
content_type="application/json",
|
|
)
|
|
assert resp.status_code == 404
|
|
|
|
|
|
def test_full_game_payload_exposes_resolved_commands_for_personnage_objects(
|
|
client: FlaskClient, tmp_game_slug_cleanup: Callable[[str], str]
|
|
) -> None:
|
|
slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup)
|
|
_add_personnage(client, slug, screen_id)
|
|
screens.add_scene_object(slug, screen_id, kind="decor") # jamais de commandes sur un décor
|
|
|
|
payload = screens.full_game_payload(slug)
|
|
scene_screen = next(s for s in payload["screens"] if s["id"] == screen_id)
|
|
personnage_obj = next(o for o in scene_screen["elements"] if o["kind"] == "personnage")
|
|
decor_obj = next(o for o in scene_screen["elements"] if o["kind"] == "decor")
|
|
assert personnage_obj["personnage_commandes"] == screens.DEFAULT_PERSONNAGE_COMMANDS
|
|
assert "personnage_commandes" not in decor_obj
|