@@ -64,15 +64,23 @@ pub struct NegotiatedExtension {
6464#[ derive( Debug , Error , PartialEq , Eq ) ]
6565pub enum NegotiationError {
6666 #[ error(
67- "{family} extension '{name}' did not provide protocol metadata; upgrade the extension to a version that supports OpenShell extension negotiation"
67+ "{family} extension '{name}' did not provide protocol metadata; upgrade the extension to a version that supports OpenShell extension negotiation (expected {expected}) "
6868 ) ]
69- MissingMetadata { family : & ' static str , name : String } ,
69+ MissingMetadata {
70+ family : & ' static str ,
71+ name : String ,
72+ expected : String ,
73+ } ,
7074 #[ error(
7175 "gateway did not provide protocol metadata to {family} extension '{name}'; upgrade the gateway and extension together"
7276 ) ]
7377 MissingGatewayMetadata { family : & ' static str , name : String } ,
74- #[ error( "{family} extension '{name}' did not provide a protocol version" ) ]
75- MissingProtocolVersion { family : & ' static str , name : String } ,
78+ #[ error( "{family} extension '{name}' did not provide a protocol version (expected {expected})" ) ]
79+ MissingProtocolVersion {
80+ family : & ' static str ,
81+ name : String ,
82+ expected : String ,
83+ } ,
7684 #[ error(
7785 "{family} extension '{name}' uses unsupported protocol {remote_major}.{remote_minor}; gateway supports {local_major}.{local_minor}"
7886 ) ]
@@ -148,6 +156,14 @@ pub fn extension_metadata(
148156 }
149157}
150158
159+ /// Protocol version and base capability an extension of `family` must declare.
160+ fn expected_contract ( family : ExtensionFamily ) -> String {
161+ format ! (
162+ "protocol {PROTOCOL_MAJOR}.{PROTOCOL_MINOR} and capability {}" ,
163+ family. contract_capability( )
164+ )
165+ }
166+
151167pub fn negotiate (
152168 family : ExtensionFamily ,
153169 configured_name : impl Into < String > ,
@@ -156,20 +172,24 @@ pub fn negotiate(
156172) -> Result < NegotiatedExtension , NegotiationError > {
157173 let configured_name = configured_name. into ( ) ;
158174 let family_name = family. as_str ( ) ;
175+ let expected = expected_contract ( family) ;
159176 let extension = extension. ok_or_else ( || NegotiationError :: MissingMetadata {
160177 family : family_name,
161178 name : configured_name. clone ( ) ,
179+ expected : expected. clone ( ) ,
162180 } ) ?;
163181 let version = extension. protocol_version . as_ref ( ) . ok_or_else ( || {
164182 NegotiationError :: MissingProtocolVersion {
165183 family : family_name,
166184 name : configured_name. clone ( ) ,
185+ expected : expected. clone ( ) ,
167186 }
168187 } ) ?;
169188 let gateway_version = gateway. protocol_version . as_ref ( ) . ok_or_else ( || {
170189 NegotiationError :: MissingProtocolVersion {
171190 family : family_name,
172191 name : "gateway" . to_string ( ) ,
192+ expected,
173193 }
174194 } ) ?;
175195 if version. major != gateway_version. major {
@@ -401,10 +421,13 @@ mod tests {
401421 #[ test]
402422 fn missing_metadata_and_major_skew_are_actionable ( ) {
403423 let ( gateway, mut extension) = compatible ( ) ;
404- assert ! ( matches!(
405- negotiate( ExtensionFamily :: Compute , "example" , & gateway, None ) ,
406- Err ( NegotiationError :: MissingMetadata { .. } )
407- ) ) ;
424+ let missing = negotiate ( ExtensionFamily :: Compute , "example" , & gateway, None ) . unwrap_err ( ) ;
425+ assert ! ( matches!( missing, NegotiationError :: MissingMetadata { .. } ) ) ;
426+ assert ! (
427+ missing
428+ . to_string( )
429+ . contains( "protocol 1.0 and capability openshell.compute.contract" )
430+ ) ;
408431 extension. protocol_version . as_mut ( ) . unwrap ( ) . major = 2 ;
409432 assert ! ( matches!(
410433 negotiate(
@@ -417,6 +440,28 @@ mod tests {
417440 ) ) ;
418441 }
419442
443+ #[ test]
444+ fn missing_protocol_version_names_the_expected_contract ( ) {
445+ let ( gateway, mut extension) = compatible ( ) ;
446+ extension. protocol_version = None ;
447+ let error = negotiate (
448+ ExtensionFamily :: Compute ,
449+ "example" ,
450+ & gateway,
451+ Some ( extension) ,
452+ )
453+ . unwrap_err ( ) ;
454+ assert ! ( matches!(
455+ error,
456+ NegotiationError :: MissingProtocolVersion { .. }
457+ ) ) ;
458+ assert ! (
459+ error
460+ . to_string( )
461+ . contains( "protocol 1.0 and capability openshell.compute.contract" )
462+ ) ;
463+ }
464+
420465 #[ test]
421466 fn both_peers_require_capabilities_from_the_other ( ) {
422467 let ( mut gateway, mut extension) = compatible ( ) ;
0 commit comments