mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 18:04:20 +08:00
对 v1.21→v1.32.5 的 249 文件 4.2 万行改动做六路专项审查,本轮落地全部发现: 回测正确性:组合收益 fillna(0) 虚增、轮动停牌日过期价成交、单标的 WF 逐窗指标 被预热区稀释(三件套均带先红后绿回归);worst_drawdown 方向、grading 容错、 组合体检品种费率、寻优端点费率透传。 安全:LLM api_url 仅 http/https 且禁 userinfo(封死 file:// 读取与 Key 外送链)、 错误响应不回显原始 body、响应体 2MB 上限、配置原子写、坏配置字段级防御。 数据:涨跌停价整数分币舍入(67/318/90 个价位错 1 分漏判清零)、交易时段/采样/ provisional 统一沪时区、warehouse 增量缺口自动全量重拉、provisional 定点转正、 baostock 真故障抛错 + W/M 去 tradestatus(实测服务端报错,周月兜底此前从未工作) + 指数 vol 股→手(实测锚定)、ccpm 结构变更抛错。 Web API:缓存键补 count/vipdoc、NaN 清洗先于缓存、count>800 分页取全量、 submit 透传真实状态、pending 不再被淘汰成幽灵、watchlist/server 入参约束。 公式:FILTER 去副作用、0-1 值域误判收严、递归深度上限、REF 负移位显式禁止。 前端:4 处请求竞态序号守卫、Sparkline viewBox、北交所 market=2 映射、 空数据缓存死角、AI 弹窗卸载中止轮询、量能/资金日历口径修正。 CLI/CI:warehouse sync 失败 exit 1、参数校验干净报错、release 真实发布 SHA256、 CI 超时与缓存、spec 补 baostock 前提。 约 60 条回归测试先红后绿;pytest 1820 全过,ruff/mypy/vue-tsc/node --test 全绿。
86 lines
3.2 KiB
Python
86 lines
3.2 KiB
Python
"""vipdoc 路径设置(app_settings_store + /settings/vipdoc 端点)单测。
|
|
|
|
覆盖:KV 存取/删除、端点保存校验(不存在路径 400)、保存后清空涨停缓存、
|
|
_effective_vipdoc 优先级(显式参数 > 已存设置 > 自动检测)。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def settings_env(tmp_path, monkeypatch):
|
|
"""独立配置目录 + 全新单例。"""
|
|
from easy_tdx.web import app_settings_store as asm
|
|
|
|
monkeypatch.setenv("EASY_TDX_CONFIG_DIR", str(tmp_path / "cfg"))
|
|
asm._store = None
|
|
yield asm
|
|
asm._store = None
|
|
|
|
|
|
def test_settings_kv_roundtrip(settings_env):
|
|
store = settings_env.get_app_settings_store()
|
|
assert store.get("vipdoc") is None # 缺省 None
|
|
store.set("vipdoc", r"D:\new_tdx\vipdoc")
|
|
assert store.get("vipdoc") == r"D:\new_tdx\vipdoc"
|
|
store.set("vipdoc", r"E:\tdx\vipdoc") # 覆盖
|
|
assert store.get("vipdoc") == r"E:\tdx\vipdoc"
|
|
store.delete("vipdoc")
|
|
assert store.get("vipdoc") is None
|
|
|
|
|
|
def test_vipdoc_settings_endpoints(settings_env, tmp_path):
|
|
"""GET/PUT 往返;PUT 校验目录存在;保存即清空涨停扫描缓存。"""
|
|
pytest.importorskip("fastapi")
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
from easy_tdx.web.errors import register_exception_handlers
|
|
from easy_tdx.web.routers import market as market_mod
|
|
|
|
real_dir = tmp_path / "vipdoc_real"
|
|
(real_dir / "sh" / "lday").mkdir(parents=True)
|
|
|
|
app = FastAPI()
|
|
register_exception_handlers(app)
|
|
app.include_router(market_mod.router, prefix="/api/v1")
|
|
app.state.tdx_client = object()
|
|
|
|
with TestClient(app) as client:
|
|
# 初始:无已存设置
|
|
r = client.get("/api/v1/settings/vipdoc")
|
|
assert r.status_code == 200
|
|
assert r.json()["stored"] is None
|
|
|
|
# 不存在的路径 → 400
|
|
bad = client.put("/api/v1/settings/vipdoc", json={"path": str(tmp_path / "nope")})
|
|
assert bad.status_code == 400
|
|
|
|
# 保存有效目录 → 生效 + 涨停缓存清空
|
|
r = client.put("/api/v1/settings/vipdoc", json={"path": str(real_dir)})
|
|
assert r.status_code == 200
|
|
assert r.json()["stored"] == str(real_dir)
|
|
assert market_mod._limitup_cache == {}
|
|
|
|
# GET 回读
|
|
assert client.get("/api/v1/settings/vipdoc").json()["stored"] == str(real_dir)
|
|
|
|
# 清除(空串)→ 恢复自动检测
|
|
r = client.put("/api/v1/settings/vipdoc", json={"path": ""})
|
|
assert r.status_code == 200
|
|
assert client.get("/api/v1/settings/vipdoc").json()["stored"] is None
|
|
|
|
|
|
def test_effective_vipdoc_priority(settings_env, tmp_path, monkeypatch):
|
|
"""显式参数 > 已存设置 > 自动检测(None)。"""
|
|
from easy_tdx.web.app_settings_store import get_app_settings_store
|
|
from easy_tdx.web.routers.market import _effective_vipdoc
|
|
|
|
get_app_settings_store().set("vipdoc", str(tmp_path))
|
|
assert _effective_vipdoc(str(tmp_path / "other")) == str(tmp_path / "other") # 显式优先
|
|
assert _effective_vipdoc(None) == str(tmp_path) # 已存设置
|
|
get_app_settings_store().delete("vipdoc")
|
|
assert _effective_vipdoc(None) is None # 落回自动检测
|