109 lines
2.8 KiB
Rust
109 lines
2.8 KiB
Rust
use mem_core::parse_gate_response;
|
|||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a1_wellformed_yes_continue() {
|
||
|
|
let response = r#"<think>This is useful</think>
|
||
|
|
<check>yes</check>
|
||
|
|
<update>New memory text here</update>
|
||
|
|
<next>continue</next>"#;
|
||
|
|
|
||
|
|
let result = parse_gate_response(response).expect("Should parse");
|
||
|
|
assert_eq!(result.think, "This is useful");
|
||
|
|
assert!(result.update_gate);
|
||
|
|
assert_eq!(result.candidate, "New memory text here");
|
||
|
|
assert!(!result.exit_gate);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a2_wellformed_no_end() {
|
||
|
|
let response = r#"<think>Not relevant</think>
|
||
|
|
<check>no</check>
|
||
|
|
<update>Memory stays same</update>
|
||
|
|
<next>end</next>"#;
|
||
|
|
|
||
|
|
let result = parse_gate_response(response).expect("Should parse");
|
||
|
|
assert_eq!(result.think, "Not relevant");
|
||
|
|
assert!(!result.update_gate);
|
||
|
|
assert_eq!(result.candidate, "Memory stays same");
|
||
|
|
assert!(result.exit_gate);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a3_missing_check_errors() {
|
||
|
|
let response = r#"<think>Thinking</think>
|
||
|
|
<update>Memory text</update>
|
||
|
|
<next>continue</next>"#;
|
||
|
|
|
||
|
|
let err = parse_gate_response(response).expect_err("Should error");
|
||
|
|
assert_eq!(err.tag, "check");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a4_invalid_check_value() {
|
||
|
|
let response = r#"<think>Thinking</think>
|
||
|
|
<check>maybe</check>
|
||
|
|
<update>Memory text</update>
|
||
|
|
<next>continue</next>"#;
|
||
|
|
|
||
|
|
let err = parse_gate_response(response).expect_err("Should error");
|
||
|
|
assert_eq!(err.tag, "check");
|
||
|
|
assert!(err.message.contains("yes") || err.message.contains("no"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a5_invalid_next_value() {
|
||
|
|
let response = r#"<think>Thinking</think>
|
||
|
|
<check>yes</check>
|
||
|
|
<update>Memory text</update>
|
||
|
|
<next>maybe</next>"#;
|
||
|
|
|
||
|
|
let err = parse_gate_response(response).expect_err("Should error");
|
||
|
|
assert_eq!(err.tag, "next");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a6_missing_update_errors() {
|
||
|
|
let response = r#"<think>Thinking</think>
|
||
|
|
<check>yes</check>
|
||
|
|
<next>continue</next>"#;
|
||
|
|
|
||
|
|
let err = parse_gate_response(response).expect_err("Should error");
|
||
|
|
assert_eq!(err.tag, "update");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a7_nested_think_uses_last() {
|
||
|
|
let response = r#"<think>First thought</think>
|
||
|
|
<think>Second thought that matters</think>
|
||
|
|
<check>yes</check>
|
||
|
|
<update>Memory text</update>
|
||
|
|
<next>continue</next>"#;
|
||
|
|
|
||
|
|
let result = parse_gate_response(response).expect("Should parse");
|
||
|
|
assert_eq!(result.think, "Second thought that matters");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a8_duplicate_check_errors() {
|
||
|
|
let response = r#"<think>Thinking</think>
|
||
|
|
<check>yes</check>
|
||
|
|
<check>no</check>
|
||
|
|
<update>Memory text</update>
|
||
|
|
<next>continue</next>"#;
|
||
|
|
|
||
|
|
let err = parse_gate_response(response).expect_err("Should error");
|
||
|
|
assert_eq!(err.tag, "check");
|
||
|
|
assert!(err.message.contains("appears"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn a9_unclosed_tag_errors() {
|
||
|
|
let response = r#"<think>Thinking
|
||
|
|
<check>yes</check>
|
||
|
|
<update>Memory text</update>
|
||
|
|
<next>continue</next>"#;
|
||
|
|
|
||
|
|
let err = parse_gate_response(response).expect_err("Should error");
|
||
|
|
assert_eq!(err.tag, "think");
|
||
|
|
}
|