README Source History Refs Reviews Compare Notes Search Review guide Pin the two wire shapes consumers will key off (#138) 86589ba37e2a15faa2c3337cfe275a637648d8f6
Oliver Jan Krylow <oliver@bugabinga.net > · 26 Jul 2026
SSH signature · not checked
Browse files Compare with HEAD
Both shapes were covered only by round-trips, and a round-trip passes just as
happily after a rename because encoder and decoder move together. §7.5's
MuxProvider reads `ProviderError`'s `kind` string to decide failover, so a
silent rename turns classification into a default while every existing test
stays green.
The first attempt reproduced the same fault inside the fix: its CBOR test
round-tripped a definition against itself, which is invariant to
`#[serde(flatten)]`. It now decodes to a CBOR value and asserts the spec's
fields sit at the top level with no `spec` key — removing the attribute fails
it, verified both ways. The kind list became a wildcard-free match so an eighth
variant stops the test compiling rather than shipping unpinned.
`smith/src/provider.rs` and `smith/src/tool.rs`, two tests, 22 total.
Closes #133 Changed files (2) Diff layout Auto Unified Split
smith/src/provider.rs Modified +52 / −0 text lines
229 229 assert_eq! (restored, events); assert_eq! (restored, events);
238 + fn expected_kind (error: & ProviderError) -> &'static str {240 + ProviderError::RateLimit(_ ) => "rate_limit" ,241 + ProviderError::AuthFailed(_ ) => "auth_failed" ,242 + ProviderError::Network(_ ) => "network" ,243 + ProviderError::ServerError(_ ) => "server_error" ,244 + ProviderError::InvalidRequest(_ ) => "invalid_request" ,245 + ProviderError::ModelNotFound(_ ) => "model_not_found" ,246 + ProviderError::Timeout(_ ) => "timeout" ,251 + fn the_provider_error_wire_shape_is_pinned () {258 + serde_json::to_value(ProviderError::RateLimit("slow down" .to_owned ())).unwrap ();261 + serde_json::json! ({ "kind" : "rate_limit" , "message" : "slow down" })265 + ProviderError::RateLimit(String ::new()),266 + ProviderError::AuthFailed(String ::new()),267 + ProviderError::Network(String ::new()),268 + ProviderError::ServerError(String ::new()),269 + ProviderError::InvalidRequest(String ::new()),270 + ProviderError::ModelNotFound(String ::new()),271 + ProviderError::Timeout(String ::new()),274 + let encoded = serde_json::to_value(error).unwrap ();276 + encoded.get ("kind" ).and_then (serde_json::Value::as_str),277 + Some (expected_kind (error)),278 + "{error:?} must stay on the wire as {}" ,279 + expected_kind (error)233 285 fn provider_errors_carry_their_message () { fn provider_errors_carry_their_message () {smith/src/tool.rs Modified +35 / −0 text lines
209 209 assert_eq! (restored, definition); assert_eq! (restored, definition);
213 + fn a_definition_flattens_through_cbor_too () {224 + let definition = Echo.definition ();225 + let mut bytes = Vec ::new();226 + ciborium::into_writer(& definition, &mut bytes).unwrap ();228 + let encoded: ciborium::value::Value = ciborium::from_reader(bytes.as_slice ()).unwrap ();229 + let map = encoded.as_map ().unwrap ();230 + let keys: Vec <&str > = map.iter ().filter_map (|(key, _)| key.as_text ()).collect ();233 + ! keys.contains (& "spec" ),234 + "the spec must flatten, not nest: {keys:?}" 236 + for expected in ["name" , "description" , "parameters" , "execution_mode" ] {238 + keys.contains (& expected),239 + "{expected} must sit at the top level: {keys:?}" 243 + let restored: ToolDefinition = ciborium::from_reader(bytes.as_slice ()).unwrap ();244 + assert_eq! (restored, definition);213 248 fn tools_are_sequential_unless_they_say_otherwise () { fn tools_are_sequential_unless_they_say_otherwise () {214 249 assert_eq! (ToolExecutionMode::default(), ToolExecutionMode::Sequential); assert_eq! (ToolExecutionMode::default(), ToolExecutionMode::Sequential);