chore: apply cargo fmt across workspace and update docs

- Run cargo fmt on all Rust crates for consistent formatting
- Update CLAUDE.md with WASM plugin commands and dev.ps1 instructions
- Update wiki: add WASM plugin architecture, rewrite dev environment docs
- Minor frontend cleanup (unused imports)
This commit is contained in:
iven
2026-04-15 00:49:20 +08:00
parent e16c1a85d7
commit 9568dd7875
113 changed files with 4355 additions and 937 deletions

193
wiki/testing.md Normal file
View File

@@ -0,0 +1,193 @@
# 测试环境指南
> 本项目在 **Windows** 环境下开发,使用 PowerShell 脚本一键启动。不使用 Docker数据库和缓存直接通过原生安装运行。
## 环境要求
| 工具 | 最低版本 | 用途 |
|------|---------|------|
| Rust | stable (1.93+) | 后端编译 |
| Node.js | 20+ | 前端工具链 |
| pnpm | 9+ | 前端包管理 |
| PostgreSQL | 16+ | 主数据库 |
| Redis | 7+ | 缓存 + 会话 |
## 服务连接信息
| 服务 | 地址 | 用途 |
|------|------|------|
| PostgreSQL | `postgres://erp:erp_dev_2024@localhost:5432/erp` | 主数据库 |
| Redis | `redis://localhost:6379` | 缓存 + 会话 |
| 后端 API | `http://localhost:3000/api/v1` | Axum 服务 |
| 前端 SPA | `http://localhost:5174` | Vite 开发服务器 |
## 一键启动(推荐)
使用 PowerShell 脚本管理前后端服务:
```powershell
.\dev.ps1 # 启动后端 + 前端
.\dev.ps1 -Status # 查看端口状态
.\dev.ps1 -Restart # 重启所有服务
.\dev.ps1 -Stop # 停止所有服务
```
脚本会自动:
1. 清理端口占用
2. 编译并启动 Rust 后端 (`cargo run -p erp-server`)
3. 安装前端依赖并启动 Vite 开发服务器 (`pnpm dev`)
## 手动启动
### 1. 启动基础设施
确保 PostgreSQL 和 Redis 服务已在 Windows 上运行:
```powershell
# 检查 PostgreSQL 服务状态
Get-Service -Name "postgresql*"
# 检查 Redis 是否运行(如果作为 Windows 服务安装)
Get-Service -Name "Redis" -ErrorAction SilentlyContinue
# 或通过命令行启动 Redis
redis-server
```
### 2. 启动后端
```powershell
cargo run -p erp-server
```
首次运行会自动执行数据库迁移。
### 3. 启动前端
```powershell
cd apps/web
pnpm install # 首次需要安装依赖
pnpm dev # 启动开发服务器
```
## 验证清单
### 后端验证
```bash
# 编译检查(无错误)
cargo check
# 全量测试(应全部通过)
cargo test --workspace
# Lint 检查(无警告)
cargo clippy -- -D warnings
# 格式检查
cargo fmt --check
```
### 前端验证
```bash
cd apps/web
# 安装依赖
pnpm install
# TypeScript 编译 + 生产构建
pnpm build
# 类型检查
pnpm tsc -b
```
### 功能验证
| 端点 | 方法 | 说明 |
|------|------|------|
| `http://localhost:3000/api/v1/health` | GET | 健康检查 |
| `http://localhost:3000/api/docs/openapi.json` | GET | OpenAPI 文档 |
| `http://localhost:5174` | GET | 前端页面 |
### 登录信息
- 用户名: `admin`
- 密码: `Admin@2026`
## 数据库管理
### 连接数据库
```bash
psql -U erp -d erp -h localhost
```
### 查看表结构
```sql
\dt -- 列出所有表
\d table_name -- 查看表结构
```
### 迁移
迁移在 `crates/erp-server/migration/src/` 目录下。后端启动时自动执行。
## 测试详情
### 测试分布
| Crate | 测试数 | 说明 |
|-------|--------|------|
| erp-auth | 8 | 密码哈希、TTL 解析 |
| erp-core | 6 | RBAC 权限检查 |
| erp-workflow | 16 | BPMN 解析、表达式求值 |
| erp-plugin-prototype | 6 | WASM 插件集成测试 |
| **总计** | **36** | |
### 运行特定测试
```bash
# 运行单个 crate 的测试
cargo test -p erp-auth
# 运行匹配名称的测试
cargo test -p erp-core -- require_permission
# 运行插件集成测试
cargo test -p erp-plugin-prototype
```
## 常见问题
### Q: 端口被占用
```powershell
# 查看占用端口的进程
Get-NetTCPConnection -LocalPort 3000 -State Listen
# 终止进程
Stop-Process -Id <PID> -Force
# 或使用 dev.ps1 自动清理
.\dev.ps1 -Stop
```
### Q: 数据库连接失败
1. 确认 PostgreSQL 服务正在运行
2. 检查 `crates/erp-server/config/default.toml` 中的连接字符串
3. 确认 `erp` 数据库已创建
### Q: 首次启动很慢
首次 `cargo run` 需要编译整个 workspace后续增量编译会很快。
## 关联模块
- [[infrastructure]] — 基础设施配置详情
- [[database]] — 数据库迁移和表结构
- [[frontend]] — 前端技术栈和配置
- [[erp-server]] — 后端服务配置