Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

1.1 KB
Raw Blame
use axum::{routing::post, Json, Router};
use parking_lot::Mutex;
use serde_json::{json, Value};
use std::sync::Arc;

#[derive(Debug, Clone, PartialEq)]
pub struct RecordedRequest {
    pub method: String,
    pub path: String,
    pub body: Value,
}

#[derive(Clone)]
struct FakeIntegrationState {
    requests: Arc<Mutex<Vec<RecordedRequest>>>,
}

pub struct FakeIntegrationBackend {
    pub base_url: String,
    state: FakeIntegrationState,
}

impl FakeIntegrationBackend {
    pub fn requests(&self) -> Vec<RecordedRequest> {
        self.state.requests.lock().clone()
    }
}

fn record(state: &FakeIntegrationState, method: &str, path: String, body: Value) {
    state.requests.lock().push(RecordedRequest {
        method: method.to_string(),
        path,
        body,
    });
}

fn as_string_array(value: &Value, key: &str) -> Vec<String> {
    value
        .get(key)
        .and_then(Value::as_array)
        .map(|items| {
            items
                .iter()
                .filter_map(Value::as_str)
                .map(ToOwned::to_owned)
                .collect()
        })
        .unwrap_or_default()
}

include!("test_support_backend.rs");