fix(interface): preserve operation item uniqueness

Disambiguate generated argument types when distinct operation names normalize to the same PascalCase form, and add the requested Number round-trip and collision regression coverage.
This commit is contained in:
2026-09-28 23:21:13 +09:00
parent 18ac8844b0
commit 3f94d48f04
3 changed files with 79 additions and 0 deletions
+11
View File
@@ -67,6 +67,17 @@ fn supported_values_round_trip() {
assert!(fields.iter().all(|field| field.name != "priority"));
assert_eq!(Request::decode(encoded).unwrap(), request);
let number = 42.5_f64;
assert_eq!(f64::type_expr(), TypeExpr::Number);
assert_eq!(f64::decode(number.encode().unwrap()).unwrap(), number);
let narrow_number = 1.5_f32;
assert_eq!(f32::type_expr(), TypeExpr::Number);
assert_eq!(
f32::decode(narrow_number.encode().unwrap()).unwrap(),
narrow_number
);
for color in [Color::Red, Color::Blue] {
let encoded = color.clone().encode().unwrap();
let decoded = Color::decode(encoded).unwrap();
+38
View File
@@ -216,3 +216,41 @@ fn typed_dispatch_validates_decodes_invokes_encodes_and_validates() {
let unknown = CatalogDefinition::dispatch(&AcceptingCatalog, "missing", vec![]).unwrap_err();
assert!(matches!(unknown, DispatchError::UnknownOperation(name) if name == "missing"));
}
/// Operations whose distinct source names normalize to the same PascalCase.
#[interface]
pub trait DistinctOperations {
/// Returns the first item marker.
fn item(&self) -> OperationResult<String>;
/// Returns the underscored item marker.
fn item_(&self) -> OperationResult<String>;
}
struct DistinctImplementation;
impl DistinctOperations for DistinctImplementation {
fn item(&self) -> OperationResult<String> {
Ok("item".into())
}
fn item_(&self) -> OperationResult<String> {
Ok("item_".into())
}
}
#[test]
fn distinct_operation_names_always_generate_distinct_public_items() {
let descriptor = DistinctOperationsDefinition::descriptor();
assert_eq!(descriptor.operations[0].name, "item");
assert_eq!(descriptor.operations[1].name, "item_");
let first = DistinctOperationsDefinition::dispatch(&DistinctImplementation, "item", vec![])
.unwrap()
.unwrap();
let second = DistinctOperationsDefinition::dispatch(&DistinctImplementation, "item_", vec![])
.unwrap()
.unwrap();
assert_eq!(first, Value::String("item".into()));
assert_eq!(second, Value::String("item_".into()));
}