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
@@ -19,7 +19,7 @@ function readFieldValue(definitionId, rowId, fieldName) {
|
||||
// capturé (voir bindClicks() dans triggers.js).
|
||||
if (rowId === -1) rowId = window.lastClickedRowId;
|
||||
const rows = gameData.data[String(definitionId)] || [];
|
||||
const row = rows.find(r => r.id === rowId);
|
||||
const row = rows.find((r) => r.id === rowId);
|
||||
return row ? row[fieldName] : undefined;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,9 @@ function compareValues(actual, operator, expected, fieldType) {
|
||||
const e = normalizeBool(expected);
|
||||
return operator === 'different' ? a !== e : a === e;
|
||||
}
|
||||
const an = parseFloat(actual), en = parseFloat(expected);
|
||||
const numeric = !isNaN(an) && !isNaN(en);
|
||||
const an = parseFloat(actual); const
|
||||
en = parseFloat(expected);
|
||||
const numeric = !Number.isNaN(an) && !Number.isNaN(en);
|
||||
if (numeric) {
|
||||
switch (operator) {
|
||||
case 'egal': return an === en;
|
||||
@@ -53,6 +54,7 @@ function compareValues(actual, operator, expected, fieldType) {
|
||||
case 'inferieur': return an < en;
|
||||
case 'superieur_egal': return an >= en;
|
||||
case 'inferieur_egal': return an <= en;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
const as = (actual === undefined || actual === null) ? '' : String(actual);
|
||||
@@ -63,7 +65,8 @@ function compareValues(actual, operator, expected, fieldType) {
|
||||
// créateur/l'IA n'a aucun moyen de connaître la casse EXACTE attendue).
|
||||
// superieur/inferieur restent une comparaison lexicographique brute
|
||||
// (l'ordre alphabétique dépend de la casse, hors du champ de ce bug).
|
||||
const asLower = as.toLowerCase(), esLower = es.toLowerCase();
|
||||
const asLower = as.toLowerCase(); const
|
||||
esLower = es.toLowerCase();
|
||||
switch (operator) {
|
||||
case 'egal': return asLower === esLower;
|
||||
case 'different': return asLower !== esLower;
|
||||
@@ -98,7 +101,7 @@ function resolveVariablePath(rawValue, path) {
|
||||
if (!path) return rawValue;
|
||||
let current;
|
||||
try { current = rawValue ? JSON.parse(rawValue) : null; } catch (e) { return null; }
|
||||
const segmentRe = /\.([^.\[\]]+)|\[(\d+)\]/g;
|
||||
const segmentRe = /\.([^.[\]]+)|\[(\d+)\]/g;
|
||||
let m;
|
||||
while ((m = segmentRe.exec(path)) !== null) {
|
||||
if (current === null || current === undefined) return null;
|
||||
@@ -133,7 +136,9 @@ function forgeCollisionRectFromBox(box, collision) {
|
||||
const left = box.left + (box.width - width) / 2 + offsetX;
|
||||
const top = box.top + (box.height - height) / 2 + offsetY;
|
||||
const shape = (collision && collision.shape) || 'rectangle';
|
||||
return { left, top, right: left + width, bottom: top + height, width, height, shape };
|
||||
return {
|
||||
left, top, right: left + width, bottom: top + height, width, height, shape,
|
||||
};
|
||||
}
|
||||
|
||||
function forgeRectanglesOverlap(a, b) {
|
||||
@@ -145,9 +150,12 @@ function forgeRectanglesOverlap(a, b) {
|
||||
// volontairement approximatif plutôt qu'une vraie intersection cercle-
|
||||
// rectangle, hors scope de ce premier réglage).
|
||||
function forgeCirclesOverlap(a, b) {
|
||||
const acx = a.left + a.width / 2, acy = a.top + a.height / 2, ar = Math.min(a.width, a.height) / 2;
|
||||
const bcx = b.left + b.width / 2, bcy = b.top + b.height / 2, br = Math.min(b.width, b.height) / 2;
|
||||
const dx = acx - bcx, dy = acy - bcy;
|
||||
const acx = a.left + a.width / 2; const acy = a.top + a.height / 2; const
|
||||
ar = Math.min(a.width, a.height) / 2;
|
||||
const bcx = b.left + b.width / 2; const bcy = b.top + b.height / 2; const
|
||||
br = Math.min(b.width, b.height) / 2;
|
||||
const dx = acx - bcx; const
|
||||
dy = acy - bcy;
|
||||
return Math.sqrt(dx * dx + dy * dy) < (ar + br);
|
||||
}
|
||||
|
||||
@@ -174,14 +182,17 @@ function forgeShapesOverlap(a, b) {
|
||||
// nulles), ou collision explicitement désactivée => pas de chevauchement
|
||||
// plutôt que de planter.
|
||||
function elementsOverlap(elementIdA, elementIdB) {
|
||||
const a = document.querySelector('[data-element-id="' + elementIdA + '"]');
|
||||
const b = document.querySelector('[data-element-id="' + elementIdB + '"]');
|
||||
const a = document.querySelector(`[data-element-id="${elementIdA}"]`);
|
||||
const b = document.querySelector(`[data-element-id="${elementIdB}"]`);
|
||||
if (!a || !b) return false;
|
||||
const screenData = (typeof screensData !== 'undefined' && typeof window !== 'undefined')
|
||||
&& screensData.find(function (s) { return s.id === window.currentScreenId; });
|
||||
const objA = screenData && (screenData.elements || []).find(function (o) { return o.id === elementIdA; });
|
||||
const objB = screenData && (screenData.elements || []).find(function (o) { return o.id === elementIdB; });
|
||||
if ((objA && objA.collision && objA.collision.enabled === false) || (objB && objB.collision && objB.collision.enabled === false)) {
|
||||
&& screensData.find((s) => s.id === window.currentScreenId);
|
||||
const objA = screenData && (screenData.elements || []).find((o) => o.id === elementIdA);
|
||||
const objB = screenData && (screenData.elements || []).find((o) => o.id === elementIdB);
|
||||
if (
|
||||
(objA && objA.collision && objA.collision.enabled === false)
|
||||
|| (objB && objB.collision && objB.collision.enabled === false)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const rectA = forgeCollisionRectFromBox(a.getBoundingClientRect(), objA && objA.collision);
|
||||
@@ -209,7 +220,11 @@ function evaluateConditionClause(clause) {
|
||||
const fieldType = varInfo && varInfo.type === 'booleen' ? 'booleen' : '';
|
||||
return compareValues(actual, operator, expected, fieldType);
|
||||
}
|
||||
const actual = readFieldValue(clause.definition_id ?? clause.cond_definition_id, clause.row_id ?? clause.cond_row_id, clause.field ?? clause.cond_field);
|
||||
const actual = readFieldValue(
|
||||
clause.definition_id ?? clause.cond_definition_id,
|
||||
clause.row_id ?? clause.cond_row_id,
|
||||
clause.field ?? clause.cond_field,
|
||||
);
|
||||
return compareValues(actual, operator, expected, clause.field_type ?? clause.cond_field_type);
|
||||
}
|
||||
|
||||
@@ -230,7 +245,15 @@ function evaluateConditionNode(node) {
|
||||
// cette branche ne s'exécute jamais côté client.
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = {
|
||||
readFieldValue, compareValues, readVariableValue, resolveVariablePath, evaluateConditionClause, evaluateConditionNode,
|
||||
forgeCollisionRectFromBox, forgeRectanglesOverlap, forgeCirclesOverlap, forgeShapesOverlap,
|
||||
readFieldValue,
|
||||
compareValues,
|
||||
readVariableValue,
|
||||
resolveVariablePath,
|
||||
evaluateConditionClause,
|
||||
evaluateConditionNode,
|
||||
forgeCollisionRectFromBox,
|
||||
forgeRectanglesOverlap,
|
||||
forgeCirclesOverlap,
|
||||
forgeShapesOverlap,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user