fix(comfy-cloud): /history 完成分支校验 jobs 详情状态码
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,11 @@ async fn fetch_history(db: &sqlx::SqlitePool, prompt_id: &str) -> AppResult<Valu
|
|||||||
.header("X-API-Key", &api_key)
|
.header("X-API-Key", &api_key)
|
||||||
.send().await
|
.send().await
|
||||||
.map_err(|e| AppError::UpstreamError(e.to_string()))?;
|
.map_err(|e| AppError::UpstreamError(e.to_string()))?;
|
||||||
|
if !detail_resp.status().is_success() {
|
||||||
|
let st = detail_resp.status();
|
||||||
|
let body = detail_resp.text().await.unwrap_or_default();
|
||||||
|
return Err(AppError::UpstreamError(format!("Comfy Cloud jobs [{st}]: {body}")));
|
||||||
|
}
|
||||||
let detail_json: Value = detail_resp.json().await.map_err(|e| AppError::UpstreamError(e.to_string()))?;
|
let detail_json: Value = detail_resp.json().await.map_err(|e| AppError::UpstreamError(e.to_string()))?;
|
||||||
let outputs = detail_json.get("outputs");
|
let outputs = detail_json.get("outputs");
|
||||||
Ok(comfy_cloud_job_to_history(prompt_id, status, outputs))
|
Ok(comfy_cloud_job_to_history(prompt_id, status, outputs))
|
||||||
@@ -174,6 +179,37 @@ mod tests {
|
|||||||
assert_eq!(history["p1"]["outputs"]["9"]["images"][0]["filename"], "a.png");
|
assert_eq!(history["p1"]["outputs"]["9"]["images"][0]["filename"], "a.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn history_completed_job_detail_non_success_errors() {
|
||||||
|
let server = MockServer::start().await;
|
||||||
|
Mock::given(method("GET"))
|
||||||
|
.and(path("/api/job/p1/status"))
|
||||||
|
.and(match_header("X-API-Key", "key-123"))
|
||||||
|
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({ "status": "completed" })))
|
||||||
|
.mount(&server).await;
|
||||||
|
Mock::given(method("GET"))
|
||||||
|
.and(path("/api/jobs/p1"))
|
||||||
|
.respond_with(ResponseTemplate::new(500).set_body_json(serde_json::json!({ "error": "boom" })))
|
||||||
|
.mount(&server).await;
|
||||||
|
|
||||||
|
let pool = db_with_site(&server.uri()).await;
|
||||||
|
assert!(fetch_history(&pool, "p1").await.is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn history_failed_status_maps_to_error() {
|
||||||
|
let server = MockServer::start().await;
|
||||||
|
Mock::given(method("GET"))
|
||||||
|
.and(path("/api/job/p1/status"))
|
||||||
|
.and(match_header("X-API-Key", "key-123"))
|
||||||
|
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({ "status": "failed" })))
|
||||||
|
.mount(&server).await;
|
||||||
|
|
||||||
|
let pool = db_with_site(&server.uri()).await;
|
||||||
|
let history = fetch_history(&pool, "p1").await.unwrap();
|
||||||
|
assert_eq!(history["p1"]["status"]["status_str"], "error");
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn view_proxies_file_bytes() {
|
async fn view_proxies_file_bytes() {
|
||||||
let server = MockServer::start().await;
|
let server = MockServer::start().await;
|
||||||
|
|||||||
Reference in New Issue
Block a user