From 7dfaa3f0950a6fdbc1cbbb7ef40218c45d383252 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 8 Apr 2026 02:14:49 -0400 Subject: [PATCH] tests for flux1 dev --- .../src/api/common_aspect_ratio.rs | 2 ++ .../generate/image/distill_image_request.rs | 30 ++++++++++++++++--- .../image/omni_gen_image_generate_handler.rs | 4 +-- .../omni_gen/generate/image/tests/mod.rs | 1 + 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/crates/api_clients/artcraft/artcraft_router/src/api/common_aspect_ratio.rs b/crates/api_clients/artcraft/artcraft_router/src/api/common_aspect_ratio.rs index e206b15e36..b49c8a65e5 100644 --- a/crates/api_clients/artcraft/artcraft_router/src/api/common_aspect_ratio.rs +++ b/crates/api_clients/artcraft/artcraft_router/src/api/common_aspect_ratio.rs @@ -36,7 +36,9 @@ pub enum CommonAspectRatio { // Auto values that bake in resolution // These are from the Seedream models + #[serde(rename = "auto_2k")] Auto2k, + #[serde(rename = "auto_4k")] Auto4k, // Defined aspect ratios that bake in resolution diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/distill_image_request.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/distill_image_request.rs index 043ccf48a7..67738d16b1 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/distill_image_request.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/distill_image_request.rs @@ -48,8 +48,10 @@ pub struct DistilledImageRequest { /// The fully-built router request, with `provider = Fal` so it matches the /// plan we actually execute. Private — useful for tests / debugging only. /// - /// Borrows inside this request point into the `_owned_*` boxes above. - #[allow(dead_code)] + /// Borrows inside this request point into the `_owned_*` boxes above. Access + /// only via [`DistilledImageRequest::request`] (an accessor that ties the + /// returned reference to `&self`) — never moved out, otherwise the borrows + /// would dangle once the boxes are dropped with `Self`. request: GenerateImageRequest<'static>, /// Cost estimate as computed by the Artcraft provider — this is what we bill on. @@ -58,8 +60,28 @@ pub struct DistilledImageRequest { /// Execution plan as computed by the Fal provider — what we hand to the router. /// /// Borrows inside this plan point into the `_owned_*` boxes above (and into - /// `request`, which itself points into them). - pub plan: ImageGenerationPlan<'static>, + /// `request`, which itself points into them). Access only via + /// [`DistilledImageRequest::plan`] — moving the plan out of `Self` would + /// dangle the borrows once the boxes are dropped. + plan: ImageGenerationPlan<'static>, +} + +impl DistilledImageRequest { + /// Borrow the execution plan. The returned reference's lifetime is tied to + /// `&self`, so the plan can never outlive the boxes that back its borrows. + pub fn plan(&self) -> &ImageGenerationPlan<'_> { + // SAFETY: the plan was constructed with `'static` borrows that actually + // point into `self._owned_*`. Re-binding the lifetime to `&self` exposes + // the true invariant to callers. + &self.plan + } + + /// Borrow the underlying router request. Useful for tests / debugging. + /// (Same lifetime invariant as [`Self::plan`].) + #[allow(dead_code)] + pub(crate) fn request(&self) -> &GenerateImageRequest<'_> { + &self.request + } } /// Build a [`DistilledImageRequest`] from a raw API request and a pre-computed diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/omni_gen_image_generate_handler.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/omni_gen_image_generate_handler.rs index 08d24a5e1b..b5df061c99 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/omni_gen_image_generate_handler.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/omni_gen_image_generate_handler.rs @@ -135,7 +135,7 @@ pub async fn omni_gen_image_generate_handler( let distilled = distill_image_request(&request, media_file_hydration_map.as_ref())?; info!(">>> Distilled cost: {:?}", distilled.cost); - info!(">>> Distilled plan: {:?}", distilled.plan); + info!(">>> Distilled plan: {:?}", distilled.plan()); // ==================== BILLING ==================== // @@ -163,7 +163,7 @@ pub async fn omni_gen_image_generate_handler( let router_client = artcraft_router::client::router_client::RouterClient::Fal(fal_client); - let generation_response = distilled.plan.generate_image(&router_client) + let generation_response = distilled.plan().generate_image(&router_client) .await .map_err(|e| { warn!("Image generation failed: {:?}", e); diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/tests/mod.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/tests/mod.rs index e69de29bb2..2af4ed7f0a 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/tests/mod.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/omni_gen/generate/image/tests/mod.rs @@ -0,0 +1 @@ +mod test_flux_1_dev;