Fix sentence correction rejecting valid answers over incidental text differences

AnswerValidator.validate_sentence_correction compared the typed
correction to the expected word with raw string equality, with none
of the tolerance already built for dictations: no case folding, no
typographic-apostrophe or whitespace normalization, no decomposed-
accent handling. Tapping "petit" and typing "petits" could fail for
reasons having nothing to do with the grammar point being tested
(e.g. a stray capital from autocapitalization), which violates the
"an ambiguous answer is never auto-marked wrong" invariant.

Found this while chasing a manual bug report: an automated test
reproducing the user's exact click sequence (tap once, type, submit)
did NOT reproduce the failure, which actually pointed at the real
gap -- the logic worked for byte-identical input, but had zero
tolerance for anything else. Now reuses TextNormalizer (built for
dictation analysis) before comparing, case-insensitively, while still
showing the child's raw typed text in the feedback. Three new tests
cover case, incidental whitespace, and decomposed accents.

Rebuilt both exports so the shipped binaries include the fix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Denis Defolie
2026-10-11 18:12:56 +02:00
parent b0d11eb831
commit 91dcd7e07a
3 changed files with 61 additions and 1 deletions
+13 -1
View File
@@ -48,7 +48,7 @@ static func validate_sentence_correction(
errors.append(_missed_error(i, token, exercise))
elif is_faulty and was_selected:
var submitted: String = corrections.get(i, "")
if submitted != token["expected"]:
if not _matches_expected(submitted, token["expected"]):
errors.append(_wrong_correction_error(i, submitted, token, exercise))
elif not is_faulty and was_selected:
errors.append(_false_positive_error(i, token, exercise))
@@ -65,6 +65,18 @@ static func validate_sentence_correction(
)
## Compare la correction saisie a celle attendue en ignorant les differences
## incidentes (majuscule/minuscule, apostrophe typographique, espaces,
## accents decomposes) : ce n'est pas la casse qui est evaluee ici, c'est
## l'accord. Une reponse ambigue n'est pas declaree fausse automatiquement
## (CLAUDE.md, invariants pedagogiques).
static func _matches_expected(submitted: String, expected: String) -> bool:
return (
TextNormalizer.normalize(submitted).to_lower()
== TextNormalizer.normalize(expected).to_lower()
)
static func _missed_error(index: int, token: Dictionary, exercise: Dictionary) -> Dictionary:
return {
"position": index,