chore(prep): shared groundwork for batch-3 (admin/golden/cache)

第三批(T12 后台/T13 黄金集/T14 检索缓存)协调提交:
- kb:KbAssetService(登记/审核,tryon_ready 只能随 approved 打开)+ Asset 模型与 repo
- retrieval:list_gaps 缺口看板查询 + invalidate_cache() 钩子(T14 背后实现真缓存)
- 配置:ADMIN_TOKEN(空=后台 404)+ 检索缓存三参数
- pytest golden marker(默认跳过,CI 强制跑)+ Makefile golden + CI 防线 5c
- 测试隔离修复:test_auth_sms 加 autouse 清 sms:* 键夹具(频控计数跨运行
  累积会毒化后续运行——随机 IP 空间仅 254 且部分用例固定 device_id)
This commit is contained in:
xsl
2026-08-14 20:57:52 +08:00
parent 8ec8d2cefb
commit 9c1802130d
11 changed files with 236 additions and 5 deletions
+20
View File
@@ -56,6 +56,26 @@ def _rand_ip() -> str:
return f"198.51.100.{uuid.uuid4().int % 254 + 1}"
@pytest.fixture(autouse=True)
async def _clean_sms_counters() -> AsyncIterator[None]:
"""每用例前清空 sms:* 计数键。
频控计数落在常驻 Redis 里,会跨 pytest 运行累积(随机 IP 只从
198.51.100.0/24 取值、部分用例固定 device_id),历史运行的计数会把
本运行的合法发送挤过阈值。测试隔离靠自己清键,不依赖随机性。
"""
if not _infra_available():
yield
return
from packages.shared.redis_client import get_redis
redis = await get_redis()
keys = [k async for k in redis.scan_iter(match="sms:*")]
if keys:
await redis.delete(*keys)
yield
@pytest.fixture
async def env() -> AsyncIterator[tuple[Any, CapturingSender]]:
from apps.api.main import create_app