readd tests, remove markdown files

This commit is contained in:
Alex Gorevski 2026-02-17 16:08:53 -08:00 committed by Chummy
parent e2634c72c2
commit 9a6fa76825
17 changed files with 1352 additions and 0 deletions

View file

@ -556,4 +556,108 @@ mod tests {
.expect("backend=none should be rejected for migration target");
assert!(err.to_string().contains("disables persistence"));
}
// ── §7.1 / §7.2 Config backward compatibility & migration tests ──
#[test]
fn parse_category_handles_all_variants() {
assert_eq!(parse_category("core"), MemoryCategory::Core);
assert_eq!(parse_category("daily"), MemoryCategory::Daily);
assert_eq!(parse_category("conversation"), MemoryCategory::Conversation);
assert_eq!(parse_category(""), MemoryCategory::Core);
assert_eq!(
parse_category("custom_type"),
MemoryCategory::Custom("custom_type".to_string())
);
}
#[test]
fn parse_category_case_insensitive() {
assert_eq!(parse_category("CORE"), MemoryCategory::Core);
assert_eq!(parse_category("Daily"), MemoryCategory::Daily);
assert_eq!(parse_category("CONVERSATION"), MemoryCategory::Conversation);
}
#[test]
fn normalize_key_handles_empty_string() {
let key = normalize_key("", 42);
assert_eq!(key, "openclaw_42");
}
#[test]
fn normalize_key_trims_whitespace() {
let key = normalize_key(" my_key ", 0);
assert_eq!(key, "my_key");
}
#[test]
fn parse_structured_markdown_rejects_empty_key() {
assert!(parse_structured_memory_line("****:value").is_none());
}
#[test]
fn parse_structured_markdown_rejects_empty_value() {
assert!(parse_structured_memory_line("**key**:").is_none());
}
#[test]
fn parse_structured_markdown_rejects_no_stars() {
assert!(parse_structured_memory_line("key: value").is_none());
}
#[tokio::test]
async fn migration_skips_empty_content() {
let dir = TempDir::new().unwrap();
let db_path = dir.path().join("brain.db");
let conn = Connection::open(&db_path).unwrap();
conn.execute_batch("CREATE TABLE memories (key TEXT, content TEXT, category TEXT);")
.unwrap();
conn.execute(
"INSERT INTO memories (key, content, category) VALUES (?1, ?2, ?3)",
params!["empty_key", " ", "core"],
)
.unwrap();
let rows = read_openclaw_sqlite_entries(&db_path).unwrap();
assert_eq!(
rows.len(),
0,
"entries with empty/whitespace content must be skipped"
);
}
#[test]
fn backup_creates_timestamped_directory() {
let tmp = TempDir::new().unwrap();
let mem_dir = tmp.path().join("memory");
std::fs::create_dir_all(&mem_dir).unwrap();
// Create a brain.db to back up
let db_path = mem_dir.join("brain.db");
std::fs::write(&db_path, "fake db content").unwrap();
let result = backup_target_memory(tmp.path()).unwrap();
assert!(
result.is_some(),
"backup should be created when files exist"
);
let backup_dir = result.unwrap();
assert!(backup_dir.exists());
assert!(
backup_dir.to_string_lossy().contains("openclaw-"),
"backup dir must contain openclaw- prefix"
);
}
#[test]
fn backup_returns_none_when_no_files() {
let tmp = TempDir::new().unwrap();
let result = backup_target_memory(tmp.path()).unwrap();
assert!(
result.is_none(),
"backup should return None when no files to backup"
);
}
}