fix: 将52号接口范围限定为GPU worker
撤回52号网关路由、图片字段改名和mock改动,gateway目录恢复a3fddbb。worker保持base64和null响应,更新接口说明和回归测试。 验证:worker API、IP限制与网关兼容性共54项测试通过。
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
"""The legacy interface 5 and new interface 52 forward to separate worker paths."""
|
||||
"""Interface 52 belongs to the GPU worker; the gateway keeps its legacy routes."""
|
||||
import asyncio
|
||||
import importlib
|
||||
|
||||
import pytest
|
||||
from starlette.requests import Request
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name,path", [
|
||||
("hairline_generate", "/api/v1/hairline/generate"),
|
||||
("hairline_generate_52", "/api/v1/hairline/generate-52"),
|
||||
])
|
||||
def test_distinct_hairline_forwarding(monkeypatch, name, path):
|
||||
def test_legacy_hairline_forwarding(monkeypatch):
|
||||
name, path = "hairline_generate", "/api/v1/hairline/generate"
|
||||
gateway = importlib.import_module("gateway.app")
|
||||
request = Request({"type": "http", "method": "POST", "path": path, "headers": []})
|
||||
calls = []
|
||||
@@ -25,3 +21,9 @@ def test_distinct_hairline_forwarding(monkeypatch, name, path):
|
||||
assert next(route for route in gateway.app.routes if getattr(route, "path", None) == path).endpoint is endpoint
|
||||
assert asyncio.run(endpoint(request)) == {"forwarded_to": path}
|
||||
assert calls == [path]
|
||||
|
||||
|
||||
def test_interface52_is_not_exposed_by_gateway():
|
||||
gateway = importlib.import_module("gateway.app")
|
||||
assert not any(getattr(route, "path", None) == "/api/v1/hairline/generate-52"
|
||||
for route in gateway.app.routes)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Nullable/deprecated worker images retain their documented gateway keys."""
|
||||
"""Keep the gateway's historical image-field conversion unchanged."""
|
||||
import asyncio
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
@@ -11,14 +11,12 @@ from starlette.requests import Request
|
||||
from gateway.forward import rewrite_base64_to_url
|
||||
|
||||
|
||||
def test_nullable_image_fields_keep_external_names(tmp_path):
|
||||
def test_nullable_image_fields_keep_original_names(tmp_path):
|
||||
value = {"hairline_images": [{"image_high_base64": None, "image_low_base64": None,
|
||||
"grown_image_base64": None}],
|
||||
"high_hairline_center_point": None, "face_measure": None}
|
||||
actual = rewrite_base64_to_url(value, "https://example.test", str(tmp_path), rewrite_null_images=True)
|
||||
assert actual == {"hairline_images": [{"image_high_url": None, "image_low_url": None,
|
||||
"grown_image_url": None}],
|
||||
"high_hairline_center_point": None, "face_measure": None}
|
||||
actual = rewrite_base64_to_url(value, "https://example.test", str(tmp_path))
|
||||
assert actual == value
|
||||
assert not list(tmp_path.iterdir())
|
||||
|
||||
|
||||
@@ -30,23 +28,18 @@ def test_nonempty_images_still_rewrite_alongside_null_fields(tmp_path):
|
||||
Image.new("RGBA", (2, 2), (255, 255, 255, 0)).save(buf, format="PNG")
|
||||
value = {"image_middle_base64": base64.b64encode(buf.getvalue()).decode(),
|
||||
"image_high_base64": None}
|
||||
actual = rewrite_base64_to_url(value, "https://example.test", str(tmp_path), rewrite_null_images=True)
|
||||
actual = rewrite_base64_to_url(value, "https://example.test", str(tmp_path))
|
||||
assert actual["image_middle_url"].startswith("https://example.test/static/annotations/")
|
||||
assert actual["image_high_url"] is None
|
||||
assert actual["image_high_base64"] is None
|
||||
assert "image_high_url" not in actual
|
||||
assert len(list(tmp_path.iterdir())) == 1
|
||||
|
||||
|
||||
def test_legacy_nullable_image_field_names_remain_unchanged(tmp_path):
|
||||
value = {"hairline_images": [{"grown_image_base64": None}], "face_measure": None}
|
||||
assert rewrite_base64_to_url(value, "https://example.test", str(tmp_path)) == value
|
||||
assert not list(tmp_path.iterdir())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path,expected_key", [
|
||||
("/api/v1/hairline/generate", "grown_image_base64"),
|
||||
("/api/v1/hairline/generate-52", "grown_image_url"),
|
||||
("/api/v1/hair/grow", "grown_image_base64"),
|
||||
])
|
||||
def test_proxy_rewrites_null_images_only_for_interface52(tmp_path, monkeypatch, path, expected_key):
|
||||
def test_proxy_keeps_original_null_image_fields(tmp_path, monkeypatch, path, expected_key):
|
||||
import gateway.config as config
|
||||
import gateway.forward as forward
|
||||
|
||||
|
||||
@@ -94,8 +94,8 @@ def test_gateway_does_not_apply_worker_ip_policy(policy, monkeypatch):
|
||||
monkeypatch.setattr(gateway, '_proxy', proxy)
|
||||
# Deliberately skip lifespan: no workers or configuration are needed.
|
||||
client = TestClient(gateway.app, client=('203.0.113.9', 50000))
|
||||
assert client.post('/api/v1/hairline/generate-52').json()['code'] == 0
|
||||
assert client.post('/api/v1/hairline/generate-52').status_code == 404
|
||||
assert client.post('/api/v1/hairline/generate').json()['code'] == 0
|
||||
assert client.post('/api/v1/hair/grow').json()['code'] == 0
|
||||
assert client.get('/static/test_interface52.html').status_code == 200
|
||||
assert calls == ['/api/v1/hairline/generate-52', '/api/v1/hairline/generate', '/api/v1/hair/grow']
|
||||
assert calls == ['/api/v1/hairline/generate', '/api/v1/hair/grow']
|
||||
|
||||
Reference in New Issue
Block a user