Add pure correction and pedagogy logic with full test coverage

scripts/correction/: AnswerValidator (multiple choice, sentence
correction via tap-the-faulty-word + retype) and DictationAnalyzer
build the CorrectionResult structure from cahier des charges §6.
Dictation analysis aligns words with WordAligner (Wagner-Fischer edit
distance) before any character comparison, so an omitted or added
word doesn't cascade into false errors on every following word.
TextNormalizer handles non-breaking spaces, typographic apostrophes,
and decomposed-vs-composed French accented characters via an
explicit table (GDScript has no built-in NFC/NFD normalization).
Error classification follows the data annotations only (rule_id
present -> grammatical, absent -> unclassified), never a runtime
linguistic guess.

scripts/pedagogy/: DifficultyManager (per-skill difficulty from
recent results), AttemptFlow (3-attempt graduated aid: hint, then
explanation, then reveal, matching exercise-lifecycle.md's second
gap), and ReviewScheduler (the five mastery states from §9, with
session-counted spaced review intervals [1, 3, 6, 12] rather than
wall-clock dates, since a family device's clock isn't trustworthy).

All of it is pure: no scene tree, no clock or RNG read directly,
every effectful input (session number, attempt outcome) is a
parameter. 65 headless tests across both layers, including the
word-omission-doesn't-cascade regression and the full
decouverte -> acquise -> a_reviser -> acquise path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Denis Defolie
2026-10-11 17:03:14 +02:00
parent d057c8ee77
commit 2fe455f5d1
36 changed files with 1111 additions and 28 deletions
+45
View File
@@ -0,0 +1,45 @@
extends GutTest
## Tests de WordAligner : l'alignement doit absorber les mots omis ou ajoutes
## sans decaler les comparaisons suivantes.
var target: Array[String] = ["Les", "petits", "chats", "dorment."]
func test_identical_sequences_are_all_matches() -> void:
var ops := WordAligner.align(target, target.duplicate())
for op in ops:
assert_eq(op["op"], "match")
assert_eq(ops.size(), 4)
func test_single_substitution_is_detected_at_the_right_position() -> void:
var submitted: Array[String] = ["Les", "petit", "chats", "dorment."]
var ops := WordAligner.align(target, submitted)
assert_eq(ops.size(), 4)
assert_eq(ops[1]["op"], "substitute")
assert_eq(ops[1]["target_index"], 1)
assert_eq(ops[0]["op"], "match")
assert_eq(ops[2]["op"], "match")
assert_eq(ops[3]["op"], "match")
func test_missing_word_is_a_delete_and_does_not_shift_later_matches() -> void:
# L'enfant a oublie "petits" : sans alignement, "chats" se comparerait a
# "petits" et "dorment." a "chats", generant deux fausses erreurs en cascade.
var submitted: Array[String] = ["Les", "chats", "dorment."]
var ops := WordAligner.align(target, submitted)
assert_eq(ops.size(), 4)
assert_eq(ops[0]["op"], "match")
assert_eq(ops[1]["op"], "delete")
assert_eq(ops[1]["target_index"], 1)
assert_eq(ops[2]["op"], "match")
assert_eq(ops[2]["target_index"], 2)
assert_eq(ops[3]["op"], "match")
assert_eq(ops[3]["target_index"], 3)
func test_extra_word_is_an_insert() -> void:
var submitted: Array[String] = ["Les", "petits", "petits", "chats", "dorment."]
var ops := WordAligner.align(target, submitted)
var insert_ops: Array = ops.filter(func(op: Dictionary) -> bool: return op["op"] == "insert")
assert_eq(insert_ops.size(), 1)