Skip to content

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

Rust

test(cli): cover every empty message coordinate

AkitaOnRailsad92b2be6ba6
diff --git a/crates/ai-memory-cli/src/commands/message.rs b/crates/ai-memory-cli/src/commands/message.rs
index 285f09a6..5d9ed3c6 100644
--- a/crates/ai-memory-cli/src/commands/message.rs
+++ b/crates/ai-memory-cli/src/commands/message.rs
@@ -66,8 +66,9 @@ struct CancelMessagesResponse {
/// Dispatch `ai-memory message`.
///
/// # Errors
-/// Returns [`anyhow::Error`] when the scope cannot be resolved, stdin cannot
-/// be read, the server is unreachable, or it answers non-2xx.
+/// Returns [`anyhow::Error`] when an explicit mutating scope or target is
+/// empty, the scope cannot be resolved, stdin cannot be read, the server is
+/// unreachable, or it answers non-2xx.
pub async fn run(config: &Config, args: MessageArgs) -> Result<()> {
match args.command {
MessageCommand::Send(args) => send(config, args).await,
@@ -471,9 +472,7 @@ mod tests {
};
let error = pop(&config, a).await.unwrap_err();
assert!(
- error
- .to_string()
- .contains("--project was passed empty"),
+ error.to_string().contains("--project was passed empty"),
"unexpected error: {error}"
);
}
@@ -506,9 +505,7 @@ mod tests {
};
let error = cancel(&config, a).await.unwrap_err();
assert!(
- error
- .to_string()
- .contains("--workspace was passed empty"),
+ error.to_string().contains("--workspace was passed empty"),
"unexpected error: {error}"
);
}
@@ -547,10 +544,103 @@ mod tests {
json: false,
};
let error = send(&config, a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--to-project was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+
+ #[tokio::test]
+ async fn send_refuses_empty_workspace_coordinates_before_reading_stdin() {
+ let config = Config::default();
+ let mut a = MessageSendArgs {
+ from_workspace: Some(" ".into()),
+ from_project: None,
+ to_workspace: "team".into(),
+ to_project: "api".into(),
+ subject: None,
+ body: None,
+ json: false,
+ };
+ let error = send(&config, a).await.unwrap_err();
+ assert!(
+ error
+ .to_string()
+ .contains("--from-workspace was passed empty"),
+ "unexpected error: {error}"
+ );
+
+ a = MessageSendArgs {
+ from_workspace: None,
+ from_project: None,
+ to_workspace: String::new(),
+ to_project: "api".into(),
+ subject: None,
+ body: None,
+ json: false,
+ };
+ let error = send(&config, a).await.unwrap_err();
assert!(
error
.to_string()
- .contains("--to-project was passed empty"),
+ .contains("--to-workspace was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+
+ #[tokio::test]
+ async fn pop_refuses_empty_workspace_before_any_request() {
+ let error = pop(
+ &Config::default(),
+ MessagePopArgs {
+ workspace: Some(String::new()),
+ project: None,
+ id: None,
+ json: false,
+ },
+ )
+ .await
+ .unwrap_err();
+ assert!(
+ error.to_string().contains("--workspace was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+
+ #[tokio::test]
+ async fn cancel_refuses_empty_project_and_id_before_any_request() {
+ let config = Config::default();
+ let error = cancel(
+ &config,
+ MessageCancelArgs {
+ workspace: None,
+ project: Some(" ".into()),
+ id: None,
+ all: true,
+ json: false,
+ },
+ )
+ .await
+ .unwrap_err();
+ assert!(
+ error.to_string().contains("--project was passed empty"),
+ "unexpected error: {error}"
+ );
+
+ let error = cancel(
+ &config,
+ MessageCancelArgs {
+ workspace: None,
+ project: None,
+ id: Some(String::new()),
+ all: false,
+ json: false,
+ },
+ )
+ .await
+ .unwrap_err();
+ assert!(
+ error.to_string().contains("--id was passed empty"),
"unexpected error: {error}"
);
}
diff --git a/crates/ai-memory-cli/src/commands/mod.rs b/crates/ai-memory-cli/src/commands/mod.rs
index a88a750a..ee6307cc 100644
--- a/crates/ai-memory-cli/src/commands/mod.rs
+++ b/crates/ai-memory-cli/src/commands/mod.rs
@@ -167,14 +167,15 @@ pub(crate) fn humanize_age_secs(seconds: i64) -> String {
format!("{value} {unit}{} ago", if value == 1 { "" } else { "s" })
}
-/// Refuse an explicitly empty scope flag on a destructive command.
+/// Refuse an explicitly empty scope or target flag on a mutating command.
///
/// [`resolve_scope`] treats an empty string as absent, so a harness that
/// fills an unset variable with `""` still resolves the scope it would have
/// resolved without the flag. That is the right reading for a read, and the
-/// wrong one for a delete: `--project "" --confirm` would aim the purge at
-/// whatever the current directory resolves to, which is exactly the target
-/// nobody typed. These commands ask for the flag to be omitted instead.
+/// wrong one for a mutation: `--project "" --confirm` would aim a purge at
+/// whatever the current directory resolves to, and an empty message scope
+/// would claim or cancel mail there. These commands ask for the flag to be
+/// omitted instead.
///
/// # Errors
/// Returns an error naming `flag` when it was passed as an empty or
@@ -182,8 +183,8 @@ pub(crate) fn humanize_age_secs(seconds: i64) -> String {
pub(crate) fn refuse_empty_explicit(value: Option<&str>, flag: &str) -> Result<()> {
if value.is_some_and(|v| v.trim().is_empty()) {
bail!(
- "{flag} was passed empty; omit it to use the scope this directory resolves to, \
- or name the project explicitly"
+ "{flag} was passed empty; provide a non-empty value, or omit an optional scope \
+ flag to use the project this directory resolves to"
);
}
Ok(())