test: GET /api/jobs/{id} should include workflow for running/pending jobs

Reproduces #14995: the jobs detail endpoint only embeds the workflow for
terminal (completed/failed/cancelled) jobs. Since the frontend caches
this response by job id and never refetches, a job opened while still
running or queued permanently loses its 'Open as workflow' / 'Add to
current workflow' actions, even after it finishes.
This commit is contained in:
Claude
2026-07-31 10:08:33 +00:00
parent 5cc026f5b8
commit e8b10ed645

View File

@@ -13,6 +13,7 @@ from comfy_execution.jobs import (
apply_sorting,
has_3d_extension,
validate_job_id,
get_job,
)
@@ -450,6 +451,56 @@ class TestNormalizeQueueItem:
assert job['workflow_id'] == 'workflow-abc'
class TestGetJobIncludesWorkflowForNonTerminalJobs:
"""Regression test for https://github.com/Comfy-Org/ComfyUI/issues/14995
GET /api/jobs/{job_id} must include the 'workflow' field for running and
pending jobs, not just completed/failed/cancelled ones, since the frontend
caches this response by job id and never refetches once cached. Omitting
the field while a job is in progress permanently starves the frontend's
cache of the workflow, even after the job finishes and history would have
supplied it.
"""
def _make_queue_item(self, prompt_id):
return (
10, # priority
prompt_id,
{'nodes': {'1': {}}}, # prompt
{
'create_time': 1234567890,
'extra_pnginfo': {'workflow': {'id': 'workflow-abc'}},
}, # extra_data
['node1'], # outputs_to_execute
)
def test_running_job_detail_includes_workflow(self):
item = self._make_queue_item('prompt-running')
job = get_job('prompt-running', running=[item], queued=[], history={})
assert job['status'] == 'in_progress'
assert job['workflow'] == {
'prompt': {'nodes': {'1': {}}},
'extra_data': {
'create_time': 1234567890,
'extra_pnginfo': {'workflow': {'id': 'workflow-abc'}},
},
}
def test_pending_job_detail_includes_workflow(self):
item = self._make_queue_item('prompt-pending')
job = get_job('prompt-pending', running=[], queued=[item], history={})
assert job['status'] == 'pending'
assert job['workflow'] == {
'prompt': {'nodes': {'1': {}}},
'extra_data': {
'create_time': 1234567890,
'extra_pnginfo': {'workflow': {'id': 'workflow-abc'}},
},
}
class TestNormalizeHistoryItem:
"""Unit tests for normalize_history_item()"""