mirror of
https://github.com/deunix-educ/aventuriers-des-mots.git
synced 2026-10-13 02:11:58 +02:00
d057c8ee77
Introduces a generic JSON-Schema-subset validator in GDScript (scripts/data/schema_validator.gd) used both by `make validate-data` and, later, by ExerciseEngine at load time, plus semantic_checks.gd for cross-field constraints a schema can't express (answer index bounds, at least one faulty token in sentence correction, word count matching between a dictation's target_text and its annotations). Schemas cover rule, exercise (dispatched per type: multiple_choice, sentence_correction), dictation, curriculum, and save (save.schema.json is not yet wired into validate-data; saves live in user://, handled at the Profiles/Saves step). First draft content for the CE1 "accord_adjectif" rule (one rule, two multiple-choice exercises, one sentence correction, one dictation, one curriculum entry) exercises the full pipeline end to end and seeds docs/review/content-review.md, regenerated by the new tools/generate_content_review.py (`make content-review`). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
69 lines
2.7 KiB
GDScript
69 lines
2.7 KiB
GDScript
extends SceneTree
|
|
## Outil headless invoque par `make validate-data`.
|
|
## Valide chaque fichier JSON de data/ contre son schema (data/schemas/), puis
|
|
## applique les contraintes croisees que le schema ne peut pas exprimer.
|
|
|
|
|
|
func _init() -> void:
|
|
var failures: Array[String] = []
|
|
var checked := 0
|
|
|
|
checked += _validate_simple_dir("res://data/rules", "rule", failures)
|
|
checked += _validate_simple_dir("res://data/curriculum", "curriculum", failures)
|
|
checked += _validate_dictations("res://data/dictations", failures)
|
|
checked += _validate_exercises("res://data/exercises", failures)
|
|
|
|
if failures.is_empty():
|
|
print("validate-data : %d fichier(s) JSON valide(s)" % checked)
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
printerr(failure)
|
|
printerr("validate-data : %d erreur(s)" % failures.size())
|
|
quit(1)
|
|
|
|
|
|
func _validate_simple_dir(dir_path: String, schema_name: String, failures: Array[String]) -> int:
|
|
var count := 0
|
|
for path in DataLoader.find_json_files(dir_path):
|
|
count += 1
|
|
failures.append_array(DataLoader.validate_file(path, schema_name))
|
|
return count
|
|
|
|
|
|
func _validate_dictations(dir_path: String, failures: Array[String]) -> int:
|
|
var count := 0
|
|
for path in DataLoader.find_json_files(dir_path):
|
|
count += 1
|
|
var schema_errors := DataLoader.validate_file(path, "dictation")
|
|
failures.append_array(schema_errors)
|
|
if schema_errors.is_empty():
|
|
var data: Dictionary = DataLoader.read_json(path)
|
|
failures.append_array(SemanticChecks.check_dictation(data, path))
|
|
return count
|
|
|
|
|
|
func _validate_exercises(dir_path: String, failures: Array[String]) -> int:
|
|
var count := 0
|
|
for path in DataLoader.find_json_files(dir_path):
|
|
count += 1
|
|
var data: Variant = DataLoader.read_json(path)
|
|
if data == null or typeof(data) != TYPE_DICTIONARY or not data.has("type"):
|
|
failures.append("%s : champ 'type' manquant ou JSON invalide" % path)
|
|
continue
|
|
var exercise_type: String = data["type"]
|
|
var schema_name := DataLoader.exercise_schema_name_for_type(exercise_type)
|
|
if schema_name.is_empty():
|
|
failures.append("%s : type d'exercice inconnu '%s'" % [path, exercise_type])
|
|
continue
|
|
var schema_errors := DataLoader.validate_file(path, schema_name)
|
|
failures.append_array(schema_errors)
|
|
if not schema_errors.is_empty():
|
|
continue
|
|
match exercise_type:
|
|
"multiple_choice":
|
|
failures.append_array(SemanticChecks.check_multiple_choice(data, path))
|
|
"sentence_correction":
|
|
failures.append_array(SemanticChecks.check_sentence_correction(data, path))
|
|
return count
|