diff --git a/crates/runvil-plugin-sdk/src/names.rs b/crates/runvil-plugin-sdk/src/names.rs index c152719..6d00caf 100644 --- a/crates/runvil-plugin-sdk/src/names.rs +++ b/crates/runvil-plugin-sdk/src/names.rs @@ -37,15 +37,16 @@ const fn is_segment(bytes: &[u8], from: usize, to: usize) -> bool { true } -/// Whether `name` is a wire name the Harness accepts: 1 to 64 bytes of -/// ASCII letters, digits, `_`, and `-`. +/// Whether `name` is a wire name the Harness accepts: 1 to 64 bytes +/// starting with an ASCII letter, followed by ASCII letters, digits, `_`, +/// and `-`. #[cfg(any(test, feature = "test-support"))] pub(crate) const fn is_valid_wire_name(name: &str) -> bool { let bytes = name.as_bytes(); - if bytes.is_empty() || bytes.len() > RV_MAX_NAME { + if bytes.is_empty() || bytes.len() > RV_MAX_NAME || !bytes[0].is_ascii_alphabetic() { return false; } - let mut at = 0; + let mut at = 1; while at < bytes.len() { if !matches!(bytes[at], b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9' | b'_' | b'-') { return false; @@ -174,11 +175,21 @@ mod tests { } #[test] - fn a_wire_name_is_ascii_letters_digits_underscores_and_hyphens() { - for name in ["Read", "StrReplace", "web_fetch", "a-b", "0"] { + fn a_wire_name_starts_with_an_ascii_letter_and_holds_letters_digits_underscores_and_hyphens() { + for name in ["Read", "StrReplace", "web_fetch", "a-b", "a0"] { assert!(is_valid_wire_name(name), "{name}"); } - for name in ["", "web/fetch", "a.b", "a b", "café"] { + for name in [ + "", + "0", + "0_fetch", + "_fetch", + "-fetch", + "web/fetch", + "a.b", + "a b", + "café", + ] { assert!(!is_valid_wire_name(name), "{name:?}"); } assert!(is_valid_wire_name(&"a".repeat(RV_MAX_NAME))); diff --git a/crates/runvil-plugin-sdk/src/testing/fixture.rs b/crates/runvil-plugin-sdk/src/testing/fixture.rs index 2cef408..39f2900 100644 --- a/crates/runvil-plugin-sdk/src/testing/fixture.rs +++ b/crates/runvil-plugin-sdk/src/testing/fixture.rs @@ -69,6 +69,8 @@ pub(super) enum Breach { ToolTwice, /// Adds a tool whose wire name has a `/`. WireName, + /// Adds a tool whose wire name starts with a digit instead of an ASCII letter. + WireNameLeadingDigit, /// Adds a tool with an empty description. NoDescription, /// Adds a tool whose parameters are a JSON array. @@ -238,7 +240,11 @@ fn tool_info(breach: Breach) -> RvToolInfo { size: size_field::(), flags: if breach == Breach::ToolFlags { 2 } else { 0 }, name: text_unless(breach, Breach::ToolName, "tool", "Not A Segment"), - wire_name: text_unless(breach, Breach::WireName, "Tool", "web/fetch"), + wire_name: match breach { + Breach::WireName => rv_str("web/fetch"), + Breach::WireNameLeadingDigit => rv_str("0_fetch"), + _ => rv_str("Tool"), + }, description: text_unless(breach, Breach::NoDescription, "A fixture tool.", ""), parameters: text_unless(breach, Breach::Parameters, "{}", "[]"), } diff --git a/crates/runvil-plugin-sdk/src/testing/pack.rs b/crates/runvil-plugin-sdk/src/testing/pack.rs index 1d24df4..b821804 100644 --- a/crates/runvil-plugin-sdk/src/testing/pack.rs +++ b/crates/runvil-plugin-sdk/src/testing/pack.rs @@ -70,7 +70,9 @@ pub(super) unsafe fn add( // SAFETY: as above. let wire_name = unsafe { WIRE_NAME.read(info.wire_name) }?; if !wire_name.is_empty() && !is_valid_wire_name(&wire_name) { - return Err("the tool's wire name is not ASCII letters, digits, `_`, and `-`"); + return Err( + "the tool's wire name must start with an ASCII letter and hold only ASCII letters, digits, `_`, and `-`", + ); } // SAFETY: as above. let description = unsafe { DESCRIPTION.read(info.description) }?; @@ -139,7 +141,11 @@ mod tests { ), ( Breach::WireName, - "the tool's wire name is not ASCII letters, digits, `_`, and `-`", + "the tool's wire name must start with an ASCII letter and hold only ASCII letters, digits, `_`, and `-`", + ), + ( + Breach::WireNameLeadingDigit, + "the tool's wire name must start with an ASCII letter and hold only ASCII letters, digits, `_`, and `-`", ), (Breach::NoDescription, "the tool's description is empty"), ( diff --git a/crates/runvil-plugin-sdk/src/tool.rs b/crates/runvil-plugin-sdk/src/tool.rs index ee1cb5d..d98c5e5 100644 --- a/crates/runvil-plugin-sdk/src/tool.rs +++ b/crates/runvil-plugin-sdk/src/tool.rs @@ -19,9 +19,10 @@ pub struct ToolInfo { /// letters, digits, `-`, `_`, and `.`, such as `fetch`. The Host puts /// the Pack id before it to form the tool's id, as in `url/fetch`. pub name: String, - /// The name a model calls the tool by: 1 to 64 bytes of ASCII letters, - /// digits, `_`, and `-`. `None` lets the Host derive it from the - /// tool's id, as `url_fetch` from `url/fetch`. + /// The name a model calls the tool by: 1 to 64 bytes starting with an + /// ASCII letter, followed by ASCII letters, digits, `_`, and `-`. `None` + /// lets the Host derive it from the tool's id, as `url_fetch` from + /// `url/fetch`. pub wire_name: Option, /// What the tool does, for a model to read: non-empty, at most 65536 /// bytes. diff --git a/crates/runvil-plugin-sys/include/runvil_plugin.h b/crates/runvil-plugin-sys/include/runvil_plugin.h index 3de4671..6c6c5e1 100644 --- a/crates/runvil-plugin-sys/include/runvil_plugin.h +++ b/crates/runvil-plugin-sys/include/runvil_plugin.h @@ -640,9 +640,10 @@ struct RvToolInfo { */ struct RvStr name; /** - * The name a model calls the tool by: 1 to `RV_MAX_NAME` bytes of - * ASCII letters, digits, `_`, and `-`. Empty lets the Host derive it - * from the tool's id, as `url_fetch` from `url/fetch`. + * The name a model calls the tool by: 1 to `RV_MAX_NAME` bytes + * starting with an ASCII letter, followed by ASCII letters, digits, `_`, + * and `-`. Empty lets the Host derive it from the tool's id, as + * `url_fetch` from `url/fetch`. */ struct RvStr wire_name; /** diff --git a/crates/runvil-plugin-sys/src/lib.rs b/crates/runvil-plugin-sys/src/lib.rs index 9301fb5..7966b25 100644 --- a/crates/runvil-plugin-sys/src/lib.rs +++ b/crates/runvil-plugin-sys/src/lib.rs @@ -616,9 +616,10 @@ pub struct RvToolInfo { pub flags: RvToolFlags, /// The tool's name within its Pack: one name segment, such as `fetch`. pub name: RvStr, - /// The name a model calls the tool by: 1 to [`RV_MAX_NAME`] bytes of - /// ASCII letters, digits, `_`, and `-`. Empty lets the Host derive it - /// from the tool's id, as `url_fetch` from `url/fetch`. + /// The name a model calls the tool by: 1 to [`RV_MAX_NAME`] bytes + /// starting with an ASCII letter, followed by ASCII letters, digits, `_`, + /// and `-`. Empty lets the Host derive it from the tool's id, as + /// `url_fetch` from `url/fetch`. pub wire_name: RvStr, /// What the tool does, for a model to read: non-empty, at most /// [`RV_MAX_TOOL_TEXT`] bytes.