mirror of
https://github.com/deunix-educ/aventuriers-des-mots.git
synced 2026-10-13 02:11:58 +02:00
Add JSON schemas, data validator, and first CE1 content
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>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
extends GutTest
|
||||
## Tests du validateur de schema generique (scripts/data/schema_validator.gd),
|
||||
## independants de tout contenu reel de data/.
|
||||
|
||||
var schema: Dictionary = {
|
||||
"type": "object",
|
||||
"required": ["id", "level"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" },
|
||||
"level": { "type": "string", "enum": ["CE1", "CE2"] },
|
||||
"difficulty": { "type": "integer", "minimum": 1, "maximum": 3 },
|
||||
"tags": { "type": "array", "minItems": 1, "items": { "type": "string" } },
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
func test_valid_object_has_no_errors() -> void:
|
||||
var data := { "id": "ex_01", "level": "CE1", "difficulty": 2, "tags": ["pluriel"] }
|
||||
assert_eq(SchemaValidator.validate(data, schema), [])
|
||||
|
||||
|
||||
func test_missing_required_property_is_reported() -> void:
|
||||
var data := { "level": "CE1" }
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "id")
|
||||
|
||||
|
||||
func test_wrong_type_is_reported() -> void:
|
||||
var data := { "id": "ex_01", "level": "CE1", "difficulty": "deux" }
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "difficulty")
|
||||
|
||||
|
||||
func test_enum_violation_is_reported() -> void:
|
||||
var data := { "id": "ex_01", "level": "CM1" }
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "level")
|
||||
|
||||
|
||||
func test_pattern_violation_is_reported() -> void:
|
||||
var data := { "id": "Ex-01", "level": "CE1" }
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "id")
|
||||
|
||||
|
||||
func test_unexpected_property_is_reported_when_additional_forbidden() -> void:
|
||||
var data := { "id": "ex_01", "level": "CE1", "extra": true }
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "extra")
|
||||
|
||||
|
||||
func test_min_items_violation_is_reported() -> void:
|
||||
var data := { "id": "ex_01", "level": "CE1", "tags": [] }
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "tags")
|
||||
|
||||
|
||||
func test_numeric_bounds_are_checked() -> void:
|
||||
var data := { "id": "ex_01", "level": "CE1", "difficulty": 9 }
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "difficulty")
|
||||
Reference in New Issue
Block a user