fix: 修复智能体配置默认创建缺少agent_id参数
Agent-Logs-Url: https://github.com/xerrors/Yuxi/sessions/933d6368-5424-4327-99cf-3722768afa57 Co-authored-by: xerrors <35524243+xerrors@users.noreply.github.com>
This commit is contained in:
parent
44888094d0
commit
fb05161f10
@ -208,6 +208,7 @@ async def list_agent_configs(
|
||||
if not items:
|
||||
await repo.get_or_create_default(
|
||||
department_id=current_user.department_id,
|
||||
agent_id=agent_id,
|
||||
created_by=str(current_user.id),
|
||||
)
|
||||
items = await repo.list_by_department_agent(department_id=current_user.department_id, agent_id=agent_id)
|
||||
|
||||
70
backend/test/test_chat_router_configs.py
Normal file
70
backend/test/test_chat_router_configs.py
Normal file
@ -0,0 +1,70 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from server.routers.chat_router import chat
|
||||
from server.utils.auth_middleware import get_db, get_required_user
|
||||
from yuxi.storage.postgres.models_business import User
|
||||
|
||||
|
||||
def _build_app() -> FastAPI:
|
||||
app = FastAPI()
|
||||
app.include_router(chat, prefix="/api")
|
||||
|
||||
async def fake_db():
|
||||
return None
|
||||
|
||||
async def fake_required_user():
|
||||
return User(
|
||||
username="admin",
|
||||
user_id="admin",
|
||||
password_hash="x",
|
||||
role="admin",
|
||||
department_id=1,
|
||||
id=1,
|
||||
)
|
||||
|
||||
app.dependency_overrides[get_db] = fake_db
|
||||
app.dependency_overrides[get_required_user] = fake_required_user
|
||||
return app
|
||||
|
||||
|
||||
def test_list_agent_configs_creates_default_with_agent_id(monkeypatch):
|
||||
agent_id = "demo-agent"
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
class DummyConfig:
|
||||
id = 1
|
||||
name = "初始配置"
|
||||
description = None
|
||||
icon = None
|
||||
pics = []
|
||||
examples = []
|
||||
is_default = True
|
||||
|
||||
class DummyRepo:
|
||||
def __init__(self, _db):
|
||||
self.calls = 0
|
||||
|
||||
async def list_by_department_agent(self, *, department_id, agent_id):
|
||||
self.calls += 1
|
||||
if self.calls == 1:
|
||||
return []
|
||||
return [DummyConfig()]
|
||||
|
||||
async def get_or_create_default(self, *, department_id, agent_id, created_by=None):
|
||||
captured["department_id"] = department_id
|
||||
captured["agent_id"] = agent_id
|
||||
captured["created_by"] = created_by
|
||||
return None
|
||||
|
||||
monkeypatch.setattr("server.routers.chat_router.agent_manager.get_agent", lambda _agent_id: object())
|
||||
monkeypatch.setattr("server.routers.chat_router.AgentConfigRepository", DummyRepo)
|
||||
|
||||
client = TestClient(_build_app())
|
||||
resp = client.get(f"/api/chat/agent/{agent_id}/configs")
|
||||
assert resp.status_code == 200, resp.text
|
||||
assert captured["agent_id"] == agent_id
|
||||
assert captured["department_id"] == 1
|
||||
assert captured["created_by"] == "1"
|
||||
@ -64,6 +64,7 @@
|
||||
- 修复前端工具图标与渲染匹配不准确的问题:工具管理列表与工具调用结果统一改为基于工具 `id` 的精确映射,避免模糊匹配导致的误渲染,未命中的工具不再显示默认扳手图标
|
||||
- 修复 GitHub Pages 文档部署工作流失败:移除 `actions/setup-node@v4` 对不存在 `docs/package-lock.json` 的缓存依赖,并将 `docs` 目录安装命令从 `npm ci` 调整为 `npm install`,避免因未提交锁文件导致 CI 在依赖缓存和安装阶段直接失败
|
||||
- 修正沙盒 provisioner backend 命名与配置说明:统一对外使用 `docker` / `kubernetes`,保留 `local` 作为兼容别名;同步清理 compose 中未生效的 provisioner 环境变量、补齐 K8s 相关变量注释,并更新沙盒架构文档中的默认模式与 backend 描述
|
||||
- 修复智能体配置列表接口在“无配置自动创建默认配置”路径下的参数缺失:补齐 `get_or_create_default` 的 `agent_id` 入参,避免 `/api/chat/agent/{agent_id}/configs` 返回 500
|
||||
|
||||
<!-- 添加到这里 -->
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user