use microresolve::{MicroResolve, MicroResolveConfig};
#[test]
fn resolve_is_deterministic_across_invocations() {
let engine = make_engine();
let ns = engine.namespace("det-test");
let query = "I am having thoughts of hurting myself";
let first = ns.resolve(query);
for _ in 1..50 {
let result = ns.resolve(query);
assert_eq!(
result.len(),
first.len(),
"result length changed across invocations"
);
for (a, b) in first.iter().zip(result.iter()) {
assert_eq!(a.id, b.id, "intent order changed across invocations");
assert!(
(a.score - b.score).abs() < 1e-6,
"score changed: {} vs {} for intent {}",
a.score,
b.score,
a.id
);
}
}
}
#[test]
fn top_intent_is_stable() {
let engine = make_engine();
let ns = engine.namespace("det-test");
let query = "I am having thoughts of hurting myself";
let top = ns.resolve(query).into_iter().next().map(|m| m.id);
for _ in 0..50 {
let got = ns.resolve(query).into_iter().next().map(|m| m.id);
assert_eq!(got, top, "top intent changed across invocations");
}
}
fn make_engine() -> MicroResolve {
let engine = MicroResolve::new(MicroResolveConfig::default()).unwrap();
{
let ns = engine.namespace("det-test");
ns.add_intent(
"mental_health_crisis",
vec![
"thoughts of hurting myself",
"planning to take my life tonight",
"taking my life",
],
)
.unwrap();
ns.add_intent(
"billing",
vec!["paying my invoice", "pay my bill", "billing question"],
)
.unwrap();
}
engine
}