Skip to content

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

Rust

fix(cli): reject empty restore-page targets

AkitaOnRails0e5488073d70
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fbdb0347..c77ed3de 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,9 @@ version in [`docs/changelog/`](docs/changelog/):
### Fixed
+- `ai-memory restore-page` now refuses empty or whitespace-only `--path` and
+ `--from` values before resolving scope, authentication, or sending a request
+ to the server (#1764).
- `ai-memory message` subcommands (`send`, `pop`, and `cancel`) now refuse
explicitly empty scope flags and targets before reading stdin or sending
any request to the server (#1761).
diff --git a/crates/ai-memory-cli/src/commands/restore_page.rs b/crates/ai-memory-cli/src/commands/restore_page.rs
index 166e7630..100faf59 100644
--- a/crates/ai-memory-cli/src/commands/restore_page.rs
+++ b/crates/ai-memory-cli/src/commands/restore_page.rs
@@ -1,6 +1,6 @@
//! `ai-memory restore-page` — restore one wiki page from a git checkpoint.
-use anyhow::{Context, Result};
+use anyhow::{Context, Result, bail};
use serde::{Deserialize, Serialize};
use crate::cli::RestorePageArgs;
@@ -29,12 +29,18 @@ struct RestorePageResponse {
/// Run the `restore-page` subcommand.
///
/// # Errors
-/// Returns an error if an explicit scope flag is empty, the server is
-/// unreachable, the checkpoint/path cannot be restored, or the restored page
-/// cannot be reindexed.
+/// Returns an error if an explicit scope flag, `--path`, or `--from` is empty;
+/// the server is unreachable; the checkpoint/path cannot be restored; or the
+/// restored page cannot be reindexed.
pub async fn run(config: &Config, args: RestorePageArgs) -> Result<()> {
super::refuse_empty_explicit(args.workspace.as_deref(), "--workspace")?;
super::refuse_empty_explicit(args.project.as_deref(), "--project")?;
+ if args.path.trim().is_empty() {
+ bail!("--path was passed empty; specify the wiki page path to restore");
+ }
+ if args.from.trim().is_empty() {
+ bail!("--from was passed empty; specify the git checkpoint to restore from");
+ }
let (workspace, project) =
super::resolve_scope(config, args.workspace.as_deref(), args.project.as_deref())?;
let endpoint = ServerEndpoint::from_config_resolving_auth(config).await;
@@ -72,3 +78,44 @@ pub async fn run(config: &Config, args: RestorePageArgs) -> Result<()> {
}
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn args(path: &str, from: &str) -> RestorePageArgs {
+ RestorePageArgs {
+ path: path.into(),
+ from: from.into(),
+ workspace: None,
+ project: None,
+ json: false,
+ }
+ }
+
+ #[tokio::test]
+ async fn an_empty_path_is_refused_before_scope_or_network_work() {
+ for empty in ["", " \t "] {
+ let error = run(&Config::default(), args(empty, "HEAD~1"))
+ .await
+ .unwrap_err();
+ assert!(
+ error.to_string().contains("--path was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+ }
+
+ #[tokio::test]
+ async fn an_empty_revision_is_refused_before_scope_or_network_work() {
+ for empty in ["", " \t "] {
+ let error = run(&Config::default(), args("notes/example.md", empty))
+ .await
+ .unwrap_err();
+ assert!(
+ error.to_string().contains("--from was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+ }
+}