Add inline python extension (#3107)

Co-authored-by: Douwe Osinga <douwe@squareup.com>
Co-authored-by: Michael Neale <michael.neale@gmail.com>
This commit is contained in:
Douwe Osinga
2025-07-28 02:48:02 +02:00
committed by GitHub
parent 322c1e1416
commit b18213cf01
14 changed files with 308 additions and 12 deletions
+47
View File
@@ -432,6 +432,7 @@ impl RecipeBuilder {
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
#[test]
fn test_from_content_with_json() {
@@ -653,6 +654,52 @@ sub_recipes:
assert_eq!(author.contact, Some("test@example.com".to_string()));
}
#[test]
fn test_inline_python_extension() {
let content = r#"{
"version": "1.0.0",
"title": "Test Recipe",
"description": "A test recipe",
"instructions": "Test instructions",
"extensions": [
{
"type": "inline_python",
"name": "test_python",
"code": "print('hello world')",
"timeout": 300,
"description": "Test python extension",
"dependencies": ["numpy", "matplotlib"]
}
]
}"#;
let recipe = Recipe::from_content(content).unwrap();
assert!(recipe.extensions.is_some());
let extensions = recipe.extensions.unwrap();
assert_eq!(extensions.len(), 1);
match &extensions[0] {
ExtensionConfig::InlinePython {
name,
code,
description,
timeout,
dependencies,
} => {
assert_eq!(name, "test_python");
assert_eq!(code, "print('hello world')");
assert_eq!(description.as_deref(), Some("Test python extension"));
assert_eq!(timeout, &Some(300));
assert!(dependencies.is_some());
let deps = dependencies.as_ref().unwrap();
assert!(deps.contains(&"numpy".to_string()));
assert!(deps.contains(&"matplotlib".to_string()));
}
_ => panic!("Expected InlinePython extension"),
}
}
#[test]
fn test_from_content_with_activities() {
let content = r#"{