52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
"""真账号验证:空车场景下 cart_status / clear_cart 不再被误判为获取失败
|
|
|
|
修复前行为(2026-08-16 探针实测):空车时 cart count API 返回 status=101,
|
|
_query_cart_count 一律当失败抛 CartOperationError → cart_status 报错 5002、
|
|
clear_cart 末尾校验拿 cart_count=-1(runner 据此误判「开单前清理未清空」)。
|
|
修复后:status=101 识别为合法空车,count=0。
|
|
|
|
用法:
|
|
.venv/Scripts/python.exe scripts/verify_cart_empty.py
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
from app.shared.config import get_settings # noqa: E402
|
|
from app.trading.services.auth_session import AuthSession # noqa: E402
|
|
from app.trading.worker.site_interact import SiteInteractor # noqa: E402
|
|
|
|
|
|
async def run() -> int:
|
|
settings = get_settings()
|
|
auth = AuthSession(settings)
|
|
await auth.start()
|
|
site = SiteInteractor(auth_session=auth, settings=settings)
|
|
await site.start()
|
|
try:
|
|
status = await site.cart_status()
|
|
print(f"cart_status -> {status}")
|
|
assert status["logged_in"] is True
|
|
assert status["count"] == 0, f"预期空车 count=0,实际 {status['count']}"
|
|
assert status["raw_status"] == "101", f"预期 raw_status=101,实际 {status['raw_status']}"
|
|
|
|
cleared = await site.clear_cart()
|
|
print(f"clear_cart -> {cleared}")
|
|
assert cleared["cart_count"] == 0, (
|
|
f"空车 clear 后 cart_count 应为 0(修复前是 -1),实际 {cleared['cart_count']}"
|
|
)
|
|
|
|
print("\n验证通过:空车按正常结果返回(count=0 / raw_status=101),未误判为获取失败")
|
|
return 0
|
|
finally:
|
|
await site.close()
|
|
await auth.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(asyncio.run(run()))
|