use crate::{AiBackend, AiError, Copilot, GenerateRequest, Ollama};
#[test]
fn ollama_name_is_correct() {
let ai = Ollama::new("qwen2.5-coder:1.5b");
assert_eq!(ai.name(), "ollama");
}
#[test]
fn ollama_default_works() {
let ai = Ollama::default();
assert_eq!(ai.name(), "ollama");
}
#[test]
fn ollama_with_model_updates_model() {
let ai = Ollama::new("qwen2.5-coder:1.5b").with_model("mistral");
assert_eq!(ai.model(), "mistral");
}
#[test]
fn ollama_with_bin_updates_bin() {
let ai = Ollama::new("qwen2.5-coder:1.5b").with_bin("custom-ollama");
assert_eq!(ai.bin(), "custom-ollama");
}
#[test]
fn copilot_name_is_correct() {
let ai = Copilot::new();
assert_eq!(ai.name(), "copilot");
}
#[test]
fn copilot_default_works() {
let ai = Copilot::default();
assert_eq!(ai.name(), "copilot");
}
#[test]
fn copilot_with_bin_updates_bin() {
let ai = Copilot::new().with_bin("custom-copilot");
assert_eq!(ai.bin(), "custom-copilot");
}
#[test]
fn ollama_constructs() {
let _ = Ollama::new("mistral");
}
#[test]
fn copilot_constructs() {
let _ = Copilot::new();
}
#[test]
fn generate_request_can_hold_persona_instructions_and_memory() {
let req = GenerateRequest::new("Hello")
.with_persona("You are a concise engineering assistant.")
.with_instructions("Output only the answer.")
.with_memory("The project uses conventional commits.");
assert_eq!(
req.persona.as_deref(),
Some("You are a concise engineering assistant.")
);
assert_eq!(req.instructions.as_deref(), Some("Output only the answer."));
assert_eq!(
req.memory.as_deref(),
Some("The project uses conventional commits.")
);
assert_eq!(req.prompt, "Hello");
}
#[test]
fn generate_request_new_sets_no_instructions() {
let req = GenerateRequest::new("Hello");
assert_eq!(req.prompt, "Hello");
assert_eq!(req.instructions, None);
}
#[test]
fn generate_request_with_instructions_sets_instructions() {
let req = GenerateRequest::new("Hello").with_instructions("Be concise");
assert_eq!(req.prompt, "Hello");
assert_eq!(req.instructions.as_deref(), Some("Be concise"));
}
#[test]
fn copilot_missing_binary_returns_io_error() {
let ai = Copilot::new().with_bin("definitely-not-a-real-copilot-binary");
let req = GenerateRequest::new("Hello");
let err = ai.generate(&req).unwrap_err();
assert!(matches!(err, AiError::Io(_)));
}
#[test]
fn ollama_missing_binary_returns_io_error() {
let ai = Ollama::new("llama3.2").with_bin("definitely-not-a-real-ollama-binary");
let req = GenerateRequest::new("Hello");
let err = ai.generate(&req).unwrap_err();
assert!(matches!(err, AiError::Io(_)));
}