86 lines
2.4 KiB
Plaintext
86 lines
2.4 KiB
Plaintext
use mem_cli::verify::{Verifier, VerifyOpts, OutputFormat};
|
|||
|
|
use std::path::PathBuf;
|
||
|
|
use tempfile::TempDir;
|
||
|
|
use std::fs;
|
||
|
|
|
||
|
|
#[tokio::test]
|
||
|
|
async fn a1_clean_passes() {
|
||
|
|
// Create a minimal clean log
|
||
|
|
let temp_dir = TempDir::new().unwrap();
|
||
|
|
let log_dir = temp_dir.path().join("log");
|
||
|
|
fs::create_dir(&log_dir).unwrap();
|
||
|
|
|
||
|
|
// Write clean log with one L1 and one L0
|
||
|
|
let log_content = r#"{"project": "test", "level": "L0", "text": "error output", "parents": [], "gate": false, "run_id": "run1", "query_id": "q1"}
|
||
|
|
{"project": "test", "level": "L1", "text": "learned lesson", "parents": [{"text": "error output"}], "gate": true, "run_id": "run1", "query_id": "q1"}
|
||
|
|
"#;
|
||
|
|
|
||
|
|
fs::write(log_dir.join("test.jsonl"), log_content).unwrap();
|
||
|
|
|
||
|
|
let opts = VerifyOpts {
|
||
|
|
project: "test".to_string(),
|
||
|
|
check_db: false, // No database in unit test
|
||
|
|
check_log: true,
|
||
|
|
log_dir: Some(log_dir),
|
||
|
|
format: OutputFormat::Text,
|
||
|
|
};
|
||
|
|
|
||
|
|
let verifier = Verifier::new("postgresql://dummy").await.unwrap_or_else(|_| {
|
||
|
|
// Create a mock verifier if DB connection fails
|
||
|
|
panic!("Test should not reach here");
|
||
|
|
});
|
||
|
|
|
||
|
|
let result = verifier.verify(opts).await;
|
||
|
|
// We can't actually test this without a database
|
||
|
|
// This is more of a unit test structure
|
||
|
|
}
|
||
|
|
|
||
|
|
#[tokio::test]
|
||
|
|
async fn a2_orphan_memory_would_fail() {
|
||
|
|
// Test structure: L1 with empty parents
|
||
|
|
// In a real test, this would be caught by:
|
||
|
|
// Invariant 1: "L1 memory has no parents (evidence)"
|
||
|
|
|
||
|
|
// This demonstrates the test structure needed for M2.7
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a3_dangling_parent_detection() {
|
||
|
|
// Invariant 2: Parent sha not found in log
|
||
|
|
// Would need to parse log and check all parent refs exist
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a4_uncited_evidence_detection() {
|
||
|
|
// Invariant 3: Evidence sha is not cited by any memory
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a5_evidence_gate_mismatch() {
|
||
|
|
// Invariant 4: evidence count != gate.update==true count
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a6_cycle_detection() {
|
||
|
|
// Invariant 5: A → B → A would create a cycle
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a7_level_mismatch_detection() {
|
||
|
|
// Invariant 6: L2 node with L0 parent (should be L1)
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a8_reports_all_violations() {
|
||
|
|
// Create fixture with 3 violations
|
||
|
|
// Assert all 3 appear in output
|
||
|
|
// (not fail-fast behavior)
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a9_db_and_log_independent() {
|
||
|
|
// Introduce violation in DB only
|
||
|
|
// Assert --log catches nothing, --db catches it
|
||
|
|
// Proves two checks are independent
|
||
|
|
}
|