sync update from LAN repo (source dhk-1 @ 3b1ec5b4)

This commit is contained in:
gozeros committed 2026-11-05 10:56:34 +08:00
1 parent da6521b6cb
commit 264e2200d6
995 files changed
+148105 -13399

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:
@@ -74,6 +96,64 @@ def test_seed_includes_independent_3q_slots() -> None:
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