Files
aiagent/backend/scripts/e2e_platform_capability_smoke_testclient.py
renjianbo 41ffd31923 feat: P0 commercial readiness — password security, legal, account management
Backend changes for Phase A of v1.0 commercial launch:

P0-3: Password Security
- Remove hardcoded admin/123456 defaults from 34+ bootstrap scripts
- Add PLATFORM_USERNAME/PLATFORM_PASSWORD env vars to config
- Add PUT /api/v1/auth/change-password endpoint (requires old password)

P0-1: User Agreement & Privacy Policy
- Add agreed_terms/agreed_terms_version/agreed_terms_at to User model
- New GET /api/v1/legal/privacy and GET /api/v1/legal/terms endpoints
- New POST /api/v1/legal/agree endpoint to record consent
- Register endpoint now validates agreed_terms must be True

P0-6: Account Management
- Add phone/status/is_email_verified to User model
- Add DELETE /api/v1/auth/account for account deletion (with password confirmation)
- Add PUT /api/v1/auth/phone for phone binding
- Reject authentication for deleted accounts (status=deleted)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-01 22:01:54 +08:00

93 lines
3.2 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.
#!/usr/bin/env python3
"""
与 e2e_platform_capability_smoke.py 相同业务验证,但走 FastAPI TestClient不经过 TCP 8037
适用:本机存在多个进程占用 8037、HTTP 命中旧实例导致 /platform 路由 404 时。
用法:
cd backend && .\\venv\\Scripts\\python.exe scripts/e2e_platform_capability_smoke_testclient.py
"""
from __future__ import annotations
import os
import sys
import time
from fastapi.testclient import TestClient
# 确保加载 backend 目录
def main() -> int:
os.environ.setdefault("PLATFORM_BASE_URL", "http://testserver")
from app.main import app
c = TestClient(app)
r = c.post(
"/api/v1/auth/login",
data={"username": os.getenv("PLATFORM_USERNAME"), "password": os.getenv("PLATFORM_PASSWORD")},
headers={"Content-Type": "application/x-www-form-urlencoded"},
)
if r.status_code != 200:
print("login:", r.status_code, r.text[:500], file=sys.stderr)
return 1
token = r.json().get("access_token")
h = {"Authorization": f"Bearer {token}"}
g = c.get("/api/v1/platform/scene-templates", headers=h)
if g.status_code != 200:
print("scene-templates:", g.status_code, g.text[:500], file=sys.stderr)
return 2
templates = g.json() or []
tid = "template_customer_service"
ids = [x.get("id") for x in templates if isinstance(x, dict)]
if tid not in ids:
tid = ids[0] if ids else None
if not tid:
print("无模板", file=sys.stderr)
return 3
name = os.getenv("SMOKE_AGENT_NAME") or f"冒烟_客服DSL_TC_{int(time.time())}"
cr = c.post(
"/api/v1/platform/agents/from-template",
headers=h,
json={
"template_id": tid,
"name": name,
"description": "e2e testclient",
"parameters": {"temperature": 0.35},
"budget_config": {"max_steps": 50, "max_llm_invocations": 5, "max_tool_calls": 20},
},
)
if cr.status_code not in (200, 201):
print("from-template:", cr.status_code, cr.text[:800], file=sys.stderr)
return 4
aid = cr.json().get("id")
print("agent:", aid, cr.json().get("name"))
body = {
"agent_id": aid,
"input_data": {
"query": os.getenv("SMOKE_USER_QUERY") or "你好,请用一句话说明你能帮我做什么。",
"scenario_dsl": {
"version": "1",
"scene": "customer_service_smoke_tc",
"goal": "验证 TestClient 执行",
"constraints": ["简短"],
"deliverables": ["一句回复"],
"acceptance": ["有内容"],
"payload": {"channel": "smoke_tc"},
},
},
}
er = c.post("/api/v1/executions", headers=h, json=body)
if er.status_code not in (200, 201):
print("executions:", er.status_code, er.text[:800], file=sys.stderr)
return 5
eid = er.json()["id"]
print("execution:", eid, "(异步任务需 Celery此处仅校验创建成功)")
print("OK — TestClient 路径:模板 + DSL 创建执行记录成功。请用 Celery 跑完后查 GET /api/v1/executions/{id}")
return 0
if __name__ == "__main__":
raise SystemExit(main())