fix(comfy-cloud): /history 完成分支校验 jobs 详情状态码

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
boos
2026-06-17 23:39:18 +08:00
parent 7758858141
commit 08a2980f5f
+36
View File
@@ -71,6 +71,11 @@ async fn fetch_history(db: &sqlx::SqlitePool, prompt_id: &str) -> AppResult<Valu
.header("X-API-Key", &api_key)
.send().await
.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 outputs = detail_json.get("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");
}
#[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]
async fn view_proxies_file_bytes() {
let server = MockServer::start().await;