perf(webui): accelerate JSONL session list and thread loading (#5194)

This commit is contained in:
chengyongru
2026-08-03 09:51:35 +08:00
committed by GitHub
parent db6c9effc3
commit 580824a15a
14 changed files with 864 additions and 129 deletions
+38
View File
@@ -0,0 +1,38 @@
"""Tests for shared embedded WebUI HTTP helpers."""
import gzip
import json
from nanobot.webui.http_utils import http_json_response
def test_http_json_response_compresses_large_payload_when_gzip_is_accepted() -> None:
payload = {"message": "响应内容" * 2_000}
response = http_json_response(payload, accept_encoding="br, gzip; q=0.5")
assert response.headers["Content-Encoding"] == "gzip"
assert response.headers["Vary"] == "Accept-Encoding"
assert int(response.headers["Content-Length"]) == len(response.body)
assert json.loads(gzip.decompress(response.body)) == payload
def test_http_json_response_preserves_identity_when_gzip_is_rejected() -> None:
payload = {"message": "x" * 8_000}
response = http_json_response(payload, accept_encoding="gzip;q=0, br")
assert "Content-Encoding" not in response.headers
assert response.headers["Vary"] == "Accept-Encoding"
assert int(response.headers["Content-Length"]) == len(response.body)
assert json.loads(response.body) == payload
def test_http_json_response_does_not_compress_small_payload() -> None:
payload = {"ok": True}
response = http_json_response(payload, accept_encoding="gzip")
assert "Content-Encoding" not in response.headers
assert response.headers["Vary"] == "Accept-Encoding"
assert json.loads(response.body) == payload