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