Files
wenzi/docs/prd/P1_P2_可执行修复工单.md

250 lines
8.4 KiB
Markdown
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.
# P1/P2 可执行修复工单(文件级)
## 总览
| 工单ID | 优先级 | 主题 | 当前状态 |
|---|---|---|---|
| MOSQ-P1-001 | P1 | E2E 严格断言,消除 401/异常吞掉导致假绿 | 已修复(2026-03-20) |
| MOSQ-P1-002 | P1 | 解封关键集成测试(去 Disabled + 取消 surefire 排除) | 已落地 |
| MOSQ-P2-001 | P2 | 审批失败回滚的 anonymous 容错不应吞异常 | 已落地 |
| MOSQ-P2-002 | P2 | AuthService demo fallback 与硬编码 demo hash 清理 | 已落地 |
| MOSQ-P2-003 | P2 | 权限迁移测试CI可信度CI已配置strict模式 | 已落地 |
| MOSQ-P2-004 | P2 | 生产环境风控前置检查文档 | 已补充(2026-03-20) |
---
## MOSQ-P1-001E2E 严格断言修复
### 目标
- 禁止 `user-journey` 用例吞掉 API 错误后仍通过。
- 无真实凭证时必须“显式跳过”,有真实凭证时必须“严格断言 2xx”。
### 文件级变更步骤
1. 修改 `frontend/e2e/fixtures/test-data.ts`
- 新增 `TestData.userToken` 字段。
- 新增 `hasRealApiCredentials()`,用于判断是否真实凭证(非占位值)。
- `apiClient` 使用 `testData.userToken`,不再硬编码 `test-e2e-token`
2. 修改 `frontend/e2e/tests/user-journey.spec.ts`
- 在核心旅程用例 `beforeEach` 增加 `test.skip(!hasRealApiCredentials(...))`
- 去除 API 步骤中的 `try/catch` 吞错逻辑。
- 为关键 API活动列表/详情/统计/排行榜/短链/分享)增加强断言。
3. 修改 `frontend/e2e/tests/user-journey-fixed.spec.ts`
- 同步改为严格断言模式。
- 无真实凭证显式 `skip`,不允许“日志告警后通过”。
### 测试用例
1. 语法与装配检查
- 命令:
- `cd frontend/e2e && npx playwright test --config playwright.config.ts --list`
- 实际27 条测试分布在6个文件中api-smoke、h5-user-operations、simple-health、user-frontend-operation、user-journey、user-journey-fixed
2. 无真实凭证场景
- 命令:
- `cd frontend/e2e && npx playwright test tests/user-journey-fixed.spec.ts --config playwright.config.ts --reporter=line`
- 预期:相关测试 `skipped`显式0 条"假通过"。
3. 有真实凭证场景(环境准备后)
- 命令:
- `cd frontend/e2e && npx playwright test --config playwright.config.ts`
- 预期:关键 API 步骤必须返回断言状态200/201/3xx出现 401/500 直接失败。
### 回滚策略
- 仅回退以下文件到修复前版本:
- `frontend/e2e/fixtures/test-data.ts`
- `frontend/e2e/tests/user-journey.spec.ts`
- `frontend/e2e/tests/user-journey-fixed.spec.ts`
### 工时评估
- 开发1.5h
- 验证0.5h
- 合计2.0h
### 验收标准
- 不存在 `try/catch + console.warn/console.log` 吞 API 失败并继续通过的路径。
- 无凭证时是“显式 skipped”有凭证时是“严格断言”。
---
## MOSQ-P1-002关键集成测试解封
### 目标
- 移除 `SimpleApiIntegrationTest` 禁用状态。
- 取消 surefire 对关键集成测试的默认排除。
- 通过测试桩修复认证链路,避免解封即失败。
### 文件级变更步骤
1. 修改 `src/test/java/com/mosquito/project/integration/AbstractIntegrationTest.java`
- 注入 `@MockBean AuthService`
- `@BeforeEach` 中 mock
- `validateToken(...) -> TokenInfo(10001L, ...)`
- `getUserById(...) -> UserInfo(...)`
- 导入 `TestSecurityConfig` 以稳定集成测试安全链路。
2. 修改 `src/test/java/com/mosquito/project/integration/SimpleApiIntegrationTest.java`
- 删除 `@Disabled` 注解。
3. 修改 `pom.xml`
-`maven-surefire-plugin``excludes` 中移除:
- `SimpleApiIntegrationTest`
- `ShortLinkRedirectIntegrationTest`
- `ActivityAnalyticsServiceIntegrationTest`
- `ActivityServiceCacheTest`
### 测试用例
1. P1 定向回归
- 命令:
- `mvn -q -Dtest=SimpleApiIntegrationTest,ShortLinkRedirectIntegrationTest,ActivityAnalyticsServiceIntegrationTest,ActivityServiceCacheTest test`
- 预期:
- `SimpleApiIntegrationTest` tests=6 failures=0 errors=0
- `ShortLinkRedirectIntegrationTest` tests=1 failures=0 errors=0
- `ActivityAnalyticsServiceIntegrationTest` tests=3 failures=0 errors=0
- `ActivityServiceCacheTest` tests=1 failures=0 errors=0
2. 全链路回归CI 脚本)
- 命令:
- `./scripts/ci/backend-verify.sh`
- 预期P1 改动相关测试不过不应引入新失败。
- 当前观察:存在既有非 P1 阻断项 `PermissionCanonicalMigrationTest` SQL 方言问题H2 对 `REGEXP` 不兼容)。
### 回滚策略
- 仅回退以下文件:
- `src/test/java/com/mosquito/project/integration/AbstractIntegrationTest.java`
- `src/test/java/com/mosquito/project/integration/SimpleApiIntegrationTest.java`
- `pom.xml`
### 工时评估
- 开发1.0h
- 验证1.0h
- 合计2.0h
### 验收标准
- `SimpleApiIntegrationTest` 不再被 `@Disabled`
- surefire 不再默认跳过上述 4 个关键集成测试。
- 定向回归全部通过。
---
## MOSQ-P2-001审批失败回滚 anonymous 容错
### 目标
- 审批流失败补偿中,不再吞掉写审计失败异常;至少记录 warn 并携带上下文。
### 文件级变更步骤
1. 修改 `src/main/java/com/mosquito/project/controller/ApiKeyController.java`
- 定位审批失败回滚分支(当前 `catch (Exception ignore)`)。
- 改为:
- 捕获后 `log.warn(...)`(包含 `approvalRecordId`/`apiKeyId`/`operator`)。
- 不影响主流程返回,但避免 silent failure。
2. 新增或修改测试
- 推荐新增:`src/test/java/com/mosquito/project/controller/ApiKeyControllerTest.java`
- 覆盖“审计写入异常但接口仍可预期返回”场景,并断言日志/行为。
### 测试用例
- `mvn -q -Dtest=ApiKeyControllerTest test`
### 回滚策略
- 回退 `ApiKeyController` 和新增测试文件。
### 工时评估
- 开发0.5h
- 验证0.5h
- 合计1.0h
### 验收标准
- 代码中不存在该处 `catch (Exception ignore)`
- 单测覆盖该容错路径。
---
## MOSQ-P2-002移除 demo fallback 与硬编码 demo hash
### 目标
- 彻底去除 demo 认证分支和硬编码 hash认证只依赖真实用户体系。
### 文件级变更步骤
1. 修改 `src/main/java/com/mosquito/project/service/AuthService.java`
- 删除 `ADMIN_HASH/OPERATOR_HASH` 常量。
- 删除 `verifyDemoUser/getDemoUserId/getDemoUserDisplayName` 及调用路径。
- `login` 在用户不存在时统一返回认证失败。
2. 补充测试
- 修改/新增 `src/test/java/com/mosquito/project/service/AuthServiceTest.java`
- 覆盖:
- 用户不存在 -> 认证失败
- 后端不再读取 `app.demo-auth.*` 配置(配置项已清理)
### 测试用例
- `mvn -q -Dtest=AuthServiceTest test`
### 回滚策略
- 回退 `AuthService` 与相关测试改动。
### 工时评估
- 开发1.0h
- 验证0.5h
- 合计1.5h
### 验收标准
- 主代码不存在硬编码 demo 凭据。
- 不存在"用户不存在时走 demo fallback"的认证分支。
---
## MOSQ-P2-003权限迁移测试CI可信度
### 目标
- CI环境中确保权限迁移测试不被跳过提升测试可信度。
### 现状
- `RolePermissionMigrationTest` 使用 `Assumptions.assumeTrue()` 在无Docker环境下跳过测试
- CI脚本 `scripts/ci/backend-verify.sh` 已配置 `-Dmigration.test.strict=true`
- 在无Docker本地环境中测试仍会被跳过这是预期行为
### 文件级变更步骤
无需代码修改CI配置已正确。
### 测试用例
1. CI环境验证
- 命令:`./scripts/ci/backend-verify.sh`
- 预期:`RolePermissionMigrationTest` 在CI中不被跳过
### 验收标准
- CI中 `RolePermissionMigrationTest` 必须执行,不被跳过。
---
## MOSQ-P2-004生产环境风控前置检查
### 目标
- 补充生产环境部署前的风控检查清单文档。
### 文件级变更
1. 新增文档:`docs/PRODUCTION_RISK_CHECKLIST.md`
### 检查清单内容
1. **认证与授权检查**
- [ ] 所有管理接口已配置权限验证
- [ ] API Key认证已启用
- [ ] CORS配置已限制可信域名
2. **数据安全检查**
- [ ] 敏感数据已加密存储
- [ ] 数据库连接已使用SSL
- [ ] 审计日志已启用
3. **风控规则检查**
- [ ] 风险规则已配置并启用
- [ ] 限流规则已配置
- [ ] 黑名单机制已就绪
4. **监控与告警检查**
- [ ] 健康检查接口已配置
- [ ] 异常告警已配置
- [ ] 日志收集已配置
### 验收标准
- 文档 `docs/PRODUCTION_RISK_CHECKLIST.md` 已创建并包含上述检查项。