use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64_STANDARD}; use shared_contracts::hyper3d as contract; use super::{ image_data_url::decode_image_data_url, normalize::{normalize_bbox_condition, normalize_required_opaque_text}, options::build_submit_options_from_text, }; #[test] fn validates_and_defaults_submit_options() { let payload = contract::Hyper3dTextToModelRequest { prompt: "宝箱".to_string(), negative_prompt: None, seed: Some(7), geometry_file_format: None, material: None, quality: None, mesh_mode: None, addons: vec!["HighPack".to_string()], bbox_condition: Some(vec![1.0, 2.0, 3.0]), preview_render: None, }; let options = build_submit_options_from_text(&payload).expect("options should build"); assert_eq!(options.geometry_file_format, "glb"); assert_eq!(options.material, "PBR"); assert_eq!(options.quality, "medium"); assert_eq!(options.mesh_mode, "Quad"); assert_eq!(options.addons, vec!["HighPack"]); assert!(options.preview_render); } #[test] fn rejects_invalid_bbox_condition() { let error = normalize_bbox_condition(Some(vec![1.0, 0.0, 3.0])).expect_err("invalid bbox should fail"); assert_eq!(error.status_hint(), crate::Hyper3dStatusHint::BadRequest); } #[test] fn accepts_opaque_subscription_key_without_length_cap() { let long_key = "a".repeat(300); let normalized = normalize_required_opaque_text(&format!(" {long_key} "), "subscriptionKey") .expect("subscription key should be accepted"); assert_eq!(normalized, long_key); } #[test] fn decodes_png_data_url() { let data_url = format!( "data:image/png;base64,{}", BASE64_STANDARD.encode(b"\x89PNG\r\n\x1A\nrest") ); let image = decode_image_data_url(&data_url, 1).expect("image should decode"); assert_eq!(image.mime_type, "image/png"); assert_eq!(image.file_name, "reference-01.png"); assert!(!image.bytes.is_empty()); }