Skip to content

Commit 80d37bc

Browse files
committed
Fix schema validation to work with Python 3.14
jsonschema started warning when it's auto-resolving references, so we instead pre-download the expected references and create a registry.
1 parent 444e2a5 commit 80d37bc

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

tools/ci/tc/tests/test_valid.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# mypy: ignore-errors
2+
from urllib.parse import urlsplit
23

34
import json
45
import os
@@ -9,6 +10,8 @@
910
import pytest
1011
import yaml
1112
from jsonschema import validate
13+
from referencing import Resource
14+
from referencing.jsonschema import DRAFT6, SchemaRegistry
1215

1316
from tools.ci.tc import decision
1417

@@ -86,13 +89,24 @@ def test_verify_payload():
8689
"""Verify that the decision task produces tasks with a valid payload"""
8790
from tools.ci.tc.decision import decide
8891

89-
r = httpx.get("https://community-tc.services.mozilla.com/schemas/queue/v1/create-task-request.json")
90-
r.raise_for_status()
91-
create_task_schema = r.json()
92+
schema_urls = ["https://community-tc.services.mozilla.com/schemas/common/metaschema.json",
93+
"https://community-tc.services.mozilla.com/schemas/queue/v1/task-metadata.json",
94+
"https://community-tc.services.mozilla.com/schemas/queue/v1/task.json",
95+
"https://community-tc.services.mozilla.com/schemas/queue/v1/create-task-request.json",
96+
"https://community-tc.services.mozilla.com/references/schemas/docker-worker/v1/payload.json"]
9297

93-
r = httpx.get("https://community-tc.services.mozilla.com/references/schemas/docker-worker/v1/payload.json")
94-
r.raise_for_status()
95-
payload_schema = r.json()
98+
schemas = {}
99+
for schema_url in schema_urls:
100+
name = urlsplit(schema_url).path.rsplit("/", 1)[-1].rsplit(".", 1)[0]
101+
r = httpx.get(schema_url)
102+
r.raise_for_status()
103+
schemas[name]= (schema_url, r.json())
104+
105+
106+
registry = SchemaRegistry()
107+
for url, schema_doc in schemas.values():
108+
resource = Resource.from_contents(schema_doc, default_specification=DRAFT6)
109+
registry = registry.with_resource(url, resource)
96110

97111
jobs = ["lint",
98112
"manifest_upload",
@@ -111,8 +125,12 @@ def test_verify_payload():
111125
task_id_map = decide(event)
112126
for name, (task_id, task_data) in task_id_map.items():
113127
try:
114-
validate(instance=task_data, schema=create_task_schema)
115-
validate(instance=task_data["payload"], schema=payload_schema)
128+
validate(instance=task_data,
129+
schema=schemas["create-task-request"][1],
130+
registry=registry)
131+
validate(instance=task_data["payload"],
132+
schema=schemas["payload"][1],
133+
registry=registry)
116134
except Exception as e:
117135
print(f"Validation failed for task '{name}':\n{json.dumps(task_data, indent=2)}")
118136
raise e

tools/requirements_tests.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
httpx[http2]==0.27.2
22
json-e==4.7.0
3-
jsonschema==4.17.3
3+
jsonschema==4.25.1; python_version >= '3.9'
4+
jsonschema==4.23.0; python_version < '3.9'
45
pyyaml==6.0.1
56
types-pyyaml==6.0.12.20241230
67
taskcluster==91.0.1

0 commit comments

Comments
 (0)