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
@@ -1 +1 @@
|
||||
from . import ia_chat
|
||||
from . import ia_chat # noqa: F401 - enregistre la route definie dans ce module
|
||||
|
||||
+16
-12
@@ -1,14 +1,16 @@
|
||||
from typing import Any
|
||||
|
||||
from flask import g, jsonify, request
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
import ai
|
||||
import screens
|
||||
|
||||
from core.flask_app import app
|
||||
|
||||
_CONVERSATION_NOT_FOUND = {"error": "conversation introuvable"}
|
||||
|
||||
|
||||
def _get_owned_conversation(slug, conversation_id):
|
||||
def _get_owned_conversation(slug: str, conversation_id: int) -> dict[str, Any] | None:
|
||||
"""La portée par SLUG (db.connect(slug), voir screens/ia/) suffit
|
||||
déjà à isoler les conversations d'un jeu à l'autre — un id d'une
|
||||
autre base n'existe simplement pas ici, même patron que
|
||||
@@ -17,22 +19,22 @@ def _get_owned_conversation(slug, conversation_id):
|
||||
|
||||
|
||||
@app.route("/game/<slug>/screens/<int:screen_id>/ia-conversations", methods=["GET"])
|
||||
def ia_conversations_list(slug, screen_id):
|
||||
def ia_conversations_list(slug: str, screen_id: int) -> Response:
|
||||
"""Colonne de gauche de l'onglet "Générer avec l'IA" — toutes les
|
||||
conversations de cet écran, plus récente en premier."""
|
||||
return jsonify(screens.list_ia_conversations(slug, screen_id))
|
||||
|
||||
|
||||
@app.route("/game/<slug>/screens/<int:screen_id>/ia-conversations", methods=["POST"])
|
||||
def ia_conversations_create(slug, screen_id):
|
||||
""""+ Nouvelle conversation" — créée immédiatement, vide."""
|
||||
def ia_conversations_create(slug: str, screen_id: int) -> Response:
|
||||
""" "+ Nouvelle conversation" — créée immédiatement, vide."""
|
||||
conversation_id = screens.create_ia_conversation(slug, screen_id)
|
||||
conversation = screens.get_ia_conversation(slug, conversation_id)
|
||||
return jsonify(conversation)
|
||||
|
||||
|
||||
@app.route("/game/<slug>/ia-conversations/<int:conversation_id>", methods=["DELETE"])
|
||||
def ia_conversation_delete(slug, conversation_id):
|
||||
def ia_conversation_delete(slug: str, conversation_id: int) -> Response | tuple[Response, int]:
|
||||
if not _get_owned_conversation(slug, conversation_id):
|
||||
return jsonify(_CONVERSATION_NOT_FOUND), 404
|
||||
screens.delete_ia_conversation(slug, conversation_id)
|
||||
@@ -40,7 +42,7 @@ def ia_conversation_delete(slug, conversation_id):
|
||||
|
||||
|
||||
@app.route("/game/<slug>/ia-conversations/<int:conversation_id>/messages", methods=["GET"])
|
||||
def ia_conversation_messages(slug, conversation_id):
|
||||
def ia_conversation_messages(slug: str, conversation_id: int) -> Response | tuple[Response, int]:
|
||||
"""Historique complet d'UNE conversation — chargé par
|
||||
static/js/ia/ia-chat.js à sa sélection dans la colonne."""
|
||||
if not _get_owned_conversation(slug, conversation_id):
|
||||
@@ -49,7 +51,7 @@ def ia_conversation_messages(slug, conversation_id):
|
||||
|
||||
|
||||
@app.route("/game/<slug>/ia-conversations/<int:conversation_id>/messages", methods=["POST"])
|
||||
def ia_conversation_send(slug, conversation_id):
|
||||
def ia_conversation_send(slug: str, conversation_id: int) -> Response | tuple[Response, int]:
|
||||
"""Envoie un message dans une conversation — body {message}. Persiste
|
||||
le message du créateur et la réponse, renvoie les deux.
|
||||
|
||||
@@ -79,7 +81,9 @@ def ia_conversation_send(slug, conversation_id):
|
||||
|
||||
user_message_id = screens.add_ia_chat_message(slug, conversation_id, "user", message)
|
||||
assistant_message_id = screens.add_ia_chat_message(slug, conversation_id, "assistant", reply)
|
||||
return jsonify({
|
||||
"user_message": {"id": user_message_id, "role": "user", "content": message},
|
||||
"assistant_message": {"id": assistant_message_id, "role": "assistant", "content": reply},
|
||||
})
|
||||
return jsonify(
|
||||
{
|
||||
"user_message": {"id": user_message_id, "role": "user", "content": message},
|
||||
"assistant_message": {"id": assistant_message_id, "role": "assistant", "content": reply},
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user