Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions atomic-cli/src/commands/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,17 @@ pub fn memory_new(args: &super::memory::new::MemoryNew) -> CliResult<bool> {
};
let response = session.create_vault_entity(request)?;
let entry = response.entry.expect("created entry");
if args.json {
println!(
"{}",
serde_json::json!({
"id": entry.id,
"file": entry.vault_path.unwrap_or_default(),
"kind": args.kind,
})
);
return Ok(true);
}
println!("Created memory: {}", entry.id);
println!(" file: {}", entry.vault_path.clone().unwrap_or_default());
println!(" kind: {}", args.kind);
Expand Down
57 changes: 57 additions & 0 deletions atomic-cli/tests/it/routing_parity_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,63 @@ fn intent_list_json_carries_attestation_columns_over_the_wire() {
assert!(table.contains(&id));
}

#[test]
fn memory_new_json_outputs_only_the_created_memory_object() {
let (repo, home) = fixture("memory-new-json");
let (repo_dir, home_dir) = (repo.path(), home.path());

for text in [
"JSON creation routes over the wire.",
":::memory\nJSON creation routes over the wire.\n:::",
] {
let output = run(
repo_dir,
home_dir,
&[
"memory", "new", "--kind", "lesson", "--text", text, "--json",
],
);
let value: serde_json::Value = serde_json::from_str(&output)
.unwrap_or_else(|error| panic!("memory new must emit only JSON: {error}: {output}"));
let id = value["id"].as_str().expect("created memory id");
assert!(!id.is_empty(), "created memory id must not be empty");
let file = format!(".vault/memory/{id}.md");
assert_eq!(
value,
serde_json::json!({"id": id, "file": file, "kind": "lesson"})
);
assert!(repo_dir.join(&file).is_file(), "created file: {file}");
}
}

#[test]
fn memory_new_without_json_preserves_the_human_summary() {
let (repo, home) = fixture("memory-new-human");
let output = run(
repo.path(),
home.path(),
&[
"memory",
"new",
"--kind",
"context",
"--text",
"Human creation summary.",
],
);
let id = output
.lines()
.next()
.and_then(|line| line.strip_prefix("Created memory: "))
.expect("human memory creation summary");
assert_eq!(
output,
format!(
"Created memory: {id}\n file: .vault/memory/{id}.md\n kind: context\n status: active\n"
)
);
}

#[test]
fn memory_list_json_carries_kind_status_about_columns() {
let (repo, home) = fixture("memory-list");
Expand Down
Loading