fix: template
This commit is contained in:
parent
9f6b6630ce
commit
f9e67bfc3d
|
|
@ -145,9 +145,15 @@ pub async fn execute_python_command(
|
|||
} else if json_value.get("result").is_some() || json_value.get("error").is_some() {
|
||||
// This is a final result or error response
|
||||
if let Ok(mut result) = final_result_clone.lock() {
|
||||
*result = Some(json_str.to_string());
|
||||
}
|
||||
println!("JSON-RPC result found: {}", json_str);
|
||||
// Extract the result or error content from JSON-RPC
|
||||
if let Some(result_content) = json_value.get("result") {
|
||||
*result = Some(result_content.to_string());
|
||||
println!("JSON-RPC result extracted: {}", result_content);
|
||||
} else if let Some(error_content) = json_value.get("error") {
|
||||
*result = Some(format!("{{\"status\":false,\"error\":{}}}", error_content));
|
||||
println!("JSON-RPC error extracted: {}", error_content);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} else if line.trim().starts_with('{') && line.trim().ends_with('}') {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
use crate::python_executor::execute_python_command;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_get_templates() {
|
||||
let app = tauri::test::mock_app();
|
||||
let args = vec![
|
||||
"-m".to_string(),
|
||||
"python_core.services.template_manager".to_string(),
|
||||
"--action".to_string(),
|
||||
"get_templates".to_string(),
|
||||
];
|
||||
|
||||
match execute_python_command(app, &args, None).await {
|
||||
Ok(result) => {
|
||||
println!("Result: {}", result);
|
||||
// Parse the result to verify it's valid JSON
|
||||
match serde_json::from_str::<serde_json::Value>(&result) {
|
||||
Ok(json) => {
|
||||
println!("Parsed JSON successfully");
|
||||
if let Some(status) = json.get("status") {
|
||||
println!("Status: {}", status);
|
||||
}
|
||||
if let Some(templates) = json.get("templates") {
|
||||
if let Some(array) = templates.as_array() {
|
||||
println!("Found {} templates", array.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Failed to parse JSON: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify template loading functionality
|
||||
"""
|
||||
|
||||
import sys
|
||||
import json
|
||||
from python_core.services.template_manager import TemplateManager
|
||||
from python_core.utils.jsonrpc import create_response_handler
|
||||
|
||||
def test_get_templates():
|
||||
"""Test getting templates"""
|
||||
rpc = create_response_handler("test")
|
||||
|
||||
try:
|
||||
manager = TemplateManager()
|
||||
templates = manager.get_templates()
|
||||
|
||||
result = {
|
||||
"status": True,
|
||||
"templates": [template.__dict__ for template in templates]
|
||||
}
|
||||
|
||||
rpc.success(result)
|
||||
|
||||
except Exception as e:
|
||||
rpc.error(-32603, f"Failed to get templates: {str(e)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_get_templates()
|
||||
Loading…
Reference in New Issue