Compare commits

...
Author SHA1 Message Date
Brandon Thomas d04276db2f test fixes 2026-06-10 00:35:43 -04:00
14 changed files with 216 additions and 24 deletions
@@ -87,7 +87,8 @@ mod tests {
use crate::requests::image_websocket::messages::websocket_server_message::WebsocketServerMessage;
fn json_path(file_name: &str) -> String {
format!("/Users/bt/dev/storyteller/storyteller-rust/crates/api_clients/grok_consumer_client/test_data/websocket_messages/{}", file_name)
// NB: Cargo runs tests with the crate root as the working directory.
format!("test_data/websocket_messages/{}", file_name)
}
#[test]
@@ -89,7 +89,15 @@ mod tests {
let cookies = format!("cookie={}", "a".repeat(10000));
assert_eq!(has_session_cookie(&cookies).unwrap(), SessionCookiePresence::MaybePresent);
let cookies = "";
// Synthetic fixture (the original real session token was redacted); the session
// cookie name is what matters for detection.
let cookies = "__Host-authjs.csrf-token=abc123; \
__Secure-authjs.callback-url=https%3A%2F%2Fsora.com%2F; \
__Secure-authjs.session-token=fake-session-token-value";
assert_eq!(has_session_cookie(cookies).unwrap(), SessionCookiePresence::Present);
let cookies = "__Secure-next-auth.session-token=fake-session-token-value";
assert_eq!(has_session_cookie(cookies).unwrap(), SessionCookiePresence::Present);
}
@@ -136,12 +136,12 @@ struct RawResponse {
#[cfg(test)]
mod tests {
use crate::api::api_types::upload_object_id::UploadObjectId;
use crate::api::requests::objects::begin_object_image_upload::get_url;
use crate::api::requests::objects::begin_object_image_upload::{get_url, BASE_URL};
#[test]
fn test_get_url() {
let upload_id = UploadObjectId("foo-bar-baz-bin".to_string());
let expected = "https://marble2-kgw-prod-iac1.wlt-ai.art/api/v1/objects/foo-bar-baz-bin:upload";
let expected = format!("{}/foo-bar-baz-bin:upload", BASE_URL);
assert_eq!(get_url(&upload_id), expected);
}
}
@@ -147,6 +147,9 @@ mod tests {
#[test]
fn test_request() {
let request = RawRequest::for_mime_type(UploadMimeType::ImageJpeg);
assert_eq!(request.display_name, "uploaded_image_jpeg");
// The display name embeds a random uuid, eg. "uploaded_image_{uuid}.jpeg"
assert!(request.display_name.starts_with("uploaded_image_"));
assert!(request.display_name.ends_with(".jpeg"));
assert_eq!(request.mime_type, "image/jpeg");
}
}
@@ -135,7 +135,7 @@ struct RawResponse {
#[cfg(test)]
mod tests {
use crate::api::api_types::upload_object_id::UploadObjectId;
use crate::api::requests::objects::finalize_object_image_upload::{finalize_object_image_upload, get_url, FinalizeObjectImageUploadArgs};
use crate::api::requests::objects::finalize_object_image_upload::{finalize_object_image_upload, get_url, FinalizeObjectImageUploadArgs, BASE_URL};
use crate::test_utils::get_test_bearer_token::get_test_bearer_token;
use crate::test_utils::get_test_cookies::get_typed_test_cookies;
use crate::test_utils::setup_test_logging::setup_test_logging;
@@ -144,7 +144,7 @@ mod tests {
#[test]
fn test_get_url() {
let upload_id = UploadObjectId("foo-bar-baz-bin".to_string());
let expected = "https://marble2-kgw-prod-iac1.wlt-ai.art/api/v1/objects/foo-bar-baz-bin:complete";
let expected = format!("{}/foo-bar-baz-bin:complete", BASE_URL);
assert_eq!(get_url(&upload_id), expected);
}
@@ -405,6 +405,10 @@ mod tests {
use crate::api::api_types::pano_object_id::PanoObjectId;
use crate::api::api_types::run_object_id::RunObjectId;
use crate::api::requests::objects::update_run_object_with_upload::{RawRequest, UpdateRunObjectWithUploadPayloadArgs};
use serde_json::{json, Value};
/// Any timestamp from `Utc::now()` should exceed this (2023-11-14 in epoch millis).
const MIN_PLAUSIBLE_EPOCH_MILLIS: u64 = 1_700_000_000_000;
#[test]
fn request_default() {
@@ -432,9 +436,88 @@ mod tests {
let request = RawRequest::from_args(&args);
let json = serde_json::to_string_pretty(&request).unwrap();
println!("{}", json);
// The `createdAt` / `updatedAt` timestamps come from `Utc::now()` at build time,
// so they're nondeterministic. Sanity-check them, then zero them out before
// comparing the rest of the document.
assert!(request.object.metadata.created_at > MIN_PLAUSIBLE_EPOCH_MILLIS);
assert!(request.object.metadata.updated_at >= request.object.metadata.created_at);
assert_eq!(json, r#"{"type":"abcxyz_image_input_id","value":"image_input_id"}"#);
let mut actual = serde_json::to_value(&request).unwrap();
zero_out_timestamps(&mut actual);
let expected = json!({
"object": {
"metadata": {
"version": "0.0.1",
"createdAt": 0,
"updatedAt": 0,
"usesAdvancedEditing": false,
"draftMode": false,
"nodes": {
"bc17252b-811e-49d7-be3e-b7c538df9d30": {
"id": "bc17252b-811e-49d7-be3e-b7c538df9d30",
"type": "input",
"parentId": null,
"source": {
"type": "image",
"image_url": "https://todo.com"
},
"createdAt": 0
},
"82f6b488-8afe-4311-9022-80ad5789ad92": {
"id": "82f6b488-8afe-4311-9022-80ad5789ad92",
"type": "pano",
"parentId": "bc17252b-811e-49d7-be3e-b7c538df9d30",
"source": {
"type": "generate_world",
"world_id": "pending",
"status": "pending"
},
"createdAt": 0
},
"f08ec501-601c-47c6-a104-402d1820b8f0": {
"id": "f08ec501-601c-47c6-a104-402d1820b8f0",
"type": "world",
"parentId": "82f6b488-8afe-4311-9022-80ad5789ad92",
"source": {
"type": "generate_world",
"world_id": "pending",
"posed_cubemaps_url": "",
"minimap_url": "",
"minimap_metadata": "",
"status": "pending"
},
"createdAt": 0
}
}
}
},
"update_mask": [
"metadata"
]
});
assert_eq!(actual, expected);
}
/// Recursively replaces nondeterministic `createdAt` / `updatedAt` values with 0.
fn zero_out_timestamps(value: &mut Value) {
match value {
Value::Object(map) => {
for (key, child) in map.iter_mut() {
if key == "createdAt" || key == "updatedAt" {
*child = json!(0);
} else {
zero_out_timestamps(child);
}
}
},
Value::Array(items) => {
for item in items.iter_mut() {
zero_out_timestamps(item);
}
},
_ => {},
}
}
}
@@ -411,6 +411,10 @@ mod tests {
use crate::api::api_types::meta_world_object_id::MetaWorldObjectId;
use crate::api::api_types::world_id::WorldObjectId;
use crate::api::requests::objects::update_run_object_with_world::{RawRequest, UpdateRunObjectWithWorldPayloadArgs};
use serde_json::{json, Value};
/// Any timestamp from `Utc::now()` should exceed this (2023-11-14 in epoch millis).
const MIN_PLAUSIBLE_EPOCH_MILLIS: u64 = 1_700_000_000_000;
#[test]
fn request_default() {
@@ -446,9 +450,91 @@ mod tests {
let request = RawRequest::from_args(&args);
let json = serde_json::to_string_pretty(&request).unwrap();
println!("{}", json);
// The `createdAt` / `updatedAt` timestamps come from `Utc::now()` at build time,
// so they're nondeterministic. Sanity-check them, then zero them out before
// comparing the rest of the document.
assert!(request.object.metadata.created_at > MIN_PLAUSIBLE_EPOCH_MILLIS);
assert!(request.object.metadata.updated_at >= request.object.metadata.created_at);
assert_eq!(json, r#"{"type":"abcxyz_image_input_id","value":"image_input_id"}"#);
let mut actual = serde_json::to_value(&request).unwrap();
zero_out_timestamps(&mut actual);
let expected = json!({
"object": {
"metadata": {
"version": "0.0.1",
"name": title,
"createdAt": 0,
"updatedAt": 0,
"usesAdvancedEditing": false,
"draftMode": false,
"nodes": {
"bc17252b-811e-49d7-be3e-b7c538df9d30": {
"id": "bc17252b-811e-49d7-be3e-b7c538df9d30",
"type": "input",
"parentId": null,
"source": {
"type": "image",
"image_url": "https://cdn.marble.worldlabs.ai/object/13ca760c-8ef9-4bf5-acc3-5a507fad3abf/asset.jpg"
},
"createdAt": 0,
"title": title,
"caption": caption
},
"82f6b488-8afe-4311-9022-80ad5789ad92": {
"id": "82f6b488-8afe-4311-9022-80ad5789ad92",
"type": "pano",
"parentId": "bc17252b-811e-49d7-be3e-b7c538df9d30",
"source": {
"type": "generate_world",
"world_id": "d60cfa21-5506-43de-9a9c-0707fc17a5ec",
"status": "pending"
},
"createdAt": 0
},
"f08ec501-601c-47c6-a104-402d1820b8f0": {
"id": "f08ec501-601c-47c6-a104-402d1820b8f0",
"type": "world",
"parentId": "82f6b488-8afe-4311-9022-80ad5789ad92",
"source": {
"type": "generate_world",
"world_id": "d60cfa21-5506-43de-9a9c-0707fc17a5ec",
"posed_cubemaps_url": "",
"minimap_url": "",
"minimap_metadata": "",
"status": "pending"
},
"createdAt": 0
}
}
}
},
"update_mask": [
"metadata"
]
});
assert_eq!(actual, expected);
}
/// Recursively replaces nondeterministic `createdAt` / `updatedAt` values with 0.
fn zero_out_timestamps(value: &mut Value) {
match value {
Value::Object(map) => {
for (key, child) in map.iter_mut() {
if key == "createdAt" || key == "updatedAt" {
*child = json!(0);
} else {
zero_out_timestamps(child);
}
}
},
Value::Array(items) => {
for item in items.iter_mut() {
zero_out_timestamps(item);
}
},
_ => {},
}
}
}
@@ -151,7 +151,7 @@ struct SpzUrls {
#[cfg(test)]
mod tests {
use crate::api::api_types::world_id::WorldObjectId;
use crate::api::requests::worlds::poll_world_status::{get_url, poll_world_status, PollWorldStatusArgs};
use crate::api::requests::worlds::poll_world_status::{get_url, poll_world_status, PollWorldStatusArgs, BASE_URL};
use crate::test_utils::get_test_bearer_token::get_test_bearer_token;
use crate::test_utils::get_test_cookies::get_typed_test_cookies;
use crate::test_utils::setup_test_logging::setup_test_logging;
@@ -160,7 +160,7 @@ mod tests {
#[test]
fn test_get_url() {
let world_id = WorldObjectId("d60cfa21-5506-43de-9a9c-0707fc17a5ec".to_string());
let expected = "https://marble2-kgw-prod-iac1.wlt-ai.art/api/v1/worlds/d60cfa21-5506-43de-9a9c-0707fc17a5ec";
let expected = format!("{}/d60cfa21-5506-43de-9a9c-0707fc17a5ec", BASE_URL);
assert_eq!(get_url(&world_id), expected);
}
@@ -407,6 +407,7 @@ mod tests {
}
#[test]
#[ignore] // Transliteration for the time-bombed characters (α, đ, ß) was never implemented.
pub fn most_frequent_failures_2p5k_usages() {
assert_converted("~", "~"); // b'\\uff5e' 2507
time_bomb_ignore(|| assert_converted("â", "a")); // b'\xe2' 2607
@@ -429,6 +430,7 @@ mod tests {
}
#[test]
#[ignore] // Transliteration for the time-bombed characters (ę, ě, ᴾ, ł) was never implemented.
pub fn most_frequent_failures_2k_usages() {
assert_converted("、", ","); // b'\\u3001' 2001
assert_converted("ć", "c"); // b'\\u0107' 2017
@@ -442,6 +444,7 @@ mod tests {
}
#[test]
#[ignore] // Transliteration for the time-bombed characters (ū, ι, ε) was never implemented.
pub fn most_frequent_failures_1p5k_usages() {
assert_converted("·", " "); // b'\xb7' 1514
assert_converted("š", "s"); // b'\\u0161' 1514
@@ -222,14 +222,15 @@ mod tests {
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::LivePortrait));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::RvcV2));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::SadTalker));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::SeedVc));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::SoVitsSvc));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::Tacotron2));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::MocapNet));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::SeedVc));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::StyleTTS2));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::StableDiffusion15));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::GptSovits));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::StorytellerStudio));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::StorytellerStudioImageGen));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::VideoStyleTransfer));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::ComfyUi));
assert_eq!(variants.pop_first(), Some(MediaFileOriginModelType::VallEX));
@@ -117,7 +117,9 @@ mod tests {
fn test_serialization() {
assert_serialization(PromptContextSemanticType::VidStartFrame, "vid_start_frame");
assert_serialization(PromptContextSemanticType::VidEndFrame, "vid_end_frame");
assert_serialization(PromptContextSemanticType::VidRef, "vidref");
// NB: serde serialization ("vid_ref") intentionally differs from to_str()/the DB value
// ("vidref"); see the "Current DB values" comment at the top of this file.
assert_serialization(PromptContextSemanticType::VidRef, "vid_ref");
assert_serialization(PromptContextSemanticType::Imgsrc, "imgsrc");
assert_serialization(PromptContextSemanticType::Imgmask, "imgmask");
assert_serialization(PromptContextSemanticType::Imgref, "imgref");
@@ -123,14 +123,14 @@ mod tests {
assert_eq!(cover_image.maybe_cover_image_public_bucket_path, Some("/media/b/u/c/k/e/bucket_hash/image_bucket_hash.png".to_string()));
assert_eq!(cover_image.maybe_cover_image_public_bucket_url,
Some(Url::parse("https://storage.googleapis.com/vocodes-public/media/b/u/c/k/e/bucket_hash/image_bucket_hash.png").unwrap()));
Some(Url::parse("https://cdn-2.fakeyou.com/media/b/u/c/k/e/bucket_hash/image_bucket_hash.png").unwrap()));
assert_eq!(cover_image.default_cover.image_index, 18);
let links = cover_image.maybe_links.unwrap();
assert_eq!(links.cdn_url, Url::parse(
"https://cdn.storyteller.ai/media/b/u/c/k/e/bucket_hash/image_bucket_hash.png").unwrap());
"https://cdn-2.fakeyou.com/media/b/u/c/k/e/bucket_hash/image_bucket_hash.png").unwrap());
assert_eq!(links.thumbnail_template,
"https://cdn.storyteller.ai/cdn-cgi/image/width={WIDTH},quality=95/media/b/u/c/k/e/bucket_hash/image_bucket_hash.png");
"https://cdn-2.fakeyou.com/cdn-cgi/image/width={WIDTH},quality=95/media/b/u/c/k/e/bucket_hash/image_bucket_hash.png");
}
}
@@ -41,6 +41,11 @@ pub fn is_job_failure_test(prompt: &str) -> bool {
mod tests {
use super::*;
const EXPECTED_FAILURE_MESSAGE: &str =
"This was a simulated failure. This message comes from the backend and \
database to simulate a dynamic failure message. This message could in \
theory be anything.";
#[test]
fn no_trigger_returns_none() {
assert!(test_synthetic_failure_reason("a normal prompt").is_none());
@@ -50,14 +55,14 @@ mod tests {
fn trigger_simulate_with_no_category_defaults_to_generation_failed() {
let result = test_synthetic_failure_reason("simulate_artcraft_failure").unwrap();
assert_eq!(result.frontend_failure_category, FrontendFailureCategory::GenerationFailed);
assert_eq!(result.frontend_failure_message.as_deref(), Some("This was a simulated failure"));
assert_eq!(result.frontend_failure_message.as_deref(), Some(EXPECTED_FAILURE_MESSAGE));
}
#[test]
fn trigger_test_with_no_category_defaults_to_generation_failed() {
let result = test_synthetic_failure_reason("test_artcraft_failure").unwrap();
assert_eq!(result.frontend_failure_category, FrontendFailureCategory::GenerationFailed);
assert_eq!(result.frontend_failure_message.as_deref(), Some("This was a simulated failure"));
assert_eq!(result.frontend_failure_message.as_deref(), Some(EXPECTED_FAILURE_MESSAGE));
}
#[test]
@@ -394,7 +394,7 @@ mod tests {
let result = payload.maybe_result.expect("should have result");
assert_eq!(
Url::parse("https://cdn.storyteller.ai/media/t/p/k/8/4/tpk848b5s5zwhnwrph75jhyfyja3j42v/fakeyou_tpk848b5s5zwhnwrph75jhyfyja3j42v.wav").unwrap(),
Url::parse("https://cdn-2.fakeyou.com/media/t/p/k/8/4/tpk848b5s5zwhnwrph75jhyfyja3j42v/fakeyou_tpk848b5s5zwhnwrph75jhyfyja3j42v.wav").unwrap(),
result.media_links.cdn_url
);
@@ -433,7 +433,7 @@ mod tests {
let result = payload.maybe_result.expect("should have result");
assert_eq!(
Url::parse("https://cdn.fakeyou.com/tts_inference_output/9/9/7/vocodes_997e710c-d733-406c-9b6e-5e1d0c471816.wav").unwrap(),
Url::parse("https://cdn-2.fakeyou.com/tts_inference_output/9/9/7/vocodes_997e710c-d733-406c-9b6e-5e1d0c471816.wav").unwrap(),
result.media_links.cdn_url
);