Files
hms/wiki/testing.md
iven 0bf1822fa9
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled
fix: QA 第二轮修复 — PatientDetail 重构/测试覆盖/id_number 列宽/小程序 URL 规范化
- refactor(web): PatientDetail.tsx 拆分为 4 个子组件(737→334行)
- refactor(web): 提取 usePaginatedData hook 消除重复分页状态
- feat(db): patient.id_number varchar(20)→varchar(255) 容纳加密值
- test(health): 添加预约模块集成测试(创建/列表/租户隔离)
- test(plugin): 添加 6 个 SQL 注入 sanitize 测试
- fix(miniprogram): 7 个 service 文件 URL 构建规范化(params 对象)
- fix(miniprogram): 跨平台字段名对齐(birth_date/start_time/end_time)
2026-04-25 10:22:44 +08:00

120 lines
3.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.
---
title: 测试与验证
updated: 2026-04-23
status: stable
tags: [testing, verification]
---
# 测试与验证
> 从 [[index]] 导航。关联: [[infrastructure]] [[database]] [[frontend]] [[erp-server]]
## 1. 设计决策
- **真实数据库优先** — 集成测试用真实 PostgreSQL不用内存模拟
- **分层验证** — 编译检查 → 单元测试 → 功能验证 → 生产构建
- **环境配置统一由 [[infrastructure]] 管理** — 连接信息、启动命令、登录凭据见该页
## 2. 关键文件 + 验证清单
### 测试分布
| Crate | 测试数 | 覆盖 |
|-------|--------|------|
| erp-auth | 8 | 密码哈希、TTL 解析 |
| erp-core | 6 | RBAC 权限检查 |
| erp-workflow | 16 | BPMN 解析、表达式求值 |
| erp-plugin-prototype | 6 | WASM 插件集成 |
| **总计** | **36** | |
### 编译 + 测试
```bash
cargo check # 编译无错误
cargo test --workspace # 全量测试
cargo clippy -- -D warnings # Lint 无警告
cargo fmt --check # 格式检查
cd apps/web && pnpm build # 前端生产构建
```
### 功能验证端点
| 端点 | 说明 |
|------|------|
| `http://localhost:3000/api/v1/health` | 健康检查 |
| `http://localhost:3000/api/docs/openapi.json` | OpenAPI 文档 |
| `http://localhost:5174` | 前端页面 |
### API 快速测试
```bash
# 登录获取 Token
curl -s http://localhost:3000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"Admin@2026"}'
```
### 前端性能基准2026-04-18 Lighthouse
Accessibility / SEO / Best Practices 均 100LCP 840msCLS 0.02
### 微信小程序验证
```bash
cd apps/miniprogram && pnpm build:weapp # 构建
# 在微信开发者工具中打开 apps/miniprogram 项目
# 点击"编译" → 勾选协议 → 点击"微信一键登录"
```
验证点:登录成功 → 首页加载 → 各 Tab 页面可访问
## 3. 代码逻辑
### 集成契约
| 方向 | 模块 | 触发时机 |
|------|------|---------|
| 依赖 ← | [[infrastructure]] | 环境准备、连接信息 |
| 验证 → | [[erp-server]] | 健康检查、API 测试 |
| 验证 → | [[frontend]] | 生产构建 |
**不变量**: 功能验证需要后端服务运行中,编译检查必须先于测试通过
### 数据库常用查询
```bash
# 连接数据库
D:\postgreSQL\bin\psql.exe -U postgres -h localhost -d erp
```
```sql
SELECT version FROM seaql_migrations ORDER BY version; -- 迁移记录
SELECT code, name FROM permissions WHERE deleted_at IS NULL ORDER BY code; -- 插件权限
```
## 4. 活跃问题 + 陷阱
### 活跃问题
| 问题 | 级别 | 状态 |
|------|------|------|
| display_name 存储 XSS HTML | P1 | 待修复 |
| antd vendor chunk 2.9MB (gzip ~400KB) | P3 | 待优化 |
### 历史教训
- CRM 权限码与实体名不一致 → 403详见 [[wasm-plugin]] 权限命名铁律)
- `AppError::Internal` 无日志 → 500 静默(已加 `tracing::error`
- `build_scope_sql` 参数索引硬编码 → SQL 参数错位(已动态化)
⚠️ 首次 `cargo run` 需编译整个 workspace含 wasmtime后续增量快
⚠️ Redis 不可达时限流自动降级为 fail-open
## 5. 变更记录
| 日期 | 变更 |
|------|------|
| 2026-04-24 | 添加微信小程序验证步骤 |
| 2026-04-23 | 重构为 5 节结构,去除与 infrastructure.md 重复 |
| 2026-04-18 | Lighthouse 审计 + 性能优化 |