Files
Aether/tests/unit/test_api_format_metadata.py
fawney19 7c580e843f fix: 治理 Prometheus 指标基数爆炸和内存缓存无界增长
- 移除 token/latency Prometheus 指标的 model 标签,避免 provider x model 笛卡尔积
- HealthMonitor 滑动窗口从 DB JSON 迁移至进程内存,减少写放大
- ModelCostService 三层缓存增加 500 条上限,超限时清空
- StickyPriority 粘性缓存和健康状态字典增加容量淘汰
- AffinityManager 请求锁字典增加 500 条上限,淘汰空闲锁
- 配额刷新/探测查询使用 defer/load_only 避免加载大 JSON 列
- Alembic 迁移清理 DB 中遗留的 request_results_window 数据
- 同步更新测试适配 batch_get_cooldowns 返回值和批量删除异步化
2026-03-10 10:40:50 +08:00

63 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pytest
import src.core.api_format.metadata as metadata
from src.core.api_format.enums import ApiFamily, EndpointKind
from src.core.api_format.metadata import EndpointDefinition, get_default_body_rules_for_endpoint
def test_get_default_body_rules_for_endpoint_returns_empty_for_invalid() -> None:
assert get_default_body_rules_for_endpoint("not-a-valid-signature") == []
def test_get_default_body_rules_for_endpoint_returns_empty_for_no_rules() -> None:
"""claude:chat 没有配置 default_body_rules应返回空列表。"""
assert get_default_body_rules_for_endpoint("claude:chat") == []
def test_get_default_body_rules_for_endpoint_returns_codex_cli_rules_only() -> None:
"""只有 codex + openai:cli 返回默认请求体规则。"""
cli_rules = get_default_body_rules_for_endpoint("openai:cli", provider_type="codex")
assert len(cli_rules) == 5
actions = [r["action"] for r in cli_rules]
assert actions == ["drop", "drop", "drop", "set", "set"]
assert cli_rules[0]["path"] == "max_output_tokens"
assert cli_rules[1]["path"] == "temperature"
assert cli_rules[2]["path"] == "top_p"
assert cli_rules[3] == {"action": "set", "path": "store", "value": False}
assert cli_rules[4]["path"] == "instructions"
assert cli_rules[4]["condition"]["op"] == "not_exists"
# openai:compact also has the same default body rules (defined in EndpointDefinition)
compact_rules = get_default_body_rules_for_endpoint("openai:compact", provider_type="codex")
assert len(compact_rules) == 5
def test_get_default_body_rules_for_endpoint_returns_deep_copy(
monkeypatch: pytest.MonkeyPatch,
) -> None:
definition = EndpointDefinition(
api_family=ApiFamily.OPENAI,
endpoint_kind=EndpointKind.CLI,
default_body_rules=(
{
"action": "set",
"path": "metadata",
"value": {"source": "default"},
},
),
)
monkeypatch.setattr(metadata, "resolve_endpoint_definition", lambda _value: definition)
rules = get_default_body_rules_for_endpoint("openai:cli")
assert rules == [
{
"action": "set",
"path": "metadata",
"value": {"source": "default"},
}
]
rules[0]["value"]["source"] = "changed"
assert definition.default_body_rules[0]["value"]["source"] == "default"