This commit is contained in:
Jefsky Wong 2026-05-15 01:25:36 +00:00 committed by GitHub
commit 17790c4650
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 2 deletions

View File

@ -892,11 +892,23 @@ class PromptServer():
async def get_history(request):
max_items = request.rel_url.query.get("max_items", None)
if max_items is not None:
max_items = int(max_items)
try:
max_items = int(max_items)
except (ValueError, TypeError):
return web.json_response(
{"error": "max_items must be an integer"},
status=400
)
offset = request.rel_url.query.get("offset", None)
if offset is not None:
offset = int(offset)
try:
offset = int(offset)
except (ValueError, TypeError):
return web.json_response(
{"error": "offset must be an integer"},
status=400
)
else:
offset = -1

View File

@ -909,6 +909,34 @@ class TestExecution:
assert len(result) <= 1, "Should return at most 1 item when offset is near end"
@pytest.mark.parametrize("invalid_value", ["foo", "abc", "notanint"])
def test_history_max_items_invalid_returns_400(
self, client: ComfyClient, builder: GraphBuilder, invalid_value
):
"""Test that non-integer max_items returns 400 error"""
url = "http://{}/history?max_items={}".format(
client.server_address, invalid_value
)
with pytest.raises(urllib.error.HTTPError) as exc_info:
urllib.request.urlopen(url)
assert exc_info.value.code == 400
body = json.loads(exc_info.value.read())
assert "max_items must be an integer" in body.get("error", "")
@pytest.mark.parametrize("invalid_value", ["foo", "abc", "notanint"])
def test_history_offset_invalid_returns_400(
self, client: ComfyClient, builder: GraphBuilder, invalid_value
):
"""Test that non-integer offset returns 400 error"""
url = "http://{}/history?offset={}".format(
client.server_address, invalid_value
)
with pytest.raises(urllib.error.HTTPError) as exc_info:
urllib.request.urlopen(url)
assert exc_info.value.code == 400
body = json.loads(exc_info.value.read())
assert "offset must be an integer" in body.get("error", "")
# Jobs API tests
def test_jobs_api_job_structure(
self, client: ComfyClient, builder: GraphBuilder