feat(assessment): define corrective and training attempt contracts

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 10:36:16 +03:00
1 parent fade4e76e4
commit 20c03288d6
71 files changed
+14786 -1743

No files matched your search

+95
View File
@@ -118,6 +118,101 @@ class MergeSchemasTest(unittest.TestCase):
"#/Contact/properties/email",
)
def test_rewrites_only_schema_targets_in_discriminator_mappings(self) -> None:
self.write_yaml(
"components/schemas/common_schemas.yml",
{
"schemas": {
"entity.Contact": {"type": "object"},
"entity.Status": {"type": "string"},
}
},
)
profile_path = self.write_yaml(
"components/schemas/profile_schemas.yml",
{
"schemas": {
"response.Profile": {
"type": "object",
"discriminator": {
"propertyName": "kind",
"mapping": {
"profile": "#/schemas/response.Profile",
"status": "#/schemas/entity.Status",
"contact": "./common_schemas.yml#/schemas/entity.Contact",
"external": "https://schemas.example.test/external.yml#/schemas/External",
},
},
"mapping": {"example": "#/schemas/entity.Status"},
"example": {"mapping": {"example": "#/schemas/entity.Status"}},
}
}
},
)
source_schema = MERGE.load_yaml(profile_path)["schemas"]["response.Profile"]
references = MERGE.collect_references(source_schema)
self.assertIn(("#/schemas/response.Profile", "$.discriminator.mapping.profile"), references)
self.assertIn(
(
"./common_schemas.yml#/schemas/entity.Contact",
"$.discriminator.mapping.contact",
),
references,
)
self.assertNotIn(("#/schemas/entity.Status", "$.mapping.example"), references)
MERGE.merge_contract(self.contract_root)
profile = self.read_yaml("components/schemas.yml")["Profile"]
mapping = profile["discriminator"]["mapping"]
self.assertEqual(mapping["profile"], "#/Profile")
self.assertEqual(mapping["status"], "#/Status")
self.assertEqual(mapping["contact"], "#/Contact")
self.assertEqual(
mapping["external"],
"https://schemas.example.test/external.yml#/schemas/External",
)
self.assertEqual(profile["mapping"]["example"], "#/schemas/entity.Status")
self.assertEqual(
profile["example"]["mapping"]["example"], "#/schemas/entity.Status"
)
def test_stale_discriminator_mapping_route_refs_are_rejected(self) -> None:
self.write_yaml(
"components/schemas/health_schemas.yml",
{"schemas": {"response.Health": {"type": "object"}}},
)
self.write_yaml(
"routes/health.yml",
{
"get": {
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"oneOf": [],
"discriminator": {
"propertyName": "kind",
"mapping": {
"health": "../components/schemas.yml#/schemas/response.Health"
},
},
}
}
}
}
}
}
},
)
with self.assertRaisesRegex(MERGE.MergeError, "stale schema references") as error:
MERGE.merge_contract(self.contract_root)
self.assertIn("discriminator.mapping.health", str(error.exception))
self.assertFalse((self.contract_root / "components" / "schemas.yml").exists())
def test_duplicate_normalized_names_fail_without_overwriting_output(self) -> None:
self.write_yaml(
"components/schemas/auth_schemas.yml",