use aion_core::{AssistantDocumentPosition, AssistantDocumentSelection};
use super::*;
fn screen_only() -> AssistantTurnContext {
AssistantTurnContext {
url: Some("/studio?source=workspace".to_owned()),
concepts: vec!["A step".to_owned(), "A route".to_owned()],
document: None,
}
}
fn document(selection: Option<AssistantDocumentSelection>) -> AssistantDocumentContext {
AssistantDocumentContext {
path: "flows/checkout.awl".to_owned(),
text: "workflow checkout\n outcome done: type String, route success".to_owned(),
selection,
cursor: None,
}
}
#[test]
fn a_caret_with_no_selection_is_stated_before_the_offer() {
let mut with_cursor = document(None);
with_cursor.cursor = Some(AssistantDocumentPosition { line: 1, column: 2 });
let context = AssistantTurnContext {
document: Some(with_cursor),
..AssistantTurnContext::default()
};
assert_eq!(
format_turn_context(&context),
"Document: flows/checkout.awl\n\
```awl\n\
workflow checkout\n outcome done: type String, route success\n\
```\n\
Cursor: line 2, column 3.\n\
Nothing is selected — the whole document is offered.\n\n"
);
}
#[test]
fn a_selection_speaks_for_the_caret() {
let mut both = document(Some(AssistantDocumentSelection {
from: AssistantDocumentPosition { line: 0, column: 0 },
to: AssistantDocumentPosition { line: 0, column: 8 },
}));
both.cursor = Some(AssistantDocumentPosition { line: 0, column: 8 });
let context = AssistantTurnContext {
document: Some(both),
..AssistantTurnContext::default()
};
let prose = format_turn_context(&context);
assert!(prose.contains("Selected: line 1, column 1 through line 1, column 9."));
assert!(!prose.contains("Cursor:"));
}
#[test]
fn an_empty_context_prefixes_nothing() {
assert_eq!(format_turn_context(&AssistantTurnContext::default()), "");
assert_eq!(compose(None, "fix the check"), "fix the check");
assert_eq!(
compose(Some(&AssistantTurnContext::default()), "fix the check"),
"fix the check"
);
assert!(is_empty(&AssistantTurnContext::default()));
}
#[test]
fn a_url_with_no_concepts_is_one_line() {
let context = AssistantTurnContext {
url: Some("/runs".to_owned()),
concepts: Vec::new(),
document: None,
};
assert_eq!(format_turn_context(&context), "On screen: /runs\n\n");
}
#[test]
fn the_screen_block_is_the_consoles_own_wording() {
assert_eq!(
format_turn_context(&screen_only()),
"On screen: /studio?source=workspace\nShowing: A step, A route\n\n"
);
}
#[test]
fn a_document_with_no_selection_says_so_in_the_consoles_words() {
let context = AssistantTurnContext {
document: Some(document(None)),
..AssistantTurnContext::default()
};
assert_eq!(
format_turn_context(&context),
"Document: flows/checkout.awl\n\
```awl\n\
workflow checkout\n outcome done: type String, route success\n\
```\n\
Nothing is selected — the whole document is offered.\n\n"
);
}
#[test]
fn a_selection_is_stated_in_one_based_numbers() {
let context = AssistantTurnContext {
document: Some(document(Some(AssistantDocumentSelection {
from: AssistantDocumentPosition { line: 2, column: 0 },
to: AssistantDocumentPosition {
line: 6,
column: 19,
},
}))),
..AssistantTurnContext::default()
};
assert_eq!(
format_turn_context(&context),
"Document: flows/checkout.awl\n\
```awl\n\
workflow checkout\n outcome done: type String, route success\n\
```\n\
Selected: line 3, column 1 through line 7, column 20.\n\n"
);
}
#[test]
fn both_blocks_are_joined_by_one_blank_line() {
let mut context = screen_only();
context.document = Some(document(None));
assert_eq!(
format_turn_context(&context),
"On screen: /studio?source=workspace\n\
Showing: A step, A route\n\
\n\
Document: flows/checkout.awl\n\
```awl\n\
workflow checkout\n outcome done: type String, route success\n\
```\n\
Nothing is selected — the whole document is offered.\n\n"
);
}
#[test]
fn the_composed_prompt_is_the_prose_then_the_operators_words() {
assert_eq!(
compose(Some(&screen_only()), "fix the check"),
"On screen: /studio?source=workspace\nShowing: A step, A route\n\nfix the check"
);
}