@@ -108,7 +108,8 @@ event_records(fixture) = EventsMCP.event_subscriptions(fixture.server.events.sto
108108 @test descriptor[" delivery" ] == [" webhook" ]
109109 @test descriptor[" inputSchema" ][" required" ] == [" resource" ]
110110 @test descriptor[" payloadSchema" ][" required" ] == [" resource" , " text" ]
111- @test descriptor[" inputSchema" ][" \$ schema" ] == " http://json-schema.org/draft-07/schema#"
111+ @test ! haskey (descriptor[" inputSchema" ], " \$ schema" )
112+ @test ! haskey (descriptor[" payloadSchema" ], " \$ schema" )
112113 _, page = event_request (server, " events/list" , Dict (" limit" => 1 ); owner= " beta" )
113114 @test page[" result" ][" nextCursor" ] == " 2"
114115 _, next = event_request (server, " events/list" , Dict (" cursor" => page[" result" ][" nextCursor" ]); owner= " beta" )
@@ -152,6 +153,131 @@ event_records(fixture) = EventsMCP.event_subscriptions(fixture.server.events.sto
152153 @test ! haskey (local_schema, " \$ schema" )
153154end
154155
156+ @testset " Portable event schema publication preserves validation" begin
157+ fixture = event_fixture ()
158+ server = fixture. server
159+ schema = Dict {String,Any} (" type" => " object" , " properties" => Dict (
160+ " label" => Dict (" type" => [" string" , " null" ]),
161+ " tags" => Dict (" type" => " array" , " items" => Dict (" type" => " string" )),
162+ ), " additionalProperties" => false )
163+ original = deepcopy (schema)
164+ EventsMCP. register_event! (server; name= " portable" , input_schema= schema, payload_schema= schema,
165+ matches= (_... ) -> true )
166+ definition = server. events. definitions[" portable" ]
167+ @test EventsMCP. event_descriptor (definition)[" inputSchema" ] == original
168+ @test EventsMCP. event_descriptor (definition)[" payloadSchema" ] == original
169+ @test schema == original
170+ for validator in (definition. input_validator, definition. payload_validator)
171+ @test isvalid (validator, Dict (" label" => nothing , " tags" => [" one" ]))
172+ @test ! isvalid (validator, Dict (" label" => 1 ))
173+ @test ! isvalid (validator, Dict (" tags" => [1 ]))
174+ @test ! isvalid (validator, Dict (" unexpected" => true ))
175+ end
176+ response, rejected = event_request (server, " events/subscribe" ,
177+ event_params (name= " portable" , arguments= Dict (" label" => 1 )))
178+ @test response. status == 200
179+ @test rejected[" error" ][" code" ] == - 32602
180+ @test isempty (fixture. calls)
181+ @test isempty (event_records (fixture))
182+ @test_throws ArgumentError EventsMCP. emit_event! (server, " portable" , Dict (" label" => 1 ))
183+ @test isempty (fixture. calls)
184+
185+ # Property names and literal values are not schema keyword positions.
186+ literals = Dict {String,Any} (" type" => " object" , " properties" => Dict (
187+ " \$ schema" => Dict (" enum" => [Dict (" \$ schema" => " literal" , " \$ ref" => " literal" )]),
188+ ))
189+ EventsMCP. register_event! (server; name= " literals" , input_schema= literals, payload_schema= Dict (), matches= (_... ) -> true )
190+ @test EventsMCP. event_descriptor (server. events. definitions[" literals" ])[" inputSchema" ] == literals
191+
192+ for dialect in (" http://json-schema.org/draft-04/schema#" , " https://json-schema.org/draft-06/schema" , " http://json-schema.org/draft-07/schema#" )
193+ declared = merge (deepcopy (schema), Dict (" \$ schema" => dialect))
194+ EventsMCP. register_event! (server; name= dialect, input_schema= declared, payload_schema= Dict (), matches= (_... ) -> true )
195+ @test EventsMCP. event_descriptor (server. events. definitions[dialect])[" inputSchema" ] == declared
196+ end
197+
198+ legacy_schemas = [
199+ Dict (" type" => " array" , " items" => [Dict (" type" => " string" )], " additionalItems" => false ),
200+ Dict (" dependencies" => Dict (" a" => [" b" ])),
201+ Dict (" definitions" => Dict (" text" => Dict (" type" => " string" )), " \$ ref" => " #/definitions/text" , " maxLength" => 1 ),
202+ Dict (" properties" => Dict (" nested" => Dict (" type" => " array" , " items" => [Dict (" type" => " integer" )]))),
203+ Dict (" properties" => Dict (" nested" => Dict (" \$ schema" => " http://json-schema.org/draft-07/schema#" , " type" => " string" ))),
204+ Dict (" format" => " email" ),
205+ Dict (" prefixItems" => [Dict (" type" => " string" )]),
206+ Dict (" unevaluatedProperties" => false ),
207+ Dict (" dependentRequired" => Dict (" a" => [" b" ])),
208+ Dict (" contains" => Dict (" type" => " integer" ), " minContains" => 2 ),
209+ Dict (" x-custom" => Dict (" type" => " string" )),
210+ Dict (" exclusiveMinimum" => true , " minimum" => 1 ),
211+ ]
212+ for (index, legacy) in enumerate (legacy_schemas)
213+ name = " legacy-$(index) "
214+ EventsMCP. register_event! (server; name, input_schema= legacy, payload_schema= schema, matches= (_... ) -> true )
215+ descriptor = EventsMCP. event_descriptor (server. events. definitions[name])
216+ @test descriptor[" inputSchema" ] == merge (legacy, Dict (" \$ schema" => " http://json-schema.org/draft-07/schema#" ))
217+ @test descriptor[" payloadSchema" ] == original
218+ @test ! haskey (legacy, " \$ schema" )
219+ end
220+ tuple_validator = server. events. definitions[" legacy-1" ]. input_validator
221+ @test isvalid (tuple_validator, [" one" ])
222+ @test ! isvalid (tuple_validator, [1 ])
223+ @test ! isvalid (tuple_validator, [" one" , " two" ])
224+ dependency_validator = server. events. definitions[" legacy-2" ]. input_validator
225+ @test ! isvalid (dependency_validator, Dict (" a" => true ))
226+ @test isvalid (dependency_validator, Dict (" a" => true , " b" => false ))
227+ @test isvalid (server. events. definitions[" legacy-3" ]. input_validator, " long text" )
228+ @test_throws ArgumentError EventsMCP. register_event! (server; name= " annotation-ref" ,
229+ input_schema= Dict (" default" => Dict (" \$ ref" => " https://127.0.0.1/private" )), payload_schema= schema, matches= (_... ) -> true )
230+ end
231+
232+ @testset " Portable event constraints keep their assertions" begin
233+ cases = [
234+ (Dict (" type" => " number" , " minimum" => 0 , " maximum" => 10 ,
235+ " exclusiveMinimum" => 0 , " exclusiveMaximum" => 10 , " multipleOf" => 0.5 ),
236+ [1 , 9.5 ], [0 , 10 , 1.25 ]),
237+ (Dict {String,Any} (" type" => " string" , " minLength" => 2 , " maxLength" => 4 ,
238+ " pattern" => " ^[a-z]+\$ " , " title" => " Label" , " description" => " A short label" ,
239+ " \$ comment" => " Lowercase labels only" , " readOnly" => false , " writeOnly" => true ,
240+ " default" => " ok" , " examples" => [" ok" ]),
241+ [" ok" , " good" ], [" x" , " longer" , " UP" ]),
242+ (Dict (" type" => " array" , " items" => Dict (" type" => " string" ),
243+ " minItems" => 1 , " maxItems" => 2 , " uniqueItems" => true ),
244+ [[" one" ], [" one" , " two" ]], [String[], [" one" , " one" ], [" one" , " two" , " three" ], [1 ]]),
245+ (Dict {String,Any} (" type" => " object" , " minProperties" => 1 , " maxProperties" => 2 ,
246+ " propertyNames" => Dict (" minLength" => 1 ),
247+ " patternProperties" => Dict (" ^x_" => Dict (" type" => " boolean" ))),
248+ [Dict (" x_a" => true ), Dict (" other" => 1 )],
249+ [Dict (), Dict (" " => 1 ), Dict (" x_a" => 1 ), Dict (" a" => 1 , " b" => 2 , " c" => 3 )]),
250+ (Dict (" allOf" => [
251+ Dict (" anyOf" => [Dict (" const" => " a" ), Dict (" const" => " bb" )]),
252+ Dict (" oneOf" => [Dict (" type" => " string" ), Dict (" type" => " number" )]),
253+ Dict (" not" => Dict (" const" => " cc" )),
254+ Dict (" if" => Dict (" const" => " a" ), " then" => Dict (" maxLength" => 1 ),
255+ " else" => Dict (" minLength" => 2 )),
256+ true ,
257+ ]), [" a" , " bb" ], [" b" , " cc" , 1 ]),
258+ ]
259+ fixture = event_fixture ()
260+ for (index, (schema, accepted, rejected)) in enumerate (cases)
261+ name = " constraints-$(index) "
262+ original = deepcopy (schema)
263+ EventsMCP. register_event! (fixture. server; name, input_schema= schema,
264+ payload_schema= schema, matches= (_... ) -> true )
265+ definition = fixture. server. events. definitions[name]
266+ descriptor = EventsMCP. event_descriptor (definition)
267+ @test descriptor[" inputSchema" ] == original
268+ @test descriptor[" payloadSchema" ] == original
269+ @test schema == original
270+ for validator in (definition. input_validator, definition. payload_validator)
271+ for value in accepted
272+ @test isvalid (validator, value)
273+ end
274+ for value in rejected
275+ @test ! isvalid (validator, value)
276+ end
277+ end
278+ end
279+ end
280+
155281@testset " Webhook lifecycle, isolation, and rotation" begin
156282 fixture = event_fixture ()
157283 params = event_params (arguments= Dict (" resource" => " shared" , " metadata" => Dict (" z" => 1.0 , " a" => [true , nothing , " λ" ])))
0 commit comments