From d0683f0b6da8bdca49461ce296a93915edf2ef98 Mon Sep 17 00:00:00 2001 From: Hare Date: Tue, 29 Sep 2026 00:03:55 +0900 Subject: [PATCH] feat(host): resolve published interface references --- crates/wip-host/src/lib.rs | 12 ++++++++++++ crates/wip-host/tests/host.rs | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/crates/wip-host/src/lib.rs b/crates/wip-host/src/lib.rs index 935e8ce..a6acb19 100644 --- a/crates/wip-host/src/lib.rs +++ b/crates/wip-host/src/lib.rs @@ -208,6 +208,18 @@ impl InterfaceRegistry { }) } + /// Resolves a transport-provided opaque reference string in this registry. + /// + /// The returned value is registry-scoped and suitable for observation or a + /// qualified [`CallRequest`]. Unknown or foreign references return `None`; + /// constructing arbitrary `InterfaceRef` values is intentionally not part of + /// the public API. + #[must_use] + pub fn resolve(&self, reference: &str) -> Option { + let reference = InterfaceRef(reference.to_owned()); + self.artifacts.contains_key(&reference).then_some(reference) + } + /// Observes the descriptor and optional validator for an opaque reference. #[must_use] pub fn observe(&self, reference: &InterfaceRef) -> Option { diff --git a/crates/wip-host/tests/host.rs b/crates/wip-host/tests/host.rs index 49439c7..8c5c386 100644 --- a/crates/wip-host/tests/host.rs +++ b/crates/wip-host/tests/host.rs @@ -163,6 +163,11 @@ fn registry_exposes_opaque_validated_descriptor_observations() { let reader = registry.register(ReaderDefinition, None).unwrap(); assert_ne!(reader.reference().as_str(), "Reader"); + assert_eq!( + registry.resolve(reader.reference().as_str()).as_ref(), + Some(reader.reference()) + ); + assert!(registry.resolve("wip-interface:unknown:0").is_none()); let observation = registry.observe(reader.reference()).unwrap(); assert_eq!(observation.reference, *reader.reference()); assert_eq!(observation.descriptor.name, reader.reference().as_str()); @@ -174,6 +179,11 @@ fn registry_exposes_opaque_validated_descriptor_observations() { let mut other_registry = InterfaceRegistry::new(); let other_reader = other_registry.register(ReaderDefinition, None).unwrap(); assert_ne!(reader.reference(), other_reader.reference()); + assert!( + registry + .resolve(other_reader.reference().as_str()) + .is_none() + ); } #[test]