mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-20 02:55:08 +08:00
fix: align knowledge base CRUD API contract with kb_name, canonical payload fields, and matching OpenAPI types (#9000)
Warning: Potential breaking changes in /kb related openapi. * fix(kb): align CRUD API contract end-to-end Unify knowledge base create/update/list with kb_name, canonical_payload, optional list pagination with total, and matching OpenAPI plus dashboard types. * fix: restore _model_dict references, add KnowledgeBaseCreateRequest, fix OpenAPI allOf validation - Replace 3 remaining _model_dict() calls with payload.model_dump(exclude_none=True) - Add KnowledgeBaseCreateRequest schema with required kb_name + embedding_provider_id - Remove additionalProperties: false from OpenAPI allOf sub-schema to avoid validation failures - Use Pydantic Field(alias="name") + populate_by_name=True for legacy name migration - Delegate _canonical_kb_payload to KnowledgeBaseRequest to eliminate duplicated logic - Add getattr default None for update_kb to prevent AttributeError - Add validation error tests: missing kb_name, missing embedding_provider_id * fix: address knowledge base contract follow-ups * fix: preserve knowledge base create error shape
This commit is contained in:
@@ -1192,6 +1192,34 @@ async def test_v1_openapi_uses_pydantic_request_bodies(
|
||||
assert open_api_file_upload["x-astrbot-scope"] == "file"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_v1_knowledge_base_create_validation_uses_api_error_shape(
|
||||
asgi_client: httpx.AsyncClient,
|
||||
):
|
||||
headers = _jwt_headers()
|
||||
|
||||
missing_name_response = await asgi_client.post(
|
||||
"/api/v1/knowledge-bases",
|
||||
json={"embedding_provider_id": "embedding-1"},
|
||||
headers=headers,
|
||||
)
|
||||
missing_provider_response = await asgi_client.post(
|
||||
"/api/v1/knowledge-bases",
|
||||
json={"name": "Docs"},
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
assert missing_name_response.status_code == 200
|
||||
assert missing_name_response.json()["status"] == "error"
|
||||
assert missing_name_response.json()["message"] == "知识库名称不能为空"
|
||||
assert missing_provider_response.status_code == 200
|
||||
assert missing_provider_response.json()["status"] == "error"
|
||||
assert (
|
||||
missing_provider_response.json()["message"]
|
||||
== "缺少参数 embedding_provider_id"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_v1_conversation_path_id_allows_slash(asgi_client: httpx.AsyncClient):
|
||||
response = await asgi_client.get(
|
||||
|
||||
Reference in New Issue
Block a user