sync update from LAN repo (source master @ ca48c4ec)

This commit is contained in:
gozeros committed 2026-11-05 10:53:54 +08:00
1 parent 8bc8b0e082
commit ea9dcff9c0
873 files changed
+107866 -14011

No files matched your search

@@ -14,6 +14,7 @@ from deerflow.persistence.business_mapping.sql import DEFAULT_BUSINESS_ROWS
class _MappingStore:
def __init__(self) -> None:
self.calls: list[tuple[str, dict[str, object]]] = []
self.create_calls: list[dict[str, str]] = []
async def update_mapping(self, business_code: str, **fields: object) -> dict[str, object]:
self.calls.append((business_code, fields))
@@ -27,6 +28,27 @@ class _MappingStore:
"sort_order": 3,
}
async def create_custom_mapping(
self,
*,
business_code: str,
mapping_type: str,
) -> dict[str, object] | None:
self.create_calls.append(
{"business_code": business_code, "mapping_type": mapping_type}
)
return {
"business_code": business_code,
"label": business_code,
"mapping_type": mapping_type,
"is_custom": True,
"agent_id": None,
"agent_name": None,
"chain_id": None,
"chain_title": None,
"sort_order": 99,
}
class _ChainStore:
def __init__(self, chain: dict[str, object] | None) -> None:
@@ -68,11 +90,70 @@ def _request(
def test_seed_includes_independent_3q_slots() -> None:
codes = [row["business_code"] for row in DEFAULT_BUSINESS_ROWS]
assert codes[:5] == ["3Q", "6BF", "7BF", "8BF", "AFX"]
assert codes[5:12] == ["3q-0", "3q-1", "3q-2", "3q-3", "3q-4", "3q-5", "3q-6"]
assert codes[:6] == ["3Q", "6BF", "7BF", "8BF", "AFX", "b5-1"]
assert codes[6:13] == ["3q-0", "3q-1", "3q-2", "3q-3", "3q-4", "3q-5", "3q-6"]
assert DEFAULT_BUSINESS_ROWS[codes.index("b5-1")]["label"] == "任务分析"
assert "6-1" in codes and "7-4" in codes
assert codes.index("3q-0") < codes.index("3q-1")
assert codes.index("3q-6") < codes.index("6-1")
custom_codes = {row["business_code"] for row in DEFAULT_BUSINESS_ROWS if row.get("is_custom")}
assert custom_codes == {"3q-1", "3q-2", "3q-3", "3q-4", "3q-5", "3q-6"}
for code in custom_codes:
seed = DEFAULT_BUSINESS_ROWS[codes.index(code)]
assert seed["mapping_type"] == "自定义类型"
assert DEFAULT_BUSINESS_ROWS[codes.index("3q-0")].get("is_custom") is not True
@pytest.mark.asyncio
async def test_admin_can_create_a_custom_mapping() -> None:
request = _request("admin")
response = await business_mapping_router.create_mapping(
request,
business_mapping_router.BusinessMappingCreateRequest(
name="区域研判",
),
)
assert response.business_code == "区域研判"
assert response.label == "区域研判"
assert response.mapping_type == "自定义类型"
assert response.is_custom is True
assert request.app.state.business_mapping_store.create_calls == [
{"business_code": "区域研判", "mapping_type": "自定义类型"}
]
@pytest.mark.asyncio
async def test_non_admin_cannot_create_a_custom_mapping() -> None:
request = _request("user")
with pytest.raises(HTTPException) as error:
await business_mapping_router.create_mapping(
request,
business_mapping_router.BusinessMappingCreateRequest(
name="区域研判",
),
)
assert error.value.status_code == 403
assert request.app.state.business_mapping_store.create_calls == []
@pytest.mark.asyncio
async def test_custom_mapping_name_cannot_consume_the_a_mode_suffix() -> None:
request = _request("admin")
with pytest.raises(HTTPException) as error:
await business_mapping_router.create_mapping(
request,
business_mapping_router.BusinessMappingCreateRequest(
name="区域研判-A",
),
)
assert error.value.status_code == 422
assert request.app.state.business_mapping_store.create_calls == []
@pytest.mark.asyncio