use crate::engine::executor::ParseOutcome;
use crate::engine::runtime::LlmTurnResult;
use crate::types::Action;
fn call(id: &str, name: &str, arguments: &str) -> serde_json::Value {
serde_json::json!({
"id": id,
"function": {"name": name, "arguments": arguments},
})
}
fn turn(
is_tool_call: bool,
calls: Vec<serde_json::Value>,
text: &str,
finish: Option<&str>,
) -> LlmTurnResult {
LlmTurnResult {
full_text: text.into(),
reasoning_text: String::new(),
is_tool_call,
tool_calls: calls,
integrity: Default::default(),
usage: None,
finish_reason: finish.map(String::from),
ttft_ms: 1,
llm_duration_ms: 2,
reasoning_only: false,
thinking_signature: None,
}
}
fn reasoning_only_turn() -> LlmTurnResult {
let mut turn = turn(false, vec![], "", None);
turn.reasoning_only = true;
turn.reasoning_text = "thinking…".into();
turn
}
#[test]
fn actions_fixtures_materialize_every_call() {
let out = super::classify_turn(&turn(
true,
vec![call("call_1", "write_file", r#"{"path":"a.rs"}"#)],
"",
Some("tool_calls"),
));
assert_eq!(
out,
ParseOutcome::Actions(vec![Action::from_tool_call(
"call_1",
"write_file",
r#"{"path":"a.rs"}"#
)]),
"one envelope entry = one action, id and raw args preserved"
);
let out = super::classify_turn(&turn(
true,
vec![
call("call_1", "read_file", r#"{"path":"a.rs"}"#),
call("call_2", "execute_command", r#"{"command":"ls"}"#),
],
"",
Some("tool_calls"),
));
let ParseOutcome::Actions(actions) = &out else {
panic!("expected Actions, got {out:?}");
};
assert_eq!(
actions.iter().map(|a| a.id.as_str()).collect::<Vec<_>>(),
["call_1", "call_2"]
);
assert_eq!(
actions.iter().map(|a| a.name.as_str()).collect::<Vec<_>>(),
["read_file", "execute_command"]
);
let out = super::classify_turn(&turn(
true,
vec![call("call_1", "write_file", r#"{"path":"a.rs"#)],
"",
Some("tool_calls"),
));
let ParseOutcome::Actions(actions) = &out else {
panic!("expected Actions, got {out:?}");
};
assert_eq!(actions[0].raw_args(), r#"{"path":"a.rs"#);
assert_eq!(actions[0].identity, r#"write_file::{"path":"a.rs"#);
}
#[test]
fn incomplete_fixtures_are_tool_intent_without_materialization() {
let out = super::classify_turn(&turn(true, vec![], "", Some("tool_calls")));
assert_eq!(out, ParseOutcome::Incomplete, "flag without calls");
let out = super::classify_turn(&turn(true, vec![], "", Some("length")));
assert_eq!(out, ParseOutcome::Incomplete, "flag without calls, length");
}
#[test]
fn empty_fixtures_have_no_action_intent() {
let out = super::classify_turn(&turn(false, vec![], "all done.", Some("stop")));
assert_eq!(out, ParseOutcome::Empty, "plain text answer");
let out = super::classify_turn(&reasoning_only_turn());
assert_eq!(out, ParseOutcome::Empty, "reasoning-only turn");
let out = super::classify_turn(&turn(false, vec![], "", Some("length")));
assert_eq!(out, ParseOutcome::Empty, "empty text first, even truncated");
}
#[test]
fn malformed_fixtures_are_structural_anomalies() {
let out = super::classify_turn(&turn(false, vec![], "partial…", Some("length")));
assert_eq!(out, ParseOutcome::Malformed, "truncated finish with text");
let out = super::classify_turn(&turn(false, vec![], "some text", Some("tool_use")));
assert_eq!(out, ParseOutcome::Malformed, "ToolUse mislabel with text");
}