use async_trait::async_trait;
use super::base::{CodeExecutor, CodeExecutorError};
use super::types::{CodeExecutionInput, CodeExecutionResult};
#[derive(Debug, Clone)]
pub struct VertexAiCodeExecutorConfig {
pub project: String,
pub location: String,
pub timeout_secs: u64,
}
#[derive(Debug, Clone)]
pub struct VertexAiCodeExecutor {
config: VertexAiCodeExecutorConfig,
}
impl VertexAiCodeExecutor {
pub fn new(config: VertexAiCodeExecutorConfig) -> Self {
Self { config }
}
pub fn project(&self) -> &str {
&self.config.project
}
pub fn location(&self) -> &str {
&self.config.location
}
}
#[async_trait]
impl CodeExecutor for VertexAiCodeExecutor {
async fn execute_code(
&self,
input: CodeExecutionInput,
) -> Result<CodeExecutionResult, CodeExecutorError> {
let _ = &input;
Ok(CodeExecutionResult {
stdout: String::new(),
stderr: String::new(),
output_files: vec![],
})
}
fn stateful(&self) -> bool {
true
}
}
#[cfg(test)]
mod tests {
use super::*;
fn test_config() -> VertexAiCodeExecutorConfig {
VertexAiCodeExecutorConfig {
project: "test-project".into(),
location: "us-central1".into(),
timeout_secs: 60,
}
}
#[test]
fn executor_metadata() {
let exec = VertexAiCodeExecutor::new(test_config());
assert_eq!(exec.project(), "test-project");
assert_eq!(exec.location(), "us-central1");
assert!(exec.stateful());
}
#[tokio::test]
async fn execute_returns_empty_stub() {
let exec = VertexAiCodeExecutor::new(test_config());
let input = CodeExecutionInput {
code: "print(42)".into(),
input_files: vec![],
execution_id: None,
};
let result = exec.execute_code(input).await.unwrap();
assert!(result.stdout.is_empty());
}
}