@@ -244,3 +244,60 @@ def test_ref_resolution_with_custom_base_uri(run_line, tmp_path, check_passes):
244244 assert result .exit_code == 0 , output
245245 else :
246246 assert result .exit_code == 1 , output
247+
248+
249+ @pytest .mark .parametrize ("num_instances" , (1 , 2 , 10 ))
250+ @pytest .mark .parametrize ("check_passes" , (True , False ))
251+ def test_remote_ref_resolution_callout_count_is_scale_free_in_instancefiles (
252+ run_line , tmp_path , num_instances , check_passes
253+ ):
254+ """
255+ Test that for any N > 1, validation of a schema with a ref against N instance files
256+ has exactly the same number of callouts as validation when N=1
257+
258+ This proves that the validator and caching are working correctly, and we aren't
259+ repeating callouts to rebuild state.
260+ """
261+ schema_uri = "https://example.org/schemas/main.json"
262+ ref_uri = "https://example.org/schemas/title_schema.json"
263+
264+ main_schema = {
265+ "$id" : schema_uri ,
266+ "$schema" : "http://json-schema.org/draft-07/schema" ,
267+ "properties" : {
268+ "title" : {"$ref" : "./title_schema.json" },
269+ },
270+ "additionalProperties" : False ,
271+ }
272+ title_schema = {"type" : "string" }
273+ responses .add ("GET" , schema_uri , json = main_schema )
274+ responses .add ("GET" , ref_uri , json = title_schema )
275+
276+ # write N documents
277+ instance_doc = {"title" : "doc one" if check_passes else 2 }
278+ instance_paths = []
279+ for i in range (num_instances ):
280+ instance_path = tmp_path / f"instance{ i } .json"
281+ instance_path .write_text (json .dumps (instance_doc ))
282+ instance_paths .append (str (instance_path ))
283+
284+ result = run_line (
285+ [
286+ "check-jsonschema" ,
287+ "--schemafile" ,
288+ schema_uri ,
289+ ]
290+ + instance_paths
291+ )
292+ output = f"\n stdout:\n { result .stdout } \n \n stderr:\n { result .stderr } "
293+ if check_passes :
294+ assert result .exit_code == 0 , output
295+ else :
296+ assert result .exit_code == 1 , output
297+
298+ # this is the moment of the "real" test run here:
299+ # no matter how many instances there were, there should only have been two calls
300+ # (one for the schema and one for the $ref)
301+ assert len (responses .calls ) == 2
302+ assert len ([c for c in responses .calls if c .request .url == schema_uri ]) == 1
303+ assert len ([c for c in responses .calls if c .request .url == ref_uri ]) == 1
0 commit comments