fix(providers): 允许 max_probe_interval_minutes 设为 0 并修复零值被覆盖的问题

- 将 max_probe_interval_minutes 校验范围从 2-32 改为 0-32
- 修复 routes.py 中 max_probe_interval_minutes 和 cache_ttl_minutes
  使用 `or` 短路导致零值被默认值覆盖的问题,改用 is not None 判断
- 前端表单同步调整最小值约束和提示文案
- 新增零值校验的单元测试
This commit is contained in:
fawney19
2026-03-07 18:43:28 +08:00
parent 06b483f79d
commit 9cdcce1b5f
5 changed files with 35 additions and 12 deletions

View File

@@ -232,14 +232,14 @@
id="max_probe_interval_minutes"
:model-value="form.max_probe_interval_minutes ?? ''"
type="number"
min="2"
min="0"
max="32"
placeholder="32"
class="h-8"
@update:model-value="(v) => form.max_probe_interval_minutes = parseNumberInput(v, { min: 2, max: 32 }) ?? 32"
@update:model-value="(v) => form.max_probe_interval_minutes = parseNumberInput(v, { min: 0, max: 32 }) ?? 32"
/>
<p class="text-xs text-muted-foreground mt-0.5">
分钟,2-32
分钟,0-32
</p>
</div>
</div>

View File

@@ -100,14 +100,14 @@
id="max_probe_interval_minutes"
:model-value="form.max_probe_interval_minutes ?? ''"
type="number"
min="2"
min="0"
max="32"
placeholder="32"
class="h-8"
@update:model-value="(v) => form.max_probe_interval_minutes = parseNumberInput(v, { min: 2, max: 32 }) ?? 32"
@update:model-value="(v) => form.max_probe_interval_minutes = parseNumberInput(v, { min: 0, max: 32 }) ?? 32"
/>
<p class="text-xs text-muted-foreground mt-0.5">
2-32分钟
0-32分钟
</p>
</div>
</div>

View File

@@ -846,9 +846,13 @@ class AdminListPoolKeysAdapter(AdminApiAdapter):
rate_multipliers=rate_multipliers,
internal_priority=int(getattr(k, "internal_priority", 50) or 50),
rpm_limit=getattr(k, "rpm_limit", None),
cache_ttl_minutes=int(getattr(k, "cache_ttl_minutes", 5) or 5),
max_probe_interval_minutes=int(
getattr(k, "max_probe_interval_minutes", 32) or 32
cache_ttl_minutes=(
v if (v := getattr(k, "cache_ttl_minutes", None)) is not None else 5
),
max_probe_interval_minutes=(
v
if (v := getattr(k, "max_probe_interval_minutes", None)) is not None
else 32
),
note=getattr(k, "note", None),
allowed_models=allowed_models,

View File

@@ -475,7 +475,7 @@ class EndpointAPIKeyCreate(BaseModel):
default=5, ge=0, le=60, description="缓存 TTL分钟0=禁用默认5分钟"
)
max_probe_interval_minutes: int = Field(
default=32, ge=2, le=32, description="熔断探测间隔(分钟),范围 2-32"
default=32, ge=0, le=32, description="熔断探测间隔(分钟),范围 0-32"
)
# 备注
@@ -631,7 +631,7 @@ class EndpointAPIKeyUpdate(BaseModel):
default=None, ge=0, le=60, description="缓存 TTL分钟0=禁用"
)
max_probe_interval_minutes: int | None = Field(
default=None, ge=2, le=32, description="熔断探测间隔(分钟),范围 2-32"
default=None, ge=0, le=32, description="熔断探测间隔(分钟),范围 0-32"
)
is_active: bool | None = Field(default=None, description="是否启用")
note: str | None = Field(default=None, max_length=500, description="备注说明")

View File

@@ -9,7 +9,7 @@ from typing import Any, cast
import pytest
from src.core.exceptions import InvalidRequestException
from src.models.endpoint_models import EndpointAPIKeyUpdate
from src.models.endpoint_models import EndpointAPIKeyCreate, EndpointAPIKeyUpdate
async def _noop_invalidate_models_list_cache() -> None:
@@ -72,6 +72,25 @@ def _build_key(**overrides: Any) -> SimpleNamespace:
return SimpleNamespace(**base)
def test_key_create_accepts_zero_max_probe_interval_minutes() -> None:
payload = EndpointAPIKeyCreate.model_validate(
{
"name": "key-1",
"api_key": "secret",
"api_formats": ["openai:chat"],
"max_probe_interval_minutes": 0,
}
)
assert payload.max_probe_interval_minutes == 0
def test_key_update_accepts_zero_max_probe_interval_minutes() -> None:
payload = EndpointAPIKeyUpdate.model_validate({"max_probe_interval_minutes": 0})
assert payload.max_probe_interval_minutes == 0
def test_prepare_update_payload_auth_type_null_ignored() -> None:
key = _build_key(auth_type="api_key")
key_data = EndpointAPIKeyUpdate.model_validate({"auth_type": None})