fix: restore yaml import and async job result contracts

This commit is contained in:
a.tolmachev
2026-05-03 07:40:06 +00:00
parent 420e9416e5
commit bf270336d9
7 changed files with 275 additions and 78 deletions
+57
View File
@@ -1940,6 +1940,63 @@ mod tests {
assert!(body["error"]["context"]["poll_after_ms"].as_u64().unwrap() > 0);
}
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn allows_completed_async_job_result_fetch_without_poll_delay() {
let registry = test_registry().await;
let storage_root = test_storage_root("async_job_completed_result");
let upstream_base_url = spawn_upstream_server().await;
let base_url = spawn_admin_api(build_test_app(registry.clone(), storage_root)).await;
let client = authorized_client(&base_url).await;
let created = client
.post(format!("{base_url}/operations"))
.json(&test_rest_async_job_operation_payload(
&upstream_base_url,
"crm_async_job_completed_result",
))
.send()
.await
.unwrap()
.json::<Value>()
.await
.unwrap();
let operation_id = OperationId::new(created["operation_id"].as_str().unwrap().to_owned());
let now = OffsetDateTime::now_utc();
let job_id = AsyncJobId::new("job_completed_result".to_owned());
registry
.create_async_job(CreateAsyncJobRequest {
job: &AsyncJobHandle {
id: job_id.clone(),
workspace_id: WorkspaceId::new(DEFAULT_WORKSPACE_ID),
agent_id: None,
operation_id,
status: JobStatus::Completed,
progress: json!({ "pct": 100 }),
result: Some(json!({ "id": "lead_123" })),
error: None,
expires_at: Some(now + time::Duration::minutes(5)),
last_poll_at: Some(now),
created_at: now,
updated_at: now,
finished_at: Some(now),
},
})
.await
.unwrap();
let response = client
.get(format!("{base_url}/async-jobs/{}/result", job_id.as_str()))
.send()
.await
.unwrap();
let status = response.status();
let body = response.json::<Value>().await.unwrap();
assert_eq!(status, reqwest::StatusCode::OK);
assert_eq!(body["id"], "lead_123");
}
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn returns_structured_context_for_missing_stream_session() {
+6 -3
View File
@@ -1719,9 +1719,12 @@ impl AdminService {
)
})?;
ensure_async_job_workspace(&job, workspace_id)?;
let job = self
.touch_async_job_poll_if_ready(workspace_id, job)
.await?;
let job = if matches!(job.status, JobStatus::Completed) {
job
} else {
self.touch_async_job_poll_if_ready(workspace_id, job)
.await?
};
match job.status {
JobStatus::Completed => Ok(job.result.unwrap_or(Value::Null)),