127 lines
3.6 KiB
Rust
127 lines
3.6 KiB
Rust
use mem_core::QuerySet;
|
|
|
|
#[test]
|
|
fn a1_valid_loads() {
|
|
let qs = QuerySet::load("fixtures/query-valid.yaml").expect("Should load valid file");
|
|
|
|
assert_eq!(qs.project, "poimen");
|
|
assert_eq!(qs.queries.len(), 2);
|
|
|
|
let q1 = qs.query("architecture-decisions").expect("Should find first query");
|
|
assert_eq!(q1.question, "What architectural decisions were made?");
|
|
assert!(!q1.exit_gate);
|
|
|
|
let q2 = qs.query("infra-root-causes").expect("Should find second query");
|
|
assert_eq!(q2.question, "What infrastructure bugs were found?");
|
|
assert!(!q2.exit_gate);
|
|
|
|
assert!(qs.synthesis.is_some());
|
|
let syn = qs.synthesis.unwrap();
|
|
assert_eq!(syn.question, "What is the current state?");
|
|
assert!(syn.exit_gate);
|
|
|
|
assert_eq!(qs.defaults.memory_budget, 1024);
|
|
assert_eq!(qs.defaults.chunk_tokens, 5000);
|
|
assert!(!qs.defaults.exit_gate);
|
|
}
|
|
|
|
#[test]
|
|
fn a2_empty_question_rejected() {
|
|
let err = QuerySet::load("fixtures/query-empty-question.yaml")
|
|
.expect_err("Should reject empty question");
|
|
|
|
let err_msg = format!("{:?}", err);
|
|
assert!(
|
|
err_msg.contains("empty-question"),
|
|
"Error should name the query id: {}",
|
|
err_msg
|
|
);
|
|
assert!(
|
|
err_msg.contains("question"),
|
|
"Error should name the field: {}",
|
|
err_msg
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a3_duplicate_id_rejected() {
|
|
let err = QuerySet::load("fixtures/query-duplicate-id.yaml")
|
|
.expect_err("Should reject duplicate id");
|
|
|
|
let err_msg = format!("{:?}", err);
|
|
assert!(
|
|
err_msg.contains("duplicate"),
|
|
"Error should name the duplicate id: {}",
|
|
err_msg
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a4_bad_id_charset_rejected() {
|
|
let err = QuerySet::load("fixtures/query-bad-charset.yaml")
|
|
.expect_err("Should reject bad charset");
|
|
|
|
let err_msg = format!("{:?}", err);
|
|
assert!(
|
|
err_msg.contains("infra/root-causes"),
|
|
"Error should name the bad id: {}",
|
|
err_msg
|
|
);
|
|
assert!(
|
|
err_msg.contains("filename") || err_msg.contains("[a-z0-9-]"),
|
|
"Error should mention filename constraint: {}",
|
|
err_msg
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a5_defaults_and_overrides() {
|
|
let qs = QuerySet::load("fixtures/query-valid.yaml").expect("Should load");
|
|
|
|
let q1 = qs.query("architecture-decisions").expect("Should find query");
|
|
assert!(!q1.exit_gate, "Query without exit_gate should get default false");
|
|
|
|
let syn = qs.synthesis.expect("Should have synthesis");
|
|
assert!(syn.exit_gate, "Synthesis with exit_gate: true should be honored");
|
|
}
|
|
|
|
#[test]
|
|
fn a6_l1_exit_gate_defaults_false() {
|
|
let qs = QuerySet::load("fixtures/query-valid.yaml").expect("Should load");
|
|
|
|
// All L1 queries should have exit_gate: false (the default)
|
|
for query in &qs.queries {
|
|
assert!(!query.exit_gate, "L1 query '{}' should have exit_gate: false", query.id);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a7_missing_question_field() {
|
|
// Create a fixture on the fly with missing question field
|
|
let yaml_content = r#"
|
|
project: test
|
|
roots: []
|
|
sources: []
|
|
queries:
|
|
- id: no-question
|
|
# question field is missing
|
|
"#;
|
|
|
|
use std::fs;
|
|
fs::write("fixtures/query-missing-question.yaml", yaml_content)
|
|
.expect("Should write fixture");
|
|
|
|
let err = QuerySet::load("fixtures/query-missing-question.yaml")
|
|
.expect_err("Should reject missing question");
|
|
|
|
let err_msg = format!("{:?}", err);
|
|
assert!(
|
|
err_msg.contains("no-question") || err_msg.contains("question"),
|
|
"Error should indicate missing/empty question: {}",
|
|
err_msg
|
|
);
|
|
|
|
// Cleanup
|
|
let _ = fs::remove_file("fixtures/query-missing-question.yaml");
|
|
}
|