#![allow(dead_code)]
use runcycles::models::*;
use runcycles::CyclesClient;
use serde_json::json;
use wiremock::matchers::{method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};
pub fn make_reserve_request() -> ReservationCreateRequest {
ReservationCreateRequest::builder()
.subject(Subject {
tenant: Some("acme".into()),
..Default::default()
})
.action(Action::new("llm.completion", "gpt-4o"))
.estimate(Amount::usd_microcents(5000))
.build()
}
pub async fn mount_reserve_allow(server: &MockServer, reservation_id: &str) {
Mock::given(method("POST"))
.and(path("/v1/reservations"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"decision": "ALLOW",
"reservation_id": reservation_id,
"affected_scopes": ["tenant:acme"],
"expires_at_ms": 1700000060000_u64
})))
.mount(server)
.await;
}
pub async fn mount_extend(server: &MockServer, reservation_id: &str) {
Mock::given(method("POST"))
.and(path(format!("/v1/reservations/{reservation_id}/extend")))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"status": "ACTIVE",
"expires_at_ms": 1700000120000_u64
})))
.mount(server)
.await;
}
pub async fn setup_with_reservation(server: &MockServer) -> CyclesClient {
let client = CyclesClient::builder("key", server.uri()).build();
Mock::given(method("POST"))
.and(path("/v1/reservations"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"decision": "ALLOW_WITH_CAPS",
"reservation_id": "rsv_test",
"affected_scopes": ["tenant:acme", "app:my-app"],
"expires_at_ms": 1700000060000_u64,
"caps": {"max_tokens": 500, "max_steps_remaining": 10, "cooldown_ms": 1000}
})))
.mount(server)
.await;
mount_extend(server, "rsv_test").await;
Mock::given(method("POST"))
.and(path("/v1/reservations/rsv_test/release"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"status": "RELEASED",
"released": {"unit": "USD_MICROCENTS", "amount": 5000}
})))
.mount(server)
.await;
client
}