Files
aiagent/backend/scripts/e2e_router_invoke_demo.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

112 lines
3.4 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: 演示 Agent「演示-主链路委派invoke」执行成功并校验父子执行链。
前置:
- 已运行 create_router_invoke_demo_agent.py
- 平台 API 可访问
用法:
cd backend && .\\venv\\Scripts\\python.exe scripts/e2e_router_invoke_demo.py
"""
from __future__ import annotations
import os
import sys
import time
from typing import Any, Dict, Optional
import requests
BASE = os.getenv("PLATFORM_BASE_URL", "http://127.0.0.1:8037").rstrip("/")
USER = os.getenv("PLATFORM_USERNAME")
PWD = os.getenv("PLATFORM_PASSWORD")
DEMO_AGENT_NAME = os.getenv("DEMO_AGENT_NAME", "演示-主链路委派invoke")
def _login_headers() -> Dict[str, str]:
r = requests.post(
f"{BASE}/api/v1/auth/login",
data={"username": USER, "password": PWD},
headers={"Content-Type": "application/x-www-form-urlencoded"},
timeout=15,
)
r.raise_for_status()
token = r.json().get("access_token")
if not token:
raise RuntimeError("无 access_token")
return {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
def _find_demo_id(h: Dict[str, str]) -> Optional[str]:
r = requests.get(
f"{BASE}/api/v1/agents", params={"search": DEMO_AGENT_NAME, "limit": 50}, headers=h, timeout=30
)
r.raise_for_status()
for a in r.json() or []:
if a.get("name") == DEMO_AGENT_NAME:
return a.get("id")
return None
def _wait_done(h: Dict[str, str], eid: str, timeout_s: float = 180.0) -> Dict[str, Any]:
t0 = time.time()
while time.time() - t0 < timeout_s:
r = requests.get(f"{BASE}/api/v1/executions/{eid}", headers=h, timeout=30)
r.raise_for_status()
d = r.json()
st = d.get("status")
if st in ("completed", "failed"):
return d
time.sleep(1.2)
raise TimeoutError(eid)
def main() -> int:
h = _login_headers()
aid = _find_demo_id(h)
if not aid:
print(f"未找到 Agent: {DEMO_AGENT_NAME},请先运行 create_router_invoke_demo_agent.py", file=sys.stderr)
return 1
body = {
"agent_id": aid,
"input_data": {"query": "E2E 委派演示:请简短回复收到。", "user_id": "e2e_router_user"},
}
cr = requests.post(f"{BASE}/api/v1/executions", headers=h, json=body, timeout=30)
if cr.status_code >= 400:
print(cr.status_code, cr.text[:1200], file=sys.stderr)
return 2
eid = cr.json()["id"]
print(f"execution={eid}")
done = _wait_done(h, eid)
if done.get("status") != "completed":
print("failed:", done.get("error_message"), file=sys.stderr)
return 3
sm = requests.get(
f"{BASE}/api/v1/execution-logs/executions/{eid}/chain/summary", headers=h, timeout=30
)
if sm.status_code == 200:
s = sm.json()
print(
"chain_summary:",
s.get("total_executions"),
s.get("status_count"),
s.get("total_execution_time_ms"),
)
if (s.get("total_executions") or 0) < 2:
print("警告: 期望至少 2 条执行记录(父+子),请确认 API 已重启到最新代码", file=sys.stderr)
elif sm.status_code == 404:
print("chain/summary 404当前 API 进程可能未加载最新路由,跳过汇总校验")
else:
print("chain/summary", sm.status_code, sm.text[:300])
print("E2E 通过")
return 0
if __name__ == "__main__":
raise SystemExit(main())