102 lines
3.1 KiB
Rust
102 lines
3.1 KiB
Rust
#[test]
|
|||
|
|
#[ignore]
|
||
|
|
fn m1_gate_update_rate_under_30percent() {
|
||
|
|
// LIVE TEST: Requires real Poimen transcript + MEM_API_KEY
|
||
|
|
// run with: cargo test --test it_m1_gate -- --ignored --nocapture
|
||
|
|
|
||
|
|
use mem_core::{QuerySet, gated_loop::{run_loop, LoopConfig}, Level};
|
||
|
|
use mem_llm::ChatClient;
|
||
|
|
use std::env;
|
||
|
|
|
||
|
|
let api_key = match env::var("MEM_API_KEY") {
|
||
|
|
Ok(k) => k,
|
||
|
|
Err(_) => {
|
||
|
|
println!("SKIP: MEM_API_KEY not set");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// Load query set
|
||
|
|
let query_set = match QuerySet::load("queries/poimen.yaml") {
|
||
|
|
Ok(qs) => qs,
|
||
|
|
Err(e) => {
|
||
|
|
println!("SKIP: Could not load poimen query set: {}", e);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
let llm = match ChatClient::new("https://api.riotpiao.com/v1", api_key, "qwen2.5:3b-instruct") {
|
||
|
|
Ok(llm) => llm,
|
||
|
|
Err(e) => {
|
||
|
|
println!("SKIP: Could not create LLM client: {}", e);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// Would load real chunks from pi/claude sources here
|
||
|
|
// For now, test would just verify framework compiles
|
||
|
|
let chunks = vec![];
|
||
|
|
|
||
|
|
for query in &query_set.queries {
|
||
|
|
let config = LoopConfig {
|
||
|
|
level: Level::L1,
|
||
|
|
query: query.clone(),
|
||
|
|
memory_budget: 1024,
|
||
|
|
use_exit_gate: false,
|
||
|
|
};
|
||
|
|
|
||
|
|
match run_loop(config, chunks.clone(), &llm) {
|
||
|
|
Ok(outcome) => {
|
||
|
|
let update_rate = if outcome.chunks_seen > 0 {
|
||
|
|
(outcome.chunks_used as f32) / (outcome.chunks_seen as f32)
|
||
|
|
} else {
|
||
|
|
0.0
|
||
|
|
};
|
||
|
|
|
||
|
|
println!("Query '{}': {}/{} chunks used ({:.1}%)",
|
||
|
|
query.id,
|
||
|
|
outcome.chunks_used,
|
||
|
|
outcome.chunks_seen,
|
||
|
|
update_rate * 100.0
|
||
|
|
);
|
||
|
|
|
||
|
|
assert!(update_rate < 0.3,
|
||
|
|
"Update rate {:.1}% exceeds 30% threshold",
|
||
|
|
update_rate * 100.0
|
||
|
|
);
|
||
|
|
}
|
||
|
|
Err(e) => println!("Error running loop for {}: {}", query.id, e),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn m1_gate_framework_compiles() {
|
||
|
|
// Verifies all components work together without live gateway
|
||
|
|
use mem_core::gated_loop::{LlmClient, LoopConfig, run_loop, LoopEvent};
|
||
|
|
use mem_core::{Chunk, Level, Query};
|
||
|
|
use anyhow::Result;
|
||
|
|
|
||
|
|
struct FakeLlm;
|
||
|
|
impl LlmClient for FakeLlm {
|
||
|
|
fn complete_blocking(&self, _s: &str, _u: &str, _m: usize) -> Result<String> {
|
||
|
|
Ok("<think>no</think><check>no</check><update>x</update><next>continue</next>".to_string())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
let config = LoopConfig {
|
||
|
|
level: Level::L1,
|
||
|
|
query: Query {
|
||
|
|
id: "test".to_string(),
|
||
|
|
question: "Test?".to_string(),
|
||
|
|
exit_gate: false,
|
||
|
|
},
|
||
|
|
memory_budget: 1024,
|
||
|
|
use_exit_gate: false,
|
||
|
|
};
|
||
|
|
|
||
|
|
let outcome = run_loop(config, vec![], &FakeLlm).unwrap();
|
||
|
|
assert_eq!(outcome.chunks_seen, 0);
|
||
|
|
assert_eq!(outcome.chunks_used, 0);
|
||
|
|
}
|