test(mcp): add image tool test and consolidate MCP test fixtures (#7019)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
@@ -997,6 +997,7 @@ impl Provider for ChatGptCodexProvider {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::conversation::message::Message;
|
||||
use goose_test_support::TEST_IMAGE_B64;
|
||||
use jsonwebtoken::{Algorithm, EncodingKey, Header};
|
||||
use rmcp::model::{CallToolRequestParams, CallToolResult, Content, ErrorCode, ErrorData};
|
||||
use rmcp::object;
|
||||
@@ -1004,9 +1005,6 @@ mod tests {
|
||||
use wiremock::matchers::{body_string_contains, method, path};
|
||||
use wiremock::{Mock, MockServer, ResponseTemplate};
|
||||
|
||||
/// 1x1 transparent PNG, base64-encoded.
|
||||
const TINY_PNG_B64: &str = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNgYAAAAAMAASsJTYQAAAAASUVORK5CYII=";
|
||||
|
||||
fn input_kinds(payload: &Value) -> Vec<String> {
|
||||
payload["input"]
|
||||
.as_array()
|
||||
@@ -1106,7 +1104,7 @@ mod tests {
|
||||
vec![
|
||||
Message::user()
|
||||
.with_text("describe this")
|
||||
.with_image(TINY_PNG_B64, "image/png"),
|
||||
.with_image(TEST_IMAGE_B64, "image/png"),
|
||||
],
|
||||
vec![
|
||||
"message:user".to_string(),
|
||||
@@ -1122,7 +1120,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_image_url_format() {
|
||||
let messages = vec![Message::user().with_image(TINY_PNG_B64, "image/png")];
|
||||
let messages = vec![Message::user().with_image(TEST_IMAGE_B64, "image/png")];
|
||||
let items = build_input_items(&messages).unwrap();
|
||||
// The image is inside the content array of the user message
|
||||
let content = items[0]["content"].as_array().unwrap();
|
||||
|
||||
@@ -670,11 +670,9 @@ impl Provider for CodexProvider {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use goose_test_support::TEST_IMAGE_B64;
|
||||
use test_case::test_case;
|
||||
|
||||
/// 1x1 transparent PNG, base64-encoded.
|
||||
const TINY_PNG_B64: &str = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNgYAAAAAMAASsJTYQAAAAASUVORK5CYII=";
|
||||
|
||||
#[test]
|
||||
fn test_codex_metadata() {
|
||||
let metadata = CodexProvider::metadata();
|
||||
@@ -694,7 +692,7 @@ mod tests {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let messages = vec![Message::user()
|
||||
.with_text("Describe")
|
||||
.with_image(TINY_PNG_B64, mime)];
|
||||
.with_image(TEST_IMAGE_B64, mime)];
|
||||
let (_prompt, temp_files) = prepare_input("", &messages, dir.path()).unwrap();
|
||||
assert_eq!(temp_files.len(), 1);
|
||||
let path = temp_files[0].path();
|
||||
@@ -712,7 +710,7 @@ mod tests {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let messages = vec![Message::user()
|
||||
.with_text("Describe")
|
||||
.with_image(TINY_PNG_B64, mime)];
|
||||
.with_image(TEST_IMAGE_B64, mime)];
|
||||
let err = prepare_input("", &messages, dir.path()).unwrap_err();
|
||||
assert!(
|
||||
err.to_string().contains("Unsupported image MIME type"),
|
||||
|
||||
@@ -386,11 +386,9 @@ pub fn from_bedrock_json(document: &Document) -> Result<Value> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use anyhow::Result;
|
||||
use goose_test_support::TEST_IMAGE_B64;
|
||||
use rmcp::model::{AnnotateAble, RawImageContent};
|
||||
|
||||
// Base64 encoded 1x1 PNG image for testing
|
||||
const TEST_IMAGE_BASE64: &str = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==";
|
||||
|
||||
#[test]
|
||||
fn test_to_bedrock_image_supported_formats() -> Result<()> {
|
||||
let supported_formats = [
|
||||
@@ -403,7 +401,7 @@ mod tests {
|
||||
|
||||
for mime_type in supported_formats {
|
||||
let image = RawImageContent {
|
||||
data: TEST_IMAGE_BASE64.to_string(),
|
||||
data: TEST_IMAGE_B64.to_string(),
|
||||
mime_type: mime_type.to_string(),
|
||||
meta: None,
|
||||
}
|
||||
@@ -419,7 +417,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_to_bedrock_image_unsupported_format() {
|
||||
let image = RawImageContent {
|
||||
data: TEST_IMAGE_BASE64.to_string(),
|
||||
data: TEST_IMAGE_B64.to_string(),
|
||||
mime_type: "image/bmp".to_string(),
|
||||
meta: None,
|
||||
}
|
||||
@@ -450,7 +448,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_to_bedrock_message_content_image() -> Result<()> {
|
||||
let image = RawImageContent {
|
||||
data: TEST_IMAGE_BASE64.to_string(),
|
||||
data: TEST_IMAGE_B64.to_string(),
|
||||
mime_type: "image/png".to_string(),
|
||||
meta: None,
|
||||
}
|
||||
@@ -467,7 +465,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_to_bedrock_tool_result_content_block_image() -> Result<()> {
|
||||
let content = Content::image(TEST_IMAGE_BASE64.to_string(), "image/png".to_string());
|
||||
let content = Content::image(TEST_IMAGE_B64.to_string(), "image/png".to_string());
|
||||
let result = to_bedrock_tool_result_content_block("test_id", content)?;
|
||||
|
||||
// Verify the wrapper correctly converts Content::Image to ToolResultContentBlock::Image
|
||||
|
||||
@@ -38,6 +38,7 @@ pub const OLLAMA_DEFAULT_PORT: u16 = 11434;
|
||||
pub const OLLAMA_DEFAULT_MODEL: &str = "qwen3";
|
||||
pub const OLLAMA_KNOWN_MODELS: &[&str] = &[
|
||||
OLLAMA_DEFAULT_MODEL,
|
||||
"qwen3-vl",
|
||||
"qwen3-coder:30b",
|
||||
"qwen3-coder:480b-cloud",
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user