first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -17,7 +17,7 @@ pub(crate) fn sanitized_basename(path_or_filename: &str) -> Option<String> {
|
||||
pub(crate) fn extension_for_content_type(content_type: &str) -> Option<&'static str> {
|
||||
match content_type {
|
||||
"image/gif" => Some("gif"),
|
||||
"image/jpeg" => Some("jpg"),
|
||||
"image/jpeg" | "image/jpg" => Some("jpg"),
|
||||
"image/png" => Some("png"),
|
||||
"image/webp" => Some("webp"),
|
||||
"application/json" => Some("json"),
|
||||
@@ -107,102 +107,5 @@ pub(crate) async fn download_artifact_bytes(
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[cfg(feature = "local_fs")]
|
||||
use crate::server::server_api::ai::{
|
||||
ArtifactDownloadCommonFields, FileArtifactResponseData, ScreenshotArtifactResponseData,
|
||||
};
|
||||
#[cfg(feature = "local_fs")]
|
||||
use chrono::{TimeZone, Utc};
|
||||
|
||||
#[cfg(feature = "local_fs")]
|
||||
fn sample_file_download_response(filename: &str, filepath: &str) -> ArtifactDownloadResponse {
|
||||
ArtifactDownloadResponse::File {
|
||||
common: ArtifactDownloadCommonFields {
|
||||
artifact_uid: "artifact-123".to_string(),
|
||||
created_at: Utc.with_ymd_and_hms(2024, 1, 15, 10, 30, 0).unwrap(),
|
||||
},
|
||||
data: FileArtifactResponseData {
|
||||
download_url: "https://storage.example.com/report.txt".to_string(),
|
||||
expires_at: Utc.with_ymd_and_hms(2024, 1, 15, 11, 30, 0).unwrap(),
|
||||
content_type: "text/plain".to_string(),
|
||||
filepath: filepath.to_string(),
|
||||
filename: filename.to_string(),
|
||||
description: Some("daily summary".to_string()),
|
||||
size_bytes: Some(42),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sanitized_basename_accepts_plain_filename() {
|
||||
assert_eq!(
|
||||
sanitized_basename("report.txt"),
|
||||
Some("report.txt".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sanitized_basename_extracts_from_path() {
|
||||
assert_eq!(
|
||||
sanitized_basename("outputs/report.txt"),
|
||||
Some("report.txt".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "local_fs")]
|
||||
fn default_download_filename_prefers_server_filename() {
|
||||
assert_eq!(
|
||||
default_download_filename(&sample_file_download_response(
|
||||
"report.txt",
|
||||
"outputs/ignored.txt"
|
||||
)),
|
||||
"report.txt"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "local_fs")]
|
||||
fn default_download_filename_uses_content_type_extension_when_filename_missing() {
|
||||
assert_eq!(
|
||||
default_download_filename(&sample_file_download_response("", "outputs/report.txt")),
|
||||
"artifact-artifact-123.txt"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "local_fs")]
|
||||
fn default_download_filename_omits_extension_when_content_type_unknown() {
|
||||
let artifact = ArtifactDownloadResponse::Screenshot {
|
||||
common: ArtifactDownloadCommonFields {
|
||||
artifact_uid: "screenshot-123".to_string(),
|
||||
created_at: Utc.with_ymd_and_hms(2024, 1, 15, 10, 30, 0).unwrap(),
|
||||
},
|
||||
data: ScreenshotArtifactResponseData {
|
||||
download_url: "https://storage.example.com/screenshot".to_string(),
|
||||
expires_at: Utc.with_ymd_and_hms(2024, 1, 15, 11, 30, 0).unwrap(),
|
||||
content_type: "application/octet-stream".to_string(),
|
||||
description: Some("dashboard screenshot".to_string()),
|
||||
},
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
default_download_filename(&artifact),
|
||||
"artifact-screenshot-123"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "local_fs")]
|
||||
fn download_destination_uses_explicit_path() {
|
||||
assert_eq!(
|
||||
download_destination(
|
||||
&sample_file_download_response("report.txt", "outputs/report.txt"),
|
||||
Some(PathBuf::from("downloads/report.txt"))
|
||||
),
|
||||
PathBuf::from("downloads/report.txt")
|
||||
);
|
||||
}
|
||||
}
|
||||
#[path = "artifact_download_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
Reference in New Issue
Block a user