mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-09-02 11:47:05 +08:00
remove prompt[2] and prompt[4] from history_v2 response
This commit is contained in:
parent
4a2172758a
commit
565b537620
@ -1132,6 +1132,12 @@ class PromptQueue:
|
|||||||
for key in selected_keys:
|
for key in selected_keys:
|
||||||
item = copy.deepcopy(self.history[key])
|
item = copy.deepcopy(self.history[key])
|
||||||
item["prompt_id"] = key
|
item["prompt_id"] = key
|
||||||
|
|
||||||
|
# Remove prompt[2] (workflow) and prompt[4] (execute_outputs) to reduce response size
|
||||||
|
if "prompt" in item:
|
||||||
|
priority, prompt_id, _, extra_data, _ = item["prompt"]
|
||||||
|
item["prompt"] = [priority, prompt_id, extra_data]
|
||||||
|
|
||||||
history_items.append(item)
|
history_items.append(item)
|
||||||
|
|
||||||
return {"history": history_items}
|
return {"history": history_items}
|
||||||
|
|||||||
@ -742,3 +742,58 @@ class TestExecution:
|
|||||||
# Test offset beyond available items
|
# Test offset beyond available items
|
||||||
beyond_offset = client.get_ordered_history(max_items=2, offset=10)
|
beyond_offset = client.get_ordered_history(max_items=2, offset=10)
|
||||||
assert len(beyond_offset["history"]) == 0, "Offset beyond items should return empty list"
|
assert len(beyond_offset["history"]) == 0, "Offset beyond items should return empty list"
|
||||||
|
|
||||||
|
def test_ordered_history_prompt_field_filtering_unit(self):
|
||||||
|
"""Unit test for prompt field filtering logic in get_ordered_history."""
|
||||||
|
from execution import PromptQueue
|
||||||
|
|
||||||
|
# Mock server
|
||||||
|
class MockServer:
|
||||||
|
def queue_updated(self): pass
|
||||||
|
|
||||||
|
# Create queue and add mock history
|
||||||
|
queue = PromptQueue(MockServer())
|
||||||
|
|
||||||
|
# Mock history entry with full prompt structure
|
||||||
|
mock_prompt_tuple = (
|
||||||
|
12345, # priority/timestamp
|
||||||
|
'test-prompt-123', # prompt_id
|
||||||
|
{'nodes': {'1': {'class_type': 'SaveImage'}}}, # workflow (should be filtered)
|
||||||
|
{'client_id': 'test-client'}, # extra_data
|
||||||
|
['1'] # execute_outputs (should be filtered)
|
||||||
|
)
|
||||||
|
|
||||||
|
queue.history['test-prompt-123'] = {
|
||||||
|
'prompt': mock_prompt_tuple,
|
||||||
|
'outputs': {'1': {'images': []}},
|
||||||
|
'status': {'completed': True, 'messages': []},
|
||||||
|
'meta': {'1': {'node_id': '1'}}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test get_ordered_history with our filtering
|
||||||
|
result = queue.get_ordered_history()
|
||||||
|
|
||||||
|
# Verify structure
|
||||||
|
assert "history" in result, "Result should have history key"
|
||||||
|
assert len(result["history"]) == 1, "Should have one history item"
|
||||||
|
|
||||||
|
history_item = result["history"][0]
|
||||||
|
|
||||||
|
# Verify prompt_id field is added
|
||||||
|
assert "prompt_id" in history_item, "History item should have prompt_id field"
|
||||||
|
assert history_item["prompt_id"] == 'test-prompt-123', "prompt_id should match"
|
||||||
|
|
||||||
|
# Verify prompt field is filtered
|
||||||
|
filtered_prompt = history_item["prompt"]
|
||||||
|
assert isinstance(filtered_prompt, list), "Filtered prompt should be a list"
|
||||||
|
assert len(filtered_prompt) == 3, f"Filtered prompt should have 3 elements, got {len(filtered_prompt)}"
|
||||||
|
|
||||||
|
# Verify correct elements are preserved
|
||||||
|
assert filtered_prompt[0] == 12345, "Priority should be preserved"
|
||||||
|
assert filtered_prompt[1] == 'test-prompt-123', "Prompt ID should be preserved"
|
||||||
|
assert filtered_prompt[2] == {'client_id': 'test-client'}, "Extra data should be preserved"
|
||||||
|
|
||||||
|
# Verify other fields are unchanged
|
||||||
|
assert history_item["outputs"] == {'1': {'images': []}}, "Outputs should be unchanged"
|
||||||
|
assert history_item["status"] == {'completed': True, 'messages': []}, "Status should be unchanged"
|
||||||
|
assert history_item["meta"] == {'1': {'node_id': '1'}}, "Meta should be unchanged"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user