Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(cli): refuse empty flags on project access and grants

Vinícius DS Andrade8d63bed9c9d2
diff --git a/crates/ai-memory-cli/src/commands/grant.rs b/crates/ai-memory-cli/src/commands/grant.rs
index 5748ff2c..051a88f0 100644
--- a/crates/ai-memory-cli/src/commands/grant.rs
+++ b/crates/ai-memory-cli/src/commands/grant.rs
@@ -119,8 +119,11 @@ pub async fn list_for_user(ep: &ServerEndpoint, args: &UserGrantsArgs) -> Result
/// `ai-memory project grants --workspace W --project P`.
///
/// # Errors
-/// Transport failures, a non-root token, or an unknown project.
+/// Empty `--workspace` or `--project`; transport failures, a non-root token,
+/// or an unknown project.
pub async fn list_for_project(ep: &ServerEndpoint, args: &ProjectGrantsArgs) -> Result<()> {
+ super::refuse_empty_explicit(Some(args.workspace.as_str()), "--workspace")?;
+ super::refuse_empty_explicit(Some(args.project.as_str()), "--project")?;
let resp: GrantList = get_json(
ep,
"/admin/projects/grants",
@@ -273,4 +276,38 @@ mod tests {
);
}
}
+
+ fn grants_args() -> ProjectGrantsArgs {
+ ProjectGrantsArgs {
+ workspace: "default".into(),
+ project: "app".into(),
+ json: false,
+ }
+ }
+
+ fn dead_ep() -> ServerEndpoint {
+ ServerEndpoint::from_pair(Some("http://127.0.0.1:1".into()), None)
+ }
+
+ #[tokio::test]
+ async fn an_empty_project_flag_is_refused_before_listing_grants() {
+ let mut a = grants_args();
+ a.project = " ".into();
+ let error = list_for_project(&dead_ep(), &a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--project was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+
+ #[tokio::test]
+ async fn an_empty_workspace_flag_is_refused_before_listing_grants() {
+ let mut a = grants_args();
+ a.workspace = "".into();
+ let error = list_for_project(&dead_ep(), &a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--workspace was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
}
diff --git a/crates/ai-memory-cli/src/commands/project.rs b/crates/ai-memory-cli/src/commands/project.rs
index a2e29948..47dcd8a3 100644
--- a/crates/ai-memory-cli/src/commands/project.rs
+++ b/crates/ai-memory-cli/src/commands/project.rs
@@ -16,8 +16,9 @@ use crate::http_client::{ServerEndpoint, post_json};
/// Dispatch a `project` subcommand.
///
/// # Errors
-/// Local marker initialization failures, or a transport failure, non-root
-/// token, unknown project, or invalid mode for a server-side action.
+/// Local marker initialization failures, an empty `--workspace`, `--project`,
+/// or `--mode`, or a transport failure, non-root token, unknown project, or
+/// invalid mode for a server-side action.
pub async fn run(config: &Config, args: ProjectArgs) -> Result<()> {
match args.command {
ProjectCommand::Init(args) => crate::commands::project_init::run(config, args),
@@ -41,6 +42,9 @@ struct AccessResponse {
}
async fn access(ep: &ServerEndpoint, args: ProjectAccessArgs) -> Result<()> {
+ super::refuse_empty_explicit(Some(args.workspace.as_str()), "--workspace")?;
+ super::refuse_empty_explicit(Some(args.project.as_str()), "--project")?;
+ super::refuse_empty_explicit(Some(args.mode.as_str()), "--mode")?;
let resp: AccessResponse = post_json(
ep,
"/admin/projects/access",
@@ -72,3 +76,53 @@ async fn access(ep: &ServerEndpoint, args: ProjectAccessArgs) -> Result<()> {
}
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn access_args() -> ProjectAccessArgs {
+ ProjectAccessArgs {
+ workspace: "default".into(),
+ project: "app".into(),
+ mode: "restricted".into(),
+ }
+ }
+
+ fn dead_ep() -> ServerEndpoint {
+ ServerEndpoint::from_pair(Some("http://127.0.0.1:1".into()), None)
+ }
+
+ #[tokio::test]
+ async fn an_empty_project_flag_is_refused_before_any_request() {
+ let mut a = access_args();
+ a.project = " ".into();
+ let error = access(&dead_ep(), a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--project was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+
+ #[tokio::test]
+ async fn an_empty_workspace_flag_is_refused_before_any_request() {
+ let mut a = access_args();
+ a.workspace = "".into();
+ let error = access(&dead_ep(), a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--workspace was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+
+ #[tokio::test]
+ async fn an_empty_mode_flag_is_refused_before_any_request() {
+ let mut a = access_args();
+ a.mode = " ".into();
+ let error = access(&dead_ep(), a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--mode was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+}