From 89721987d86d361b5bae34f739a8050714d1e53d Mon Sep 17 00:00:00 2001 From: Brooks Townsend Date: Thu, 2 Jan 2025 11:43:16 -0500 Subject: [PATCH 1/2] fix(types): warn on unknown interface Signed-off-by: Brooks Townsend --- crates/wadm-types/src/validation.rs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/crates/wadm-types/src/validation.rs b/crates/wadm-types/src/validation.rs index e0b53012..a5be42ab 100644 --- a/crates/wadm-types/src/validation.rs +++ b/crates/wadm-types/src/validation.rs @@ -160,9 +160,10 @@ fn is_invalid_known_interface( }; // Unknown interface inside known namespace and package is probably a bug if !iface_lookup.contains_key(interface) { - // Unknown package inside a known interface we control is probably a bug + // Unknown package inside a known interface we control is probably a bug, but may be + // a new interface we don't know about yet return vec![ValidationFailure::new( - ValidationFailureLevel::Error, + ValidationFailureLevel::Warning, format!("unrecognized interface [{namespace}:{package}/{interface}]"), )]; } @@ -702,22 +703,13 @@ pub fn validate_link_configs(manifest: &Manifest) -> Vec { let mut failures = Vec::new(); let mut link_config_names = HashSet::new(); for link_trait in manifest.links() { - if let TraitProperty::Link(LinkProperty { - target, - source, - .. - }) = &link_trait.properties { + if let TraitProperty::Link(LinkProperty { target, source, .. }) = &link_trait.properties { for config in target.config.iter() { // Check if config name is unique - if !link_config_names.insert(( - config.name.clone(), - )) { + if !link_config_names.insert((config.name.clone(),)) { failures.push(ValidationFailure::new( ValidationFailureLevel::Error, - format!( - "Duplicate link config name found: '{}'", - config.name - ), + format!("Duplicate link config name found: '{}'", config.name), )); } } @@ -725,15 +717,10 @@ pub fn validate_link_configs(manifest: &Manifest) -> Vec { if let Some(source) = source { for config in source.config.iter() { // Check if config name is unique - if !link_config_names.insert(( - config.name.clone(), - )) { + if !link_config_names.insert((config.name.clone(),)) { failures.push(ValidationFailure::new( ValidationFailureLevel::Error, - format!( - "Duplicate link config name found: '{}'", - config.name - ), + format!("Duplicate link config name found: '{}'", config.name), )); } } From a18accaa69507f781b20656a9df7001749743480 Mon Sep 17 00:00:00 2001 From: Brooks Townsend Date: Thu, 2 Jan 2025 15:33:13 -0500 Subject: [PATCH 2/2] test(validation): allow misnamed interface as warning Signed-off-by: Brooks Townsend --- tests/validation.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/validation.rs b/tests/validation.rs index 7b26ea83..3c825f0b 100644 --- a/tests/validation.rs +++ b/tests/validation.rs @@ -44,12 +44,12 @@ async fn validate_misnamed_interface() -> Result<()> { !failures.is_empty() && failures .iter() - .all(|f| f.level == ValidationFailureLevel::Error), - "failures present, all errors" + .all(|f| f.level == ValidationFailureLevel::Warning), + "failures present, all warnings" ); assert!( - !failures.valid(), - "manifest should be invalid (misnamed interface w/ right namespace & package is probably a bug)" + failures.valid(), + "manifest should be valid (misnamed interface w/ right namespace & package is probably a bug but might be intentional)" ); Ok(()) } @@ -126,8 +126,8 @@ async fn validate_link_config_names() -> Result<()> { validate_manifest_file("./tests/fixtures/manifests/duplicate_link_config_names.wadm.yaml") .await .context("failed to validate manifest")?; - let expected_errors = 3; - assert!( + let expected_errors = 3; + assert!( !failures.is_empty() && failures .iter() @@ -135,10 +135,10 @@ async fn validate_link_config_names() -> Result<()> { && failures.len() == expected_errors, "expected {} errors because manifest contains {} duplicated link config names, instead {} errors were found", expected_errors, expected_errors, failures.len().to_string() ); - assert!( - !failures.valid(), - "manifest should be invalid (duplicated link config names lead to a dead loop)" - ); + assert!( + !failures.valid(), + "manifest should be invalid (duplicated link config names lead to a dead loop)" + ); Ok(()) }