Files
Neo-ZQYY/scripts/ops/api_health_check.py
Neo b25308c3f4 feat: P1-P3 全栈集成 — 数据库基础 + DWS 扩展 + 小程序鉴权 + 工程化体系
## P1 数据库基础
- zqyy_app: 创建 auth/biz schema、FDW 连接 etl_feiqiu
- etl_feiqiu: 创建 app schema RLS 视图、商品库存预警表
- 清理 assistant_abolish 残留数据

## P2 ETL/DWS 扩展
- 新增 DWS 助教订单贡献度表 (dws.assistant_order_contribution)
- 新增 assistant_order_contribution_task 任务及 RLS 视图
- member_consumption 增加充值字段、assistant_daily 增加处罚字段
- 更新 ODS/DWD/DWS 任务文档及业务规则文档
- 更新 consistency_checker、flow_runner、task_registry 等核心模块

## P3 小程序鉴权系统
- 新增 xcx_auth 路由/schema(微信登录 + JWT)
- 新增 wechat/role/matching/application 服务层
- zqyy_app 鉴权表迁移 + 角色权限种子数据
- auth/dependencies.py 支持小程序 JWT 鉴权

## 文档与审计
- 新增 DOCUMENTATION-MAP 文档导航
- 新增 7 份 BD_Manual 数据库变更文档
- 更新 DDL 基线快照(etl_feiqiu 6 schema + zqyy_app auth)
- 新增全栈集成审计记录、部署检查清单更新
- 新增 BACKLOG 路线图、FDW→Core 迁移计划

## Kiro 工程化
- 新增 5 个 Spec(P1/P2/P3/全栈集成/核心业务)
- 新增审计自动化脚本(agent_on_stop/build_audit_context/compliance_prescan)
- 新增 6 个 Hook(合规检查/会话日志/提交审计等)
- 新增 doc-map steering 文件

## 运维与测试
- 新增 ops 脚本:迁移验证/API 健康检查/ETL 监控/集成报告
- 新增属性测试:test_dws_contribution / test_auth_system
- 清理过期 export 报告文件
- 更新 .gitignore 排除规则
2026-02-26 08:03:53 +08:00

120 lines
4.2 KiB
Python
Raw Permalink 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.
# -*- coding: utf-8 -*-
"""API 健康检查脚本
任务 1.3:登录获取 JWT → 验证任务注册表 → 执行 sync-check
"""
import json
import sys
import requests
BASE_URL = "http://localhost:8000"
ADMIN_USER = "admin"
ADMIN_PASS = "admin123"
def main() -> int:
ok = True
# ── 1. 登录获取 JWT ──────────────────────────────────────
print("=" * 60)
print("[1/3] POST /api/auth/login — 登录获取 JWT")
print("=" * 60)
try:
resp = requests.post(
f"{BASE_URL}/api/auth/login",
json={"username": ADMIN_USER, "password": ADMIN_PASS},
timeout=10,
)
except requests.ConnectionError:
print("✗ 无法连接后端服务,请确认 uvicorn 已在 :8000 启动")
return 1
if resp.status_code != 200:
print(f"✗ 登录失败: HTTP {resp.status_code}")
print(f" 响应: {resp.text[:500]}")
return 1
tokens = resp.json()
jwt = tokens["access_token"]
print(f"✓ 登录成功,获取 JWT前 40 字符): {jwt[:40]}...")
print(f" token_type: {tokens['token_type']}")
print()
headers = {"Authorization": f"Bearer {jwt}"}
# ── 2. 获取任务注册表 ────────────────────────────────────
print("=" * 60)
print("[2/3] GET /api/tasks/registry — 验证任务注册表")
print("=" * 60)
resp = requests.get(f"{BASE_URL}/api/tasks/registry", headers=headers, timeout=10)
if resp.status_code != 200:
print(f"✗ 获取注册表失败: HTTP {resp.status_code}")
print(f" 响应: {resp.text[:500]}")
ok = False
else:
data = resp.json()
groups = data.get("groups", {})
total_tasks = sum(len(tasks) for tasks in groups.values())
common_tasks = sum(
1 for tasks in groups.values() for t in tasks if t.get("is_common")
)
if total_tasks == 0:
print("✗ 任务注册表为空!")
ok = False
else:
print(f"✓ 任务注册表非空")
print(f" 业务域数量: {len(groups)}")
print(f" 总任务数: {total_tasks}")
print(f" 常用任务数: {common_tasks}")
print(f" 业务域列表: {', '.join(sorted(groups.keys()))}")
# 按域打印任务数
for domain in sorted(groups.keys()):
tasks = groups[domain]
n_common = sum(1 for t in tasks if t.get("is_common"))
print(f" {domain}: {len(tasks)} 个任务({n_common} 个常用)")
print()
# ── 3. Sync-Check ────────────────────────────────────────
print("=" * 60)
print("[3/3] GET /api/tasks/sync-check — 后端与 ETL 注册表同步检查")
print("=" * 60)
resp = requests.get(f"{BASE_URL}/api/tasks/sync-check", headers=headers, timeout=30)
if resp.status_code != 200:
print(f"✗ sync-check 请求失败: HTTP {resp.status_code}")
print(f" 响应: {resp.text[:500]}")
ok = False
else:
sc = resp.json()
if sc.get("error"):
print(f"⚠ sync-check 返回错误: {sc['error']}")
ok = False
elif sc.get("in_sync"):
print("✓ 后端注册表与 ETL 真实注册表完全同步 (in_sync=true)")
else:
print("✗ 后端注册表与 ETL 真实注册表不同步 (in_sync=false)")
if sc.get("backend_only"):
print(f" 仅后端有ETL 缺失): {sc['backend_only']}")
if sc.get("etl_only"):
print(f" 仅 ETL 有(后端缺失): {sc['etl_only']}")
ok = False
print()
# ── 汇总 ─────────────────────────────────────────────────
print("=" * 60)
if ok:
print("✓ API 健康检查全部通过")
else:
print("✗ API 健康检查存在问题,请查看上方详情")
print("=" * 60)
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())