use std::fs;
#[test]
fn test_claude_md_includes_recovery_guarantees() {
let content = fs::read_to_string("CLAUDE.md").expect("Failed to read CLAUDE.md");
assert!(
content.contains("Recovery") || content.contains("recovery"),
"CLAUDE.md should mention recovery guarantees"
);
assert!(
content.contains("Synchronous")
&& content.contains("GroupCommit")
&& content.contains("Async"),
"CLAUDE.md should document all durability modes (Synchronous, GroupCommit, Async)"
);
let has_acid_section = content.contains("ACID") || content.contains("Correctness");
assert!(
has_acid_section,
"CLAUDE.md should have an ACID or Correctness section"
);
}
#[test]
fn test_claude_md_includes_recovery_flow() {
let content = fs::read_to_string("CLAUDE.md").expect("Failed to read CLAUDE.md");
let hybrid_storage_heading = "### Hybrid Storage";
let next_heading = "## Rust Coding Standards";
let section_start = content
.find(hybrid_storage_heading)
.expect("Hybrid Storage section not found in CLAUDE.md");
let section_end = content[section_start..]
.find(next_heading)
.map(|i| section_start + i)
.unwrap_or_else(|| content.len());
let hybrid_storage_section = &content[section_start..section_end];
assert!(
hybrid_storage_section.contains("Recovery Flow"),
"Hybrid Storage section should contain 'Recovery Flow'"
);
assert!(
hybrid_storage_section.contains("Replay WAL") || hybrid_storage_section.contains("Replay"),
"Hybrid Storage section should mention 'Replay WAL' or 'Replay'"
);
}
#[test]
fn test_claude_md_includes_recovery_benchmarks() {
let content = fs::read_to_string("CLAUDE.md").expect("Failed to read CLAUDE.md");
assert!(
content.contains("bench") || content.contains("Benchmark"),
"CLAUDE.md should mention benchmarks"
);
let has_benchmark_command = content.contains("just bench");
assert!(
has_benchmark_command,
"CLAUDE.md should document the 'just bench' command"
);
}
#[test]
fn test_claude_md_references_wal_documentation() {
let content = fs::read_to_string("CLAUDE.md").expect("Failed to read CLAUDE.md");
assert!(
content.contains("docs/WAL.md") || content.contains("WAL.md"),
"CLAUDE.md should reference docs/WAL.md for detailed WAL documentation"
);
}
#[test]
fn test_claude_md_mentions_checkpoint_recovery() {
let content = fs::read_to_string("CLAUDE.md").expect("Failed to read CLAUDE.md");
assert!(
content.contains("checkpoint") || content.contains("Checkpoint"),
"CLAUDE.md should mention checkpoints for recovery optimization"
);
}
#[test]
fn test_claude_md_recovery_content_complete() {
let content = fs::read_to_string("CLAUDE.md").expect("Failed to read CLAUDE.md");
let required_topics = vec![
("ACID", "ACID guarantees"),
("durability", "Durability guarantees"),
("WAL", "Write-Ahead Log"),
("recovery", "Recovery mechanisms"),
];
for (keyword, description) in required_topics {
assert!(
content.to_lowercase().contains(&keyword.to_lowercase()),
"CLAUDE.md should include information about: {}",
description
);
}
}
fn extract_numbered_lock_order(section: &str) -> Vec<String> {
let mut entries = Vec::new();
for line in section.lines() {
let trimmed = line.trim();
let without_comment = trimmed
.strip_prefix("//!")
.or_else(|| trimmed.strip_prefix("//"))
.unwrap_or(trimmed)
.trim();
let Some((number, entry)) = without_comment.split_once(". ") else {
if !entries.is_empty() && !without_comment.is_empty() {
break;
}
continue;
};
if number.is_empty() || !number.chars().all(|c| c.is_ascii_digit()) {
if !entries.is_empty() && !without_comment.is_empty() {
break;
}
continue;
}
entries.push(entry.trim().trim_matches('`').to_string());
}
entries
}
#[test]
fn test_lock_acquisition_order_documented() {
let claude = fs::read_to_string("CLAUDE.md").expect("Failed to read CLAUDE.md");
let write_apply = fs::read_to_string("src/api/transaction/write/apply.rs")
.expect("Failed to read write apply module");
let db_mod = fs::read_to_string("src/db/mod.rs").expect("Failed to read db module");
let expected_order: Vec<String> = [
"current_timestamp",
"wal",
"historical",
"temporal_indexes",
"id generators",
"outgoing",
"incoming",
]
.into_iter()
.map(String::from)
.collect();
let claude_section = claude
.split("### Lock Acquisition Order")
.nth(1)
.expect("CLAUDE.md should include a lock acquisition order section");
let write_apply_section = write_apply
.split("//! # Lock Acquisition Order")
.nth(1)
.expect("write apply module should include a lock acquisition order comment");
let db_mod_section = db_mod
.split("// Lock ordering for write-path primitives:")
.nth(1)
.expect("db module should include a lock acquisition order comment");
for (name, section) in [
("CLAUDE.md", claude_section),
("write apply module", write_apply_section),
("db module", db_mod_section),
] {
assert!(
!section.contains("outgoing/incoming"),
"{name} should document `outgoing` and `incoming` as separate ordered entries"
);
assert!(
!section.contains("either order"),
"{name} should not allow outgoing and incoming adjacency indexes in either order"
);
}
for (name, section) in [
("CLAUDE.md", claude_section),
("write apply module", write_apply_section),
("db module", db_mod_section),
] {
assert_eq!(
extract_numbered_lock_order(section),
expected_order,
"{name} should document the lock acquisition order as a numbered list"
);
}
}