mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
- evaluate_condition 支持递归 all/any 组合节点和 source 字段 - header_rules 支持 condition 条件触发,HeaderBuilder.apply_rules 透传 body/original_body - 提取 EndpointConditionEditor 组件统一请求头/请求体规则的条件编辑 UI - header_rules 新增服务端结构校验(action/key/from/to/condition) - 新增组合条件、source 切换、fail-closed 等测试用例
95 lines
2.8 KiB
Python
95 lines
2.8 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from src.models.endpoint_models import ProviderEndpointCreate, ProviderEndpointUpdate
|
|
|
|
|
|
def test_provider_endpoint_models_accept_nested_conditions_and_source() -> None:
|
|
payload = {
|
|
"provider_id": "provider-1",
|
|
"api_format": "openai:chat",
|
|
"base_url": "https://api.example.com",
|
|
"header_rules": [
|
|
{
|
|
"action": "set",
|
|
"key": "X-Test",
|
|
"value": "1",
|
|
"condition": {
|
|
"all": [
|
|
{"path": "mode", "op": "eq", "value": "prod", "source": "original"},
|
|
{
|
|
"any": [
|
|
{"path": "tier", "op": "eq", "value": "gold"},
|
|
{"path": "tier", "op": "eq", "value": "silver"},
|
|
]
|
|
},
|
|
]
|
|
},
|
|
}
|
|
],
|
|
"body_rules": [
|
|
{
|
|
"action": "set",
|
|
"path": "metadata.enabled",
|
|
"value": True,
|
|
"condition": {
|
|
"all": [
|
|
{"path": "metadata.kind", "op": "eq", "value": "chat"},
|
|
{"path": "metadata.tags", "op": "contains", "value": "vip"},
|
|
]
|
|
},
|
|
}
|
|
],
|
|
}
|
|
|
|
created = ProviderEndpointCreate(**payload)
|
|
updated = ProviderEndpointUpdate(
|
|
header_rules=payload["header_rules"],
|
|
body_rules=payload["body_rules"],
|
|
)
|
|
|
|
assert created.header_rules == payload["header_rules"]
|
|
assert created.body_rules == payload["body_rules"]
|
|
assert updated.header_rules == payload["header_rules"]
|
|
assert updated.body_rules == payload["body_rules"]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("field_name", "rules"),
|
|
[
|
|
(
|
|
"header_rules",
|
|
[
|
|
{
|
|
"action": "set",
|
|
"key": "X-Test",
|
|
"value": "1",
|
|
"condition": {"path": "mode", "op": "eq", "value": "prod", "source": "bad"},
|
|
}
|
|
],
|
|
),
|
|
(
|
|
"body_rules",
|
|
[
|
|
{
|
|
"action": "set",
|
|
"path": "metadata.enabled",
|
|
"value": True,
|
|
"condition": {"all": []},
|
|
}
|
|
],
|
|
),
|
|
],
|
|
)
|
|
def test_provider_endpoint_models_reject_invalid_condition_shapes(
|
|
field_name: str,
|
|
rules: list[dict],
|
|
) -> None:
|
|
with pytest.raises(ValidationError):
|
|
ProviderEndpointCreate(
|
|
provider_id="provider-1",
|
|
api_format="openai:chat",
|
|
base_url="https://api.example.com",
|
|
**{field_name: rules},
|
|
)
|