Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

Seanaye/chore/add tests (#3416)

Sean Aye1da6d5a1f3c2
diff --git a/.github/workflows/code-check-cloud-storage.yml b/.github/workflows/code-check-cloud-storage.yml
index 1183fff80d..6c82e1a938 100644
--- a/.github/workflows/code-check-cloud-storage.yml
+++ b/.github/workflows/code-check-cloud-storage.yml
@@ -278,7 +278,7 @@ jobs:
if [ -n "$NEXTEST_FILTER" ]; then
args+=(-E "$NEXTEST_FILTER")
fi
- cargo nextest run --no-tests=pass "${args[@]}"
+ cargo nextest run "${args[@]}"
- name: show sccache stats
if: always()
env:
diff --git a/rust/cloud-storage/mcp_service/src/tool_service.rs b/rust/cloud-storage/mcp_service/src/tool_service.rs
index 993c09a949..dc21ed03aa 100644
--- a/rust/cloud-storage/mcp_service/src/tool_service.rs
+++ b/rust/cloud-storage/mcp_service/src/tool_service.rs
@@ -20,8 +20,36 @@ impl<Context> AuthenticatedToolService<Context> {
pub fn new(toolset: Arc<AsyncToolCollection<Context>>, context: Context) -> Self {
Self { toolset, context }
}
+
+ fn tool_definitions(&self) -> Vec<Tool> {
+ self.toolset
+ .tools
+ .iter()
+ .map(|(key, value)| {
+ Tool::new(
+ key.to_owned(),
+ value.description.to_owned(),
+ Arc::new(value.input_schema.clone()),
+ )
+ })
+ .collect()
+ }
+
+ fn authenticated_user_id(
+ extensions: &rmcp::model::Extensions,
+ ) -> Result<MacroUserIdStr<'static>, rmcp::ErrorData> {
+ extensions
+ .get::<http::request::Parts>()
+ .and_then(|parts| parts.extensions.get::<MacroUserIdStr<'static>>().cloned())
+ .ok_or_else(|| {
+ rmcp::ErrorData::internal_error("missing user identity — is auth configured?", None)
+ })
+ }
}
+#[cfg(test)]
+mod test;
+
impl<Context> ServerHandler for AuthenticatedToolService<Context>
where
Context: Clone + Send + Sync + 'static,
@@ -52,21 +80,8 @@ where
_request: Option<PaginatedRequestParams>,
_context: rmcp::service::RequestContext<rmcp::RoleServer>,
) -> Result<ListToolsResult, rmcp::ErrorData> {
- let tools = self
- .toolset
- .tools
- .iter()
- .map(|(key, value)| {
- Tool::new(
- key.to_owned(),
- value.description.to_owned(),
- Arc::new(value.input_schema.clone()),
- )
- })
- .collect::<Vec<_>>();
-
Ok(ListToolsResult {
- tools,
+ tools: self.tool_definitions(),
..Default::default()
})
}
@@ -76,13 +91,7 @@ where
request: rmcp::model::CallToolRequestParams,
context: rmcp::service::RequestContext<rmcp::RoleServer>,
) -> Result<rmcp::model::CallToolResult, rmcp::ErrorData> {
- let user_id = context
- .extensions
- .get::<http::request::Parts>()
- .and_then(|parts| parts.extensions.get::<MacroUserIdStr<'static>>().cloned())
- .ok_or_else(|| {
- rmcp::ErrorData::internal_error("missing user identity — is auth configured?", None)
- })?;
+ let user_id = Self::authenticated_user_id(&context.extensions)?;
let request_context = RequestContext { user_id };
diff --git a/rust/cloud-storage/mcp_service/src/tool_service/test.rs b/rust/cloud-storage/mcp_service/src/tool_service/test.rs
new file mode 100644
index 0000000000..d89da6fdc3
--- /dev/null
+++ b/rust/cloud-storage/mcp_service/src/tool_service/test.rs
@@ -0,0 +1,89 @@
+use super::*;
+use ai_toolset::AsyncToolCollection;
+use rmcp::{handler::server::ServerHandler, model::ErrorCode};
+
+fn empty_service() -> AuthenticatedToolService<()> {
+ AuthenticatedToolService::new(Arc::new(AsyncToolCollection::new()), ())
+}
+
+#[test]
+fn server_info_advertises_macro_tools() {
+ let info = empty_service().get_info();
+
+ assert_eq!(info.server_info.name, "macro-tools");
+ assert_eq!(info.server_info.title.as_deref(), Some("Macro"));
+ assert_eq!(info.server_info.version, env!("CARGO_PKG_VERSION"));
+ assert!(
+ info.server_info
+ .description
+ .as_deref()
+ .is_some_and(|description| description.contains("documents, emails, and messages"))
+ );
+ assert!(info.capabilities.tools.is_some());
+}
+
+#[test]
+fn server_instructions_describe_available_workflows() {
+ let instructions = empty_service()
+ .get_info()
+ .instructions
+ .expect("server should provide MCP instructions");
+
+ for expected_text in [
+ "Macro workspace",
+ "ContentSearch",
+ "NameSearch",
+ "ReadContent",
+ "ReadMetadata",
+ "ReadThread",
+ "CreateDocument",
+ "ListEntities",
+ ] {
+ assert!(
+ instructions.contains(expected_text),
+ "instructions should mention {expected_text}"
+ );
+ }
+}
+
+#[test]
+fn empty_toolset_lists_no_tools() {
+ assert!(empty_service().tool_definitions().is_empty());
+}
+
+#[test]
+fn authenticated_user_id_is_read_from_http_request_parts() {
+ let expected_user_id = MacroUserIdStr::try_from_email("[email protected]").unwrap();
+ let mut parts = http::Request::new(()).into_parts().0;
+ parts.extensions.insert(expected_user_id.clone());
+
+ let mut extensions = rmcp::model::Extensions::new();
+ extensions.insert(parts);
+
+ let user_id = AuthenticatedToolService::<()>::authenticated_user_id(&extensions).unwrap();
+
+ assert_eq!(user_id, expected_user_id);
+}
+
+#[test]
+fn authenticated_user_id_requires_request_parts() {
+ let error =
+ AuthenticatedToolService::<()>::authenticated_user_id(&rmcp::model::Extensions::new())
+ .expect_err("missing request parts should fail auth extraction");
+
+ assert_eq!(error.code, ErrorCode::INTERNAL_ERROR);
+ assert_eq!(error.message, "missing user identity — is auth configured?");
+}
+
+#[test]
+fn authenticated_user_id_requires_user_extension_inside_request_parts() {
+ let parts = http::Request::new(()).into_parts().0;
+ let mut extensions = rmcp::model::Extensions::new();
+ extensions.insert(parts);
+
+ let error = AuthenticatedToolService::<()>::authenticated_user_id(&extensions)
+ .expect_err("missing user id should fail auth extraction");
+
+ assert_eq!(error.code, ErrorCode::INTERNAL_ERROR);
+ assert_eq!(error.message, "missing user identity — is auth configured?");
+}