feat: created sub recipe tools (#2982)

This commit is contained in:
Lifei Zhou
2025-06-25 09:29:26 +10:00
committed by GitHub
parent 566796f767
commit 9e6247d9ed
18 changed files with 1329 additions and 426 deletions
+1
View File
@@ -46,6 +46,7 @@ pub async fn agent_generator(
interactive: false, // Benchmarking is non-interactive
scheduled_job_id: None,
quiet: false,
sub_recipes: None,
})
.await;
+71 -3
View File
@@ -36,10 +36,11 @@ pub fn handle_validate(recipe_name: &str) -> Result<()> {
/// # Returns
///
/// Result indicating success or failure
pub fn handle_deeplink(recipe_name: &str) -> Result<()> {
pub fn handle_deeplink(recipe_name: &str) -> Result<String> {
// Load the recipe file first to validate it
match load_recipe(recipe_name) {
Ok(recipe) => {
let mut full_url = String::new();
if let Ok(recipe_json) = serde_json::to_string(&recipe) {
let deeplink = base64::engine::general_purpose::STANDARD.encode(recipe_json);
println!(
@@ -48,9 +49,10 @@ pub fn handle_deeplink(recipe_name: &str) -> Result<()> {
recipe.title
);
let url_safe = urlencoding::encode(&deeplink);
println!("goose://recipe?config={}", url_safe);
full_url = format!("goose://recipe?config={}", url_safe);
println!("{}", full_url);
}
Ok(())
Ok(full_url)
}
Err(err) => {
println!("{} {}", style("✗").red().bold(), err);
@@ -58,3 +60,69 @@ pub fn handle_deeplink(recipe_name: &str) -> Result<()> {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
use tempfile::TempDir;
fn create_test_recipe_file(dir: &TempDir, filename: &str, content: &str) -> String {
let file_path = dir.path().join(filename);
fs::write(&file_path, content).expect("Failed to write test recipe file");
file_path.to_string_lossy().into_owned()
}
const VALID_RECIPE_CONTENT: &str = r#"
title: "Test Recipe"
description: "A test recipe for deeplink generation"
prompt: "Test prompt content"
instructions: "Test instructions"
"#;
const INVALID_RECIPE_CONTENT: &str = r#"
title: "Test Recipe"
description: "A test recipe for deeplink generation"
prompt: "Test prompt content {{ name }}"
instructions: "Test instructions"
"#;
#[test]
fn test_handle_deeplink_valid_recipe() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let recipe_path =
create_test_recipe_file(&temp_dir, "test_recipe.yaml", VALID_RECIPE_CONTENT);
let result = handle_deeplink(&recipe_path);
assert!(result.is_ok());
assert!(result.unwrap().contains("goose://recipe?config=eyJ2ZXJzaW9uIjoiMS4wLjAiLCJ0aXRsZSI6IlRlc3QgUmVjaXBlIiwiZGVzY3JpcHRpb24iOiJBIHRlc3QgcmVjaXBlIGZvciBkZWVwbGluayBnZW5lcmF0aW9uIiwiaW5zdHJ1Y3Rpb25zIjoiVGVzdCBpbnN0cnVjdGlvbnMiLCJwcm9tcHQiOiJUZXN0IHByb21wdCBjb250ZW50In0%3D"));
}
#[test]
fn test_handle_deeplink_invalid_recipe() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let recipe_path =
create_test_recipe_file(&temp_dir, "test_recipe.yaml", INVALID_RECIPE_CONTENT);
let result = handle_deeplink(&recipe_path);
assert!(result.is_err());
}
#[test]
fn test_handle_validation_valid_recipe() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let recipe_path =
create_test_recipe_file(&temp_dir, "test_recipe.yaml", VALID_RECIPE_CONTENT);
let result = handle_validate(&recipe_path);
assert!(result.is_ok());
}
#[test]
fn test_handle_validation_invalid_recipe() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let recipe_path =
create_test_recipe_file(&temp_dir, "test_recipe.yaml", INVALID_RECIPE_CONTENT);
let result = handle_validate(&recipe_path);
assert!(result.is_err());
}
}