From 2e2a037eb81d1b8f1fd1bcbf3bdf2c945429e776 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 18 Sep 2026 12:24:58 +0800 Subject: [PATCH] fix(subscribe): align fork response model with returned id --- app/api/endpoints/subscribe.py | 2 +- tests/test_subscribe_endpoint.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/api/endpoints/subscribe.py b/app/api/endpoints/subscribe.py index 886ea57bf..5744232d2 100644 --- a/app/api/endpoints/subscribe.py +++ b/app/api/endpoints/subscribe.py @@ -740,7 +740,7 @@ async def subscribe_share_delete(share_id: int, _: _SchemaTokenPayload = Depends ) -@router.post("/fork", summary="复用订阅", response_model=_SchemaResponse[None]) +@router.post("/fork", summary="复用订阅", response_model=_SchemaResponse[_SchemaIdData]) async def subscribe_fork( sub: _SchemaSubscribeShare, current_user: ApiPrincipal = Depends(get_current_active_user_async), diff --git a/tests/test_subscribe_endpoint.py b/tests/test_subscribe_endpoint.py index 26b1fee91..43437e8c3 100644 --- a/tests/test_subscribe_endpoint.py +++ b/tests/test_subscribe_endpoint.py @@ -96,6 +96,26 @@ class TestSubscribeEndpoint: 订阅接口回归测试。 """ + def test_subscribe_fork_response_preserves_created_subscription_id(self): + """复用订阅的响应模型必须允许返回新建订阅 ID。""" + from app.api.endpoints import subscribe as subscribe_endpoint + from app.schemas.common import IdData + from app.schemas.response import Response + + route = next( + route + for route in subscribe_endpoint.router.routes + if route.path == "/fork" and "POST" in route.methods + ) + payload = Response[IdData]( + success=True, + data=IdData(id=2), + ).model_dump() + + response = route.response_model.model_validate(payload) + + assert response.data.id == 2 + def test_read_subscribes_scopes_regular_user_and_keeps_superuser_global(self): """ 普通用户只能看到自己创建的订阅,超级用户保留全局视图。