- 缘契域 domains/yuanqi:covenants(当前版)+ covenant_events(不可变历史);提议—问心—铭契—撤回全链;边界变更立即生效;多维关系并存,服务层拒绝 affinity/好感度单一键;浪漫维度成人资格标记位 - 道体铸魂与分灵 domains/jingsheng/soul.py:soul_forgings 确认流(锚点变更 pending→confirmed 应用并签发新魂籍版本,确认前人物锚点不变);分灵创建新人物(继承资料与谱系 lineage 链、不继承原身份,魂籍从 v1 起) - 河图域 domains/hetu:persistent_worlds 境界 + world_entities/world_relations 境界作用域重建 + 世谱挂接;境界正史视图(scope=persistent_world 归真集合);canonize 后置推进正史计数 - 三界分流:reality→息壤提取(不变);persistent_world→境界实录+正史推进;simulation→只记试演实录;factual_records 增 scope 列——境界/幻境实录与真界本相隔离 - 正影打通:引文 target_type=memory 时被引记忆 superseded → 返回 successor_memory_id 提示,不静默替换 - 前端:人物详情页缘契面板(提议维度选择/铭契/撤回/事件史)+ 世界页重建(境界目录/实体/正史概览)+ covenants/worlds api 库 - 退役:旧 personality/drive/evolution/world 模块、服务、端点、仓储、schema、前端五页与组件样式;迁移 007 退役九张旧表与 characters.current_personality_version_id - 验收(test_m6_domains 六用例):多维无单一好感度/铭契版本链/事件不可抹除/撤回立即生效/边界即时/铸魂确认流+魂籍版本/分灵谱系/境界正史不进真界(实录 scope 隔离+真界候选=0)/引文正影后继 - 四套件:后端 379、前端 199、BFF 4、神识 5 包全绿(2 个预存环境失败不变);迁移 007 净库+±1 干净
81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
"""API 集成测试。"""
|
|
|
|
from collections.abc import AsyncGenerator
|
|
|
|
import pytest
|
|
from httpx import ASGITransport, AsyncClient
|
|
|
|
from app.api.v1.deps import require_admin
|
|
from app.main import app
|
|
|
|
|
|
@pytest.fixture
|
|
async def client(
|
|
monkeypatch: pytest.MonkeyPatch, auth_headers: dict[str, str]
|
|
) -> AsyncGenerator[AsyncClient, None]:
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(
|
|
transport=transport,
|
|
base_url="http://test",
|
|
headers=auth_headers,
|
|
) as http_client:
|
|
yield http_client
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_health_and_defaults(client: AsyncClient) -> None:
|
|
health = await client.get("/api/v1/health")
|
|
assert health.status_code == 200
|
|
character = await client.get("/api/v1/characters/active")
|
|
assert character.status_code == 200
|
|
assert character.json()["id"].startswith("character_")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_mcp_server_crud(client: AsyncClient) -> None:
|
|
"""MCP 服务器注册 CRUD——覆盖 services/mcp 路径。"""
|
|
created = await client.post(
|
|
"/api/v1/tools/mcp-servers",
|
|
json={
|
|
"name": "测试 MCP",
|
|
"transport": "stdio",
|
|
"command": "echo",
|
|
"args_json": '["hello"]',
|
|
},
|
|
)
|
|
assert created.status_code == 201
|
|
mcp_id = created.json()["id"]
|
|
|
|
listed = await client.get("/api/v1/tools/mcp-servers")
|
|
assert listed.status_code == 200
|
|
assert any(item["id"] == mcp_id for item in listed.json())
|
|
|
|
# MCP 服务器没有 GET single 端点,跳过
|
|
|
|
# PATCH: UpdateMcpServerRequest 不含 name 字段,改 command 验证路径可通
|
|
updated = await client.patch(
|
|
f"/api/v1/tools/mcp-servers/{mcp_id}",
|
|
json={"command": "cat", "args_json": '["-n"]'},
|
|
)
|
|
assert updated.status_code == 200
|
|
assert updated.json()["command"] == "cat"
|
|
|
|
deleted = await client.delete(f"/api/v1/tools/mcp-servers/{mcp_id}")
|
|
assert deleted.status_code == 204
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_preferences_flow(client: AsyncClient) -> None:
|
|
"""偏好设置读写——覆盖 services/preferences 路径。"""
|
|
fetched = await client.get("/api/v1/settings/preferences")
|
|
assert fetched.status_code == 200
|
|
assert "temperature" in fetched.json()
|
|
|
|
updated = await client.patch(
|
|
"/api/v1/settings/preferences",
|
|
json={"temperature": 0.7, "max_output_tokens": 4096},
|
|
)
|
|
assert updated.status_code == 200
|
|
assert updated.json()["temperature"] == 0.7
|
|
assert updated.json()["max_output_tokens"] == 4096
|