stackless_integrations/providers/runloop/
sandbox.rs1use std::collections::BTreeMap;
4
5use serde::Serialize;
6use stackless_stripe_projects::catalog::verify::CatalogService;
7use stackless_stripe_projects::provision::ProvisionContext;
8
9use super::FamilyResource;
10use crate::error::IntegrationError;
11use crate::hostable::{ConfigScope, Hostable, IntegrationHosting};
12
13pub const RESOURCE_KIND: &str = "integration-runloop";
14
15#[derive(Debug, Serialize)]
16pub struct RunloopSandboxConfig {}
17
18impl CatalogService for RunloopSandboxConfig {
19 const REFERENCE: &'static str = "runloop/sandbox";
20}
21
22#[derive(Debug)]
23pub struct RunloopSandbox;
24
25impl Hostable for RunloopSandbox {
26 const PROVIDER: &'static str = "runloop";
27 const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
28 const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
29 const RESOURCE_KIND: &'static str = RESOURCE_KIND;
30 const OUTPUTS: &'static [&'static str] = &["api_key"];
31}
32
33impl FamilyResource for RunloopSandbox {
34 type Config = RunloopSandboxConfig;
35 const PROVIDER_PREFIX: &'static str = "RUNLOOP";
36 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] =
38 &[("API_KEY", "api_key", true)];
39
40 fn build_config(ctx: &ProvisionContext<'_>) -> Result<RunloopSandboxConfig, IntegrationError> {
41 let _ = super::integration_config(ctx)?;
42 Ok(RunloopSandboxConfig {})
43 }
44}
45
46pub fn validate_config(
47 name: &str,
48 config: &BTreeMap<String, toml::Value>,
49) -> Result<(), IntegrationError> {
50 let _ = (name, config);
51 Ok(())
52}
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57 use crate::ProviderOps;
58 use crate::resource::ResourcePayload;
59 use stackless_core::def::StackDef;
60 use stackless_stripe_projects::stripe::StripeProjects;
61 use stackless_stripe_projects::test_support;
62
63 #[test]
64 fn config_matches_catalog() {
65 const FIXTURE: &str = include_str!(concat!(
66 env!("CARGO_MANIFEST_DIR"),
67 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
68 ));
69 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
70 let failures =
71 stackless_stripe_projects::verify_service(&catalog, &RunloopSandboxConfig {});
72 assert!(
73 failures.is_empty(),
74 "runloop/sandbox catalog gaps:\n{}",
75 failures.join("\n")
76 );
77 }
78
79 const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_sandbox","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_runloop","provider_name":"Runloop","service_id":"sandbox","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"component"},"configuration_schema":{"type":"object","required":[],"additionalProperties":false,"properties":{}}}]}}"##;
80
81 fn test_def() -> StackDef {
82 StackDef::parse(
83 r#"
84[stack]
85name = "atto"
86[stack.projects.stripe]
87project = "project_1"
88[integrations.res]
89provider = "runloop"
90[services.api]
91source = { repo = "r", ref = "main" }
92env = { OUT = "${integrations.res.api_key}" }
93health = { path = "/health" }
94[services.api.local]
95run = "true"
96"#,
97 )
98 .unwrap()
99 }
100
101 #[tokio::test]
102 async fn provision_records_outputs() {
103 let runner = test_support::provision_script(
104 CATALOG_ENVELOPE,
105 serde_json::json!({"RUNLOOP_API_KEY": "val_api_key"}),
106 0,
107 );
108 let dir = tempfile::tempdir().unwrap();
109 std::fs::write(
110 dir.path().join("stackless.toml"),
111 "[stack]\nname=\"atto\"\n",
112 )
113 .unwrap();
114 let stripe = StripeProjects::new(&runner, dir.path());
115
116 let resource = RunloopSandbox
117 .provision(
118 &stripe.as_dyn(),
119 &test_def(),
120 dir.path(),
121 "demo",
122 "res",
123 "local",
124 false,
125 )
126 .await
127 .unwrap();
128 assert_eq!(resource.resource_kind, "integration-runloop");
129 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
130 assert_eq!(payload.outputs["api_key"], "val_api_key");
131 }
132}