This commit is contained in:
2026-03-13 10:28:10 +08:00
parent f53f43a6b9
commit 4ec09661cd
9 changed files with 1071 additions and 18 deletions

111
AGENTS.md
View File

@@ -22,9 +22,14 @@ npm run package:linux # Linux
# 代码质量
npm run lint # ESLint 检查
npm run format # Prettier 格式化
# 测试
npm test # 运行测试
npm run test:watch # 监听模式
npm run test:coverage # 测试覆盖率
```
**注意**: 无测试框架,项目暂无测试文件
**重要**: 修改 `src/main/` 目录下的文件后,必须运行 `npm test` 确保测试通过
## 2. 项目架构
@@ -34,22 +39,34 @@ src/
│ ├── index.ts # 入口,创建窗口
│ ├── ipc-handlers.ts # IPC 处理器(所有通信入口)
│ ├── storage.ts # 文件存储 + 密码加密
── kintone-api.ts # Kintone REST API 封装
── kintone-api.ts # Kintone REST API 封装
│ └── __tests__/ # 主进程测试
├── preload/ # Preload 脚本
│ ├── index.ts # 暴露 API 到渲染进程
│ └── index.d.ts # 类型声明
├── shared/ # 跨进程共享代码
│ └── types/ # 共享类型定义
── renderer/ # React 渲染进程
└── src/
├── main.tsx # React 入口
├── App.tsx # 根组件
├── components/ # React 组件
└── stores/ # Zustand Stores
── renderer/ # React 渲染进程
└── src/
├── main.tsx # React 入口
├── App.tsx # 根组件
├── components/ # React 组件
└── stores/ # Zustand Stores
└── tests/ # 测试配置
├── setup.ts # 测试环境设置
└── mocks/ # Mock 文件
```
## 3. 路径别名
| 别名 | 路径 |
| ------------- | -------------------- |
| `@renderer/*` | `src/renderer/src/*` |
| `@main/*` | `src/main/*` |
| `@preload/*` | `src/preload/*` |
| `@shared/*` | `src/shared/*` |
## 4. 代码风格
| 别名 | 路径 |
| ------------- | -------------------- |
| `@renderer/*` | `src/renderer/src/*` |
@@ -291,3 +308,81 @@ eval "$(fnm env --use-on-cd)" && npm run dev
3. Explain the reasoning and benefits
4. If significant, ask user for confirmation before implementing
5. Update related documentation after implementation
## 12. 测试规范
### 测试框架
使用 **Vitest** 作为测试框架,与 Vite 原生集成。
### 测试文件结构
```
src/main/__tests__/ # 主进程测试
tests/
├── setup.ts # 全局测试设置
└── mocks/
└── electron.ts # Electron API Mocks
```
### 测试要求
1. **修改 `src/main/` 目录下的文件后,必须运行 `npm test` 确保测试通过**
2. 新增 API 功能时,应在 `src/main/__tests__/` 中添加对应测试
3. 测试文件命名:`*.test.ts`
### 运行测试
```bash
# 运行所有测试
npm test
# 监听模式
npm run test:watch
# 测试覆盖率
npm run test:coverage
```
### Mock Electron API
测试中需要 Mock Electron 的 API`safeStorage``app` 等),已在 `tests/mocks/electron.ts` 中提供。
```typescript
// tests/setup.ts 中自动 Mock
vi.mock("electron", () => import("./mocks/electron"));
```
### 测试示例
```typescript
import { describe, expect, it, beforeAll } from "vitest";
import { SelfKintoneClient, createKintoneClient } from "@main/kintone-api";
import type { DomainWithPassword } from "@shared/types/domain";
describe("SelfKintoneClient", () => {
let client: SelfKintoneClient;
beforeAll(() => {
client = createKintoneClient({
id: "test",
name: "Test",
domain: "example.cybozu.com",
username: "user",
password: "pass",
authType: "password",
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
});
});
it("should return the correct domain", () => {
expect(client.getDomain()).toBe("example.cybozu.com");
});
it("should test connection successfully", async () => {
const result = await client.testConnection();
expect(result.success).toBe(true);
});
});
```