#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod support;
use std::sync::Arc;
use support::{Harness, token_for};
use turnframe_core::ids::TurnId;
use turnframe_core::plan::AnswerBasis;
use turnframe_provider::purpose::ModelPurpose;
use turnframe_test::providers::{ScriptedProvider, UnderstandingBuilder};
use turnframe_test::workflows::trip::{incomplete_case, operations};
fn turn_one() -> TurnId {
TurnId::from(uuid::Uuid::from_u128(1))
}
async fn a_value_and_a_question(text: &str, value: &str) -> Arc<ScriptedProvider> {
let turn = turn_one();
let understanding = UnderstandingBuilder::of(text)
.apply(
operations::SET_NAME,
token_for(turn, "trip", "trip-1"),
serde_json::json!({"value": value}),
value,
)
.ask_about(
AnswerBasis::CurrentCommittedState,
None,
&["total_amount"],
"and what is the total?",
)
.build()
.unwrap();
let provider = ScriptedProvider::builder("scripted", "model-1")
.answering("It is 30.")
.acknowledging("Noted. It is 30.")
.build_shared();
let harness = Harness::builder()
.trip("trip-1", "Trip 1", 3, incomplete_case())
.understands(understanding)
.provider(Arc::clone(&provider))
.build()
.await;
harness.handle(harness.turn(turn, text)).await.unwrap();
provider
}
fn written_from(provider: &ScriptedProvider, purpose: ModelPurpose) -> String {
provider
.calls_for(purpose)
.into_iter()
.next()
.expect("the stage ran")
.user_text()
}
#[tokio::test]
async fn the_transition_is_not_given_the_questions() {
let provider = a_value_and_a_question("Lisbon, and what is the total?", "Lisbon").await;
let shown = written_from(&provider, ModelPurpose::Acknowledge);
assert!(
shown.contains("Answers to give in your reply:\n- It is 30."),
"it is given the answer to give: {shown}"
);
assert!(
!shown.contains("what is the total"),
"and the question's words are nowhere in what it was asked to do: {shown}"
);
}
#[tokio::test]
async fn the_transition_does_not_see_the_question_in_the_users_own_message() {
let provider =
a_value_and_a_question("Porto offsite, and what is the total?", "Porto offsite").await;
let acknowledging = written_from(&provider, ModelPurpose::Acknowledge);
assert!(
acknowledging.contains("The user wrote: «Porto offsite»"),
"the acknowledgement keeps what the user said and loses what they asked: \
{acknowledging}"
);
let answering = written_from(&provider, ModelPurpose::Answer);
assert!(
answering.contains("Question: «and what is the total?»"),
"the stage whose job it is gets the question: {answering}"
);
}