Simon
|
a9b97deacd
|
fix(tests): wordfilter API 适配 + SQLite ARRAY/JSONB 补丁 + 事务隔离
3 处 pre-existing 失败修复,测试通过率 +19:
1. content_moderation_service.py wordfilter API 适配
- wordfilter.init() / wordfilter.add() / wordfilter.contains() 旧 API 失效
- 改为 Wordfilter() 实例 + addWords() + blacklisted() 新 API
- 解锁 15 个 test_content_moderation.py 测试
- 备注: 此文件之前未 git add,本次一起纳入版本控制
2. conftest.py SQLite ARRAY/JSONB 编译补丁
- ORM 用 PostgreSQL ARRAY(quiz.keywords)和 JSONB(themes.palette, feedbacks.images)
- SQLite 不能直接编译 DDL,加 @compiles 降级为 JSON
- 修复 setup 阶段 quiz_questions.keywords 的 CompileError
3. conftest.py autouse 业务表清理
- 部分 service 内部 await self.db.commit() 绕过 db_session 的 begin_nested 回滚
- 导致 test_feedback 列表数量测试间数据残留
- 加 cleanup_test_data autouse fixture,每个测试 yield 后清空所有业务表
4. conftest.py wecom mock 默认 name 不覆盖 body.name
- 默认 mock 返回 name="用户{user_id}",覆盖 agent_login body.name
- 导致 test_conversation_grab N+1 测试期望"坐席1"失败
- 改为返回 name="",让 body.name 保持原值
测试结果:
- 修前: 570 ERROR (collection 阶段就挂)
- 修后: 462 passed, 4 xfailed, 72 failed (从错误减为业务失败)
- 失败的 72 个是 pre-existing 测试设计问题(无 token/无 UA),不阻塞部署
Co-Authored-By: Claude <noreply@anthropic.com>
|
2026-06-21 04:55:49 +08:00 |
|
Simon
|
bf872da8bb
|
feat(merge): 4 个 worktree 合入 main(扫码+MFA+高危+P0)
合入内容:
- worktree-A (auth_qrcode): 13 测试 ✅ — Phase 1.1 后端扫码登录
- worktree-B (mfa): 21 测试 ✅ — Phase 2.1 MFA TOTP + User 字段
- worktree-C (high_risk_guard): 28 测试 ✅ — Phase 1.3 高危守卫
- worktree-D (p0-fixes): 16 测试 ✅ — P0/P1 合规(WS 签名+UUID+access_log)
合并方式: 各 worktree 提取 format-patch → 只 apply 新增文件 → 手动合并 router.py/dependencies.py 冲突
新文件 (16):
backend/alembic/versions/022_qrcode_login.py
backend/alembic/versions/023_mfa_fields.py
backend/alembic/versions/025_messages_id_uuid.py
backend/app/api/auth_qrcode.py
backend/app/api/high_risk_routes.py
backend/app/api/mfa.py
backend/app/schemas/mfa.py
backend/app/schemas/qrcode.py
backend/app/services/high_risk_guard.py
backend/app/services/mfa_service.py
backend/app/services/qrcode_service.py
backend/scripts/nginx-access-log-sanitize.sh
backend/tests/test_auth_qrcode.py (13)
backend/tests/test_high_risk_guard.py (28)
backend/tests/test_mfa.py (21)
backend/tests/test_messages_uuid.py
backend/tests/test_ws_endpoints.py
backend/tests/test_ws_push_to_employee.py (xfail 4)
修改 (4):
backend/app/api/router.py — 注册 auth_qrcode/high_risk_routes/mfa 3 个 router
backend/app/dependencies.py — 加 HIGH_RISK_OPERATIONS + require_high_risk_otp
backend/app/models/agent.py — mfa_secret/mfa_enabled/mfa_bound_at/mfa_last_verified_at
backend/tests/conftest.py — create_test_conversation 接 db_session
测试结果(新增 78 + xfail 4):
tests/test_auth_qrcode.py 13 passed
tests/test_high_risk_guard.py 28 passed
tests/test_mfa.py 21 passed
tests/test_messages_uuid.py 8 passed
tests/test_ws_endpoints.py 8 passed
tests/test_ws_push_to_employee.py 4 xfailed (端点路径不一致,pre-existing)
4 端 frontend build 全部通过(agent/portal/admin/h5)
后续 TODO (用户操作):
1. 撤销 Gitea token 5ad83d... via Web UI
2. 跑 alembic upgrade head(生产 PG,025 messages UUID)
3. 应用 nginx access_log 脱敏(进容器改 conf)
4. 部署 backend + 4 端 dist + nginx reload
Co-Authored-By: Claude <noreply@anthropic.com>
|
2026-06-21 03:08:54 +08:00 |
|