Files
hms/wiki/testing.md
iven ca50d32f6e
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
feat(health): 添加 erp-health 健康管理模块骨架
新建 erp-health 原生 Rust crate,覆盖设计规格中定义的 5 大业务域:

- 16 个 SeaORM Entity(患者/家属/标签/医生/健康档案/体征/化验单/预约/排班/随访/咨询等)
- 16 表数据库迁移(含索引、外键、默认值、可回滚)
- 40+ API 路由骨架(患者管理/健康数据/预约排班/随访/咨询/医生管理)
- 12 个权限声明(health.patient/health-data/appointment/follow-up/consultation/doctor 各 .list/.manage)
- DTO / Service / Handler / Event 四层架构,Service 使用 todo!() 占位
- erp-server 集成:模块注册 + AppState FromRef 桥接 + 路由挂载

同步更新 CLAUDE.md 项目进度、wiki 知识库、设计规格文档。
2026-04-23 19:59:22 +08:00

3.1 KiB
Raw Blame History

title, updated, status, tags
title updated status tags
测试与验证 2026-04-23 stable
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

编译 + 测试

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 快速测试

# 登录获取 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

3. 代码逻辑

集成契约

方向 模块 触发时机
依赖 ← infrastructure 环境准备、连接信息
验证 → erp-server 健康检查、API 测试
验证 → frontend 生产构建

不变量: 功能验证需要后端服务运行中,编译检查必须先于测试通过

数据库常用查询

# 连接数据库
D:\postgreSQL\bin\psql.exe -U postgres -h localhost -d erp
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-23 重构为 5 节结构,去除与 infrastructure.md 重复
2026-04-18 Lighthouse 审计 + 性能优化