@lobehub/chat 1.99.4 → 1.99.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,14 @@
1
1
  ---
2
2
  description: How to code review
3
- globs:
3
+ globs:
4
4
  alwaysApply: false
5
5
  ---
6
+
6
7
  # Role Description
7
8
 
8
- - You are a senior full-stack engineer skilled in performance optimization, security, and design systems.
9
- - You excel at reviewing code and providing constructive feedback.
10
- - Your task is to review submitted Git diffs **in Chinese** and return a structured review report.
9
+ - You are a senior full-stack engineer skilled in performance optimization, security, and design systems.
10
+ - You excel at reviewing code and providing constructive feedback.
11
+ - Your task is to review submitted Git diffs **in Chinese** and return a structured review report.
11
12
  - Review style: concise, direct, focused on what matters most, with actionable suggestions.
12
13
 
13
14
  ## Before the Review
@@ -16,54 +17,57 @@ Gather the modified code and context. Please strictly follow the process below:
16
17
 
17
18
  1. Use `read_file` to read [package.json](mdc:package.json)
18
19
  2. Use terminal to run command `git diff HEAD | cat` to obtain the diff and list the changed files. If you recieived empty result, run the same command once more.
19
- 3. Use `read_file` to open each changed file.
20
- 4. Use `read_file` to read [rules-attach.mdc](mdc:.cursor/rules/rules-attach.mdc). Even if you think it's unnecessary, you must read it.
21
- 5. combine changed files, step3 and `agent_requestable_workspace_rules`, list the rules which need to read
20
+ 3. Use `read_file` to open each changed file.
21
+ 4. Use `read_file` to read [rules-attach.mdc](mdc:.cursor/rules/rules-attach.mdc). Even if you think it's unnecessary, you must read it.
22
+ 5. combine changed files, step3 and `agent_requestable_workspace_rules`, list the rules which need to read
22
23
  6. Use `read_file` to read the rules list in step 5
23
24
 
24
25
  ## Review
25
26
 
26
27
  ### Code Style
27
28
 
28
- - Ensure JSDoc comments accurately reflect the implementation; update them when needed.
29
- - Look for opportunities to simplify or modernize code with the latest JavaScript/TypeScript features.
30
- - Prefer `async`/`await` over callbacks or chained `.then` promises.
31
- - Use consistent, descriptive naming—avoid obscure abbreviations.
32
- - Replace magic numbers or strings with well-named constants.
29
+ - Ensure JSDoc comments accurately reflect the implementation; update them when needed.
30
+ - Look for opportunities to simplify or modernize code with the latest JavaScript/TypeScript features.
31
+ - Prefer `async`/`await` over callbacks or chained `.then` promises.
32
+ - Use consistent, descriptive naming—avoid obscure abbreviations.
33
+ - Replace magic numbers or strings with well-named constants.
33
34
  - Use semantically meaningful variable, function, and class names.
34
35
  - Ignore purely formatting issues and other autofixable lint problems.
35
36
 
36
37
  ### Code Optimization
37
38
 
38
- - Prefer `for…of` loops to index-based `for` loops when feasible.
39
- - Decide whether callbacks should be **debounced** or **throttled**.
40
- - Use components from `@lobehub/ui`, Ant Design, or the existing design system instead of raw HTML tags (e.g., `Button` vs. `button`).
41
- - reuse npm packages already installed (e.g., `lodash/omit`) rather than reinventing the wheel.
42
- - Design for dark mode and mobile responsiveness:
43
- - Use the `antd-style` token system instead of hard-coded colors.
44
- - Select the proper component variants.
45
- - Performance considerations:
46
- - Where safe, convert sequential async flows to concurrent ones with `Promise.all`, `Promise.race`, etc.
39
+ - Prefer `for…of` loops to index-based `for` loops when feasible.
40
+ - Decide whether callbacks should be **debounced** or **throttled**.
41
+ - Use components from `@lobehub/ui`, Ant Design, or the existing design system instead of raw HTML tags (e.g., `Button` vs. `button`).
42
+ - reuse npm packages already installed (e.g., `lodash/omit`) rather than reinventing the wheel.
43
+ - Design for dark mode and mobile responsiveness:
44
+ - Use the `antd-style` token system instead of hard-coded colors.
45
+ - Select the proper component variants.
46
+ - Performance considerations:
47
+ - Where safe, convert sequential async flows to concurrent ones with `Promise.all`, `Promise.race`, etc.
47
48
  - Query only the required columns from a database rather than selecting entire rows.
48
49
 
49
50
  ### Obvious Bugs
50
51
 
51
- - Do not silently swallow errors in `catch` blocks; at minimum, log them.
52
- - Revert temporary code used only for testing (e.g., debug logs, temporary configs).
53
- - Remove empty handlers (e.g., an empty `onClick`).
52
+ - Do not silently swallow errors in `catch` blocks; at minimum, log them.
53
+ - Revert temporary code used only for testing (e.g., debug logs, temporary configs).
54
+ - Remove empty handlers (e.g., an empty `onClick`).
54
55
  - Confirm the UI degrades gracefully for unauthenticated users.
56
+ - Don't leave any debug logs in the code (except when using the `debug` module properly).
57
+ - When using the `debug` module, avoid `import { log } from 'debug'` as it logs directly to console. Use proper debug namespaces instead.
58
+ - Check logs for sensitive information like api key, etc
55
59
 
56
60
  ## After the Review: output
57
61
 
58
62
  1. Summary
59
- - Start with a brief explanation of what the change set does.
60
- - Summarize the changes for each modified file (or logical group).
63
+ - Start with a brief explanation of what the change set does.
64
+ - Summarize the changes for each modified file (or logical group).
61
65
  2. Comments Issues
62
- - List the most critical issues first.
63
- - Use an ordered list, which will be convenient for me to reference later.
64
- - For each issue:
65
- - Mark severity tag (`❌ Must fix`, `⚠️ Should fix`, `💅 Nitpick`)
66
- - Provode file path to the relevant file.
67
- - Provide recommended fix
68
- - End with a **git commit** command, instruct the author to run it.
69
- - We use gitmoji to label commit messages, format: [emoji] <type>(<scope>): <subject>
66
+ - List the most critical issues first.
67
+ - Use an ordered list, which will be convenient for me to reference later.
68
+ - For each issue:
69
+ - Mark severity tag (`❌ Must fix`, `⚠️ Should fix`, `💅 Nitpick`)
70
+ - Provode file path to the relevant file.
71
+ - Provide recommended fix
72
+ - End with a **git commit** command, instruct the author to run it.
73
+ - We use gitmoji to label commit messages, format: [emoji] <type>(<scope>): <subject>
@@ -1,8 +1,9 @@
1
1
  ---
2
- description:
3
- globs:
2
+ description:
3
+ globs:
4
4
  alwaysApply: true
5
5
  ---
6
+
6
7
  ## System Role
7
8
 
8
9
  You are an expert in full-stack Web development, proficient in JavaScript, TypeScript, CSS, React, Node.js, Next.js, Postgresql, all kinds of network protocols.
@@ -11,7 +12,6 @@ You are an expert in LLM and Ai art. In Ai image generation, you are proficient
11
12
 
12
13
  You are an expert in UI/UX design, proficient in web interaction patterns, responsive design, accessibility, and user behavior optimization. You excel at improving user retention and paid conversion rates through various interaction details.
13
14
 
14
-
15
15
  ## Problem Solving
16
16
 
17
17
  - Before formulating any response, you must first gather context by using tools like codebase_search, grep_search, file_search, web_search, fetch_rules, context7, and read_file to avoid making assumptions.
@@ -36,3 +36,8 @@ You are an expert in UI/UX design, proficient in web interaction patterns, respo
36
36
  - If you're unable to access or retrieve content from websites, please inform me immediately and request the specific information needed rather than making assumptions
37
37
  - You can use emojis, npm packages like `chalk`/`chalk-animation`/`terminal-link`/`gradient-string`/`log-symbols`/`boxen`/`consola`/`@clack/prompts` to create beautiful terminal output
38
38
  - Don't run `tsc --noEmit` to check ts syntax error, because our project is very large and the validate very slow
39
+
40
+ ## Some logging rules
41
+
42
+ - Never log user private information like api key, etc
43
+ - Don't use `import { log } from 'debug'` to log messages, because it will directly log the message to the console.
@@ -28,85 +28,39 @@ LobeChat 项目使用 Vitest 测试库,配置了两种不同的测试环境:
28
28
 
29
29
  ## 🚀 测试运行命令
30
30
 
31
- ### package.json 脚本说明
32
-
33
- 查看 [package.json](mdc:package.json) 中的测试相关脚本:
34
-
35
- ```json
36
- {
37
- "test": "npm run test-app && npm run test-server",
38
- "test-app": "vitest run --config vitest.config.ts",
39
- "test-app:coverage": "vitest run --config vitest.config.ts --coverage",
40
- "test-server": "vitest run --config vitest.config.server.ts",
41
- "test-server:coverage": "vitest run --config vitest.config.server.ts --coverage"
42
- }
43
- ```
44
-
45
- ### 推荐的测试运行方式
46
-
47
- #### ⚠️ 重要提醒
48
-
49
- **🚨 性能警告**:
50
-
51
- - **永远不要直接运行整个项目的所有测试用例** - 项目包含 3000+ 测试用例,完整运行需要约 10 分钟
52
- - **务必使用文件过滤或测试名称过滤** - 始终指定具体的测试文件或测试名称模式
53
- - **避免无意中触发全量测试** - 某些看似针对单个文件的命令实际上会运行所有测试
31
+ **🚨 性能警告**: 项目包含 3000+ 测试用例,完整运行需要约 10 分钟。务必使用文件过滤或测试名称过滤。
54
32
 
55
- #### ✅ 正确的命令格式
33
+ ### ✅ 正确的命令格式
56
34
 
57
35
  ```bash
58
- # 运行所有客户端测试
59
- npx vitest run --config vitest.config.ts
60
-
61
- # 运行所有服务端测试
62
- npx vitest run --config vitest.config.server.ts
36
+ # 运行所有客户端/服务端测试
37
+ npx vitest run --config vitest.config.ts # 客户端测试
38
+ npx vitest run --config vitest.config.server.ts # 服务端测试
63
39
 
64
40
  # 运行特定测试文件 (支持模糊匹配)
65
- npx vitest run --config vitest.config.ts basic
66
41
  npx vitest run --config vitest.config.ts user.test.ts
67
42
 
68
- # 运行特定文件的特定行号
69
- npx vitest run --config vitest.config.ts src/utils/helper.test.ts:25
70
- npx vitest run --config vitest.config.ts basic/foo.test.ts:10,basic/foo.test.ts:25
71
-
72
- # 过滤特定测试用例名称
73
- npx vitest -t "test case name" --config vitest.config.ts
43
+ # 运行特定测试用例名称 (使用 -t 参数)
44
+ npx vitest run --config vitest.config.ts -t "test case name"
74
45
 
75
46
  # 组合使用文件和测试名称过滤
76
47
  npx vitest run --config vitest.config.ts filename.test.ts -t "specific test"
48
+
49
+ # 生成覆盖率报告 (使用 --coverage 参数)
50
+ npx vitest run --config vitest.config.ts --coverage
77
51
  ```
78
52
 
79
- #### ❌ 避免的命令格式
53
+ ### ❌ 避免的命令格式
80
54
 
81
55
  ```bash
82
56
  # ❌ 这些命令会运行所有 3000+ 测试用例,耗时约 10 分钟!
83
57
  npm test
84
- npm run test
85
- pnpm test
86
- pnpm run test
87
-
88
- # ❌ 这些命令看似针对单个文件,但实际会运行所有测试用例!, 需要直接运行 vitest 命令不要使用 test npm script
89
- npm test src/libs/model-runtime/utils/openaiCompatibleFactory/index.test.ts
90
- pnpm test src/components/Button/index.test.tsx
91
-
92
- # ❌ 不要使用 pnpm test xxx (这不是有效的 vitest 命令)
93
- pnpm test some-file
58
+ npm test some-file.test.ts
94
59
 
95
60
  # ❌ 不要使用裸 vitest (会进入 watch 模式)
96
61
  vitest test-file.test.ts
97
-
98
- # ❌ 不要混淆测试环境
99
- npx vitest run --config vitest.config.server.ts client-component.test.ts
100
62
  ```
101
63
 
102
- ### 关键运行参数说明
103
-
104
- - **`vitest run`**: 运行一次测试然后退出 (避免 watch 模式)
105
- - **`vitest`**: 默认进入 watch 模式,持续监听文件变化
106
- - **`--config`**: 指定配置文件,选择正确的测试环境
107
- - **`-t`**: 过滤测试用例名称,支持正则表达式
108
- - **`--coverage`**: 生成测试覆盖率报告
109
-
110
64
  ## 🔧 测试修复原则
111
65
 
112
66
  ### 核心原则 ⚠️
@@ -116,46 +70,125 @@ npx vitest run --config vitest.config.server.ts client-component.test.ts
116
70
  3. **专注单一问题**: 只修复指定的测试,不要添加额外测试或功能
117
71
  4. **不自作主张**: 不要因为发现其他问题就直接修改,先提出再讨论
118
72
 
119
- ### 测试修复流程
73
+ ### 测试协作最佳实践 🤝
74
+
75
+ 基于实际开发经验总结的重要协作原则:
120
76
 
121
- ```mermaid
122
- flowchart TD
123
- subgraph "阶段一:分析与复现"
124
- A[开始:收到测试失败报告] --> B[定位并运行失败的测试];
125
- B --> C{是否能在本地复现?};
126
- C -->|否| D[检查测试环境/配置/依赖];
127
- C -->|是| E[分析:阅读测试代码、错误日志、Git 历史];
128
- end
129
-
130
- subgraph "阶段二:诊断与调试"
131
- E --> F[建立假设:问题出在测试、代码还是环境?];
132
- F --> G["调试:使用 console.log 或 debugger 深入检查"];
133
- G --> H{假设是否被证实?};
134
- H -->|否, 重新假设| F;
135
- end
136
-
137
- subgraph "阶段三:修复与验证"
138
- H -->|是| I{确定根本原因};
139
- I -->|测试逻辑错误| J[修复测试代码];
140
- I -->|实现代码 Bug| K[修复实现代码];
141
- I -->|环境/配置问题| L[修复配置或依赖];
142
- J --> M[验证修复:重新运行失败的测试];
143
- K --> M;
144
- L --> M;
145
- M --> N{测试是否通过?};
146
- N -->|否, 修复无效| F;
147
- N -->|是| O[扩大验证:运行当前文件内所有测试];
148
- O --> P{是否全部通过?};
149
- P -->|否, 引入新问题| F;
150
- end
151
-
152
- subgraph "阶段四:总结"
153
- P -->|是| Q[完成:撰写修复总结];
154
- end
155
-
156
- D --> F;
77
+ #### 1. 失败处理策略
78
+
79
+ **核心原则**: 避免盲目重试,快速识别问题并寻求帮助。
80
+
81
+ - **失败阈值**: 当连续尝试修复测试 1-2 次都失败后,应立即停止继续尝试
82
+ - **问题总结**: 分析失败原因,整理已尝试的解决方案及其失败原因
83
+ - **寻求帮助**: 带着清晰的问题摘要和尝试记录向团队寻求帮助
84
+ - **避免陷阱**: 不要陷入"不断尝试相同或类似方法"的循环
85
+
86
+ ```typescript
87
+ // 错误做法:连续失败后继续盲目尝试
88
+ // 第3次、第4次仍在用相似的方法修复同一个问题
89
+
90
+ // 正确做法:失败1-2次后总结问题
91
+ /*
92
+ 问题总结:
93
+ 1. 尝试过的方法:修改 mock 数据结构
94
+ 2. 失败原因:仍然提示类型不匹配
95
+ 3. 具体错误:Expected 'UserData' but received 'UserProfile'
96
+ 4. 需要帮助:不确定最新的 UserData 接口定义
97
+ */
157
98
  ```
158
99
 
100
+ #### 2. 测试用例命名规范
101
+
102
+ **核心原则**: 测试应该关注"行为",而不是"实现细节"。
103
+
104
+ - **描述业务场景**: `describe` 和 `it` 的标题应该描述具体的业务场景和预期行为
105
+ - **避免实现绑定**: 不要在测试名称中提及具体的代码行号、覆盖率目标或实现细节
106
+ - **保持稳定性**: 测试名称应该在代码重构后仍然有意义
107
+
108
+ ```typescript
109
+ // ❌ 错误的测试命名
110
+ describe('User component coverage', () => {
111
+ it('covers line 45-50 in getUserData', () => {
112
+ // 为了覆盖第45-50行而写的测试
113
+ });
114
+
115
+ it('tests the else branch', () => {
116
+ // 仅为了测试某个分支而存在
117
+ });
118
+ });
119
+
120
+ // ✅ 正确的测试命名
121
+ describe('<UserAvatar />', () => {
122
+ it('should render fallback icon when image url is not provided', () => {
123
+ // 测试具体的业务场景,自然会覆盖相关代码分支
124
+ });
125
+
126
+ it('should display user initials when avatar image fails to load', () => {
127
+ // 描述用户行为和预期结果
128
+ });
129
+ });
130
+ ```
131
+
132
+ **覆盖率提升的正确思路**:
133
+
134
+ - ✅ 通过设计各种业务场景(正常流程、边缘情况、错误处理)来自然提升覆盖率
135
+ - ❌ 不要为了达到覆盖率数字而写测试,更不要在测试中注释"为了覆盖 xxx 行"
136
+
137
+ #### 3. 测试组织结构
138
+
139
+ **核心原则**: 维护清晰的测试层次结构,避免冗余的顶级测试块。
140
+
141
+ - **复用现有结构**: 添加新测试时,优先在现有的 `describe` 块中寻找合适的位置
142
+ - **逻辑分组**: 相关的测试用例应该组织在同一个 `describe` 块内
143
+ - **避免碎片化**: 不要为了单个测试用例就创建新的顶级 `describe` 块
144
+
145
+ ```typescript
146
+ // ❌ 错误的组织方式:创建过多顶级块
147
+ describe('<UserProfile />', () => {
148
+ it('should render user name', () => {});
149
+ });
150
+
151
+ describe('UserProfile new prop test', () => {
152
+ // 不必要的新块
153
+ it('should handle email display', () => {});
154
+ });
155
+
156
+ describe('UserProfile edge cases', () => {
157
+ // 不必要的新块
158
+ it('should handle missing avatar', () => {});
159
+ });
160
+
161
+ // ✅ 正确的组织方式:合并相关测试
162
+ describe('<UserProfile />', () => {
163
+ it('should render user name', () => {});
164
+
165
+ it('should handle email display', () => {});
166
+
167
+ it('should handle missing avatar', () => {});
168
+
169
+ describe('when user data is incomplete', () => {
170
+ // 只有在有多个相关子场景时才创建子组
171
+ it('should show placeholder for missing name', () => {});
172
+ it('should hide email section when email is undefined', () => {});
173
+ });
174
+ });
175
+ ```
176
+
177
+ **组织决策流程**:
178
+
179
+ 1. 是否存在逻辑相关的现有 `describe` 块? → 如果有,添加到其中
180
+ 2. 是否有多个(3个以上)相关的测试用例? → 如果有,可以考虑创建新的子 `describe`
181
+ 3. 是否是独立的、无关联的功能模块? → 如果是,才考虑创建新的顶级 `describe`
182
+
183
+ ### 测试修复流程
184
+
185
+ 1. **复现问题**: 定位并运行失败的测试,确认能在本地复现
186
+ 2. **分析原因**: 阅读测试代码、错误日志和相关文件的 Git 修改历史
187
+ 3. **建立假设**: 判断问题出在测试逻辑、实现代码还是环境配置
188
+ 4. **修复验证**: 根据假设进行修复,重新运行测试确认通过
189
+ 5. **扩大验证**: 运行当前文件内所有测试,确保没有引入新问题
190
+ 6. **撰写总结**: 说明错误原因和修复方法
191
+
159
192
  ### 修复完成后的总结
160
193
 
161
194
  测试修复完成后,应该提供简要说明,包括:
@@ -197,7 +230,7 @@ flowchart TD
197
230
 
198
231
  例如:
199
232
 
200
- ```
233
+ ```plaintext
201
234
  src/components/Button/
202
235
  ├── index.tsx # 源文件
203
236
  └── index.test.tsx # 测试文件
@@ -205,13 +238,12 @@ src/components/Button/
205
238
 
206
239
  ## 🛠️ 测试调试技巧
207
240
 
208
- ### 运行失败测试的步骤
241
+ ### 测试调试步骤
209
242
 
210
- 1. **确定测试类型**: 查看文件路径确定使用哪个配置
211
- 2. **运行单个测试**: 使用 `-t` 参数隔离问题
212
- 3. **检查错误日志**: 仔细阅读错误信息和堆栈跟踪
213
- 4. **查看最近修改记录**: 检查相关文件的最近变更情况
214
- 5. **添加调试日志**: 在测试中添加 `console.log` 了解执行流程
243
+ 1. **确定测试环境**: 根据文件路径选择正确的配置文件
244
+ 2. **隔离问题**: 使用 `-t` 参数只运行失败的测试用例
245
+ 3. **分析错误**: 仔细阅读错误信息、堆栈跟踪和最近的文件修改记录
246
+ 4. **添加调试**: 在测试中添加 `console.log` 了解执行流程
215
247
 
216
248
  ### TypeScript 类型处理 📝
217
249
 
@@ -245,157 +277,47 @@ mockStream.toReadableStream = () => mockStream;
245
277
 
246
278
  ### 检查最近修改记录 🔍
247
279
 
248
- 为了更好地判断测试失败的根本原因,需要**系统性地检查相关文件的修改历史**。这是问题定位的关键步骤。
249
-
250
- #### 第一步:确定需要检查的文件范围
280
+ 系统性地检查相关文件的修改历史是问题定位的关键步骤。
251
281
 
252
- 1. **测试文件本身**: `path/to/component.test.ts`
253
- 2. **对应的实现文件**: `path/to/component.ts` 或 `path/to/component/index.ts`
254
- 3. **相关依赖文件**: 测试或实现中导入的其他模块
282
+ #### 三步检查法
255
283
 
256
- #### 第二步:检查当前工作目录状态
284
+ **Step 1: 查看当前状态**
257
285
 
258
286
  ```bash
259
- # 查看所有未提交的修改状态
260
- git status
261
-
262
- # 重点关注测试文件和实现文件是否有未提交的修改
263
- git status | grep -E "(test|spec)"
264
- ```
265
-
266
- #### 第三步:检查未提交的修改内容
267
-
268
- ```bash
269
- # 查看测试文件的未提交修改 (工作区 vs 暂存区)
270
- git diff path/to/component.test.ts | cat
271
-
272
- # 查看对应实现文件的未提交修改
273
- git diff path/to/component.ts | cat
274
-
275
- # 查看已暂存但未提交的修改
276
- git diff --cached path/to/component.test.ts | cat
277
- git diff --cached path/to/component.ts | cat
287
+ git status # 查看未提交的修改
288
+ git diff path/to/component.test.ts | cat # 查看测试文件修改
289
+ git diff path/to/component.ts | cat # 查看实现文件修改
278
290
  ```
279
291
 
280
- #### 第四步:检查提交历史和时间相关性
281
-
282
- **首先查看提交时间,判断修改的时效性**:
292
+ **Step 2: 查看提交历史**
283
293
 
284
294
  ```bash
285
- # 查看测试文件的最近提交历史,包含提交时间
286
- git log --pretty=format:"%h %ad %s" --date=relative -5 path/to/component.test.ts | cat
287
-
288
- # 查看实现文件的最近提交历史,包含提交时间
289
- git log --pretty=format:"%h %ad %s" --date=relative -5 path/to/component.ts | cat
290
-
291
- # 查看详细的提交时间(ISO格式,便于精确判断)
292
- git log --pretty=format:"%h %ad %an %s" --date=iso -3 path/to/component.ts | cat
293
- git log --pretty=format:"%h %ad %an %s" --date=iso -3 path/to/component.test.ts | cat
295
+ git log --pretty=format:"%h %ad %s" --date=relative -3 path/to/component.ts | cat
294
296
  ```
295
297
 
296
- **判断提交的参考价值**:
297
-
298
- 1. **最近提交(24小时内)**: 🔴 **高度相关** - 很可能是导致测试失败的直接原因
299
- 2. **近期提交(1-7天内)**: 🟡 **中等相关** - 可能相关,需要仔细分析修改内容
300
- 3. **较早提交(超过1周)**: ⚪ **低相关性** - 除非是重大重构,否则不太可能是直接原因
301
-
302
- #### 第五步:基于时间相关性查看具体修改内容
303
-
304
- **根据提交时间的远近,优先查看最近的修改**:
298
+ **Step 3: 查看具体修改内容**
305
299
 
306
300
  ```bash
307
- # 如果有24小时内的提交,重点查看这些修改
308
- git show HEAD -- path/to/component.test.ts | cat
309
- git show HEAD -- path/to/component.ts | cat
310
-
311
- # 查看次新的提交(如果最新提交时间较远)
312
- git show HEAD~1 -- path/to/component.ts | cat
313
- git show path/to/component.ts < recent-commit-hash > -- | cat
314
-
315
- # 对比最近两次提交的差异
316
- git diff HEAD~1 HEAD -- path/to/component.ts | cat
301
+ git show HEAD -- path/to/component.ts | cat # 查看最新提交的修改
317
302
  ```
318
303
 
319
- #### 第六步:分析修改与测试失败的关系
304
+ #### 时间相关性判断
320
305
 
321
- 基于修改记录和时间相关性判断:
322
-
323
- 1. **最近修改了实现代码**:
324
-
325
- ```bash
326
- # 重点检查实现逻辑的变化
327
- git diff HEAD~1 path/to/component.ts | cat
328
- ```
329
-
330
- - 很可能是实现代码的变更导致测试失败
331
- - 检查实现逻辑是否正确
332
- - 确认测试是否需要相应更新
333
-
334
- 2. **最近修改了测试代码**:
335
-
336
- ```bash
337
- # 重点检查测试逻辑的变化
338
- git diff HEAD~1 path/to/component.test.ts | cat
339
- ```
340
-
341
- - 可能是测试本身写错了
342
- - 检查测试逻辑和断言是否正确
343
- - 确认测试是否符合实现的预期行为
344
-
345
- 3. **两者都有最近修改**:
346
-
347
- ```bash
348
- # 对比两个文件的修改时间
349
- git log --pretty=format:"%ad %f" --date=iso -1 path/to/component.ts | cat
350
- git log --pretty=format:"%ad %f" --date=iso -1 path/to/component.test.ts | cat
351
- ```
352
-
353
- - 需要综合分析两者的修改
354
- - 确定哪个修改更可能导致问题
355
- - 优先检查时间更近的修改
356
-
357
- 4. **都没有最近修改**:
358
- - 可能是依赖变更或环境问题
359
- - 检查 `package.json`、配置文件等的修改
360
- - 查看是否有全局性的代码重构
361
-
362
- #### 修改记录检查示例
363
-
364
- ```bash
365
- # 完整的检查流程示例
366
- echo "=== 检查文件修改状态 ==="
367
- git status | grep component
368
-
369
- echo "=== 检查未提交修改 ==="
370
- git diff src/components/Button/index.test.tsx | cat
371
- git diff src/components/Button/index.tsx | cat
372
-
373
- echo "=== 检查提交历史和时间 ==="
374
- git log --pretty=format:"%h %ad %s" --date=relative -3 src/components/Button/index.test.tsx | cat
375
- git log --pretty=format:"%h %ad %s" --date=relative -3 src/components/Button/index.tsx | cat
376
-
377
- echo "=== 根据时间优先级查看修改内容 ==="
378
- # 如果有24小时内的提交,重点查看
379
- git show HEAD -- src/components/Button/index.tsx | cat
380
- ```
306
+ - **24小时内的提交**: 🔴 **高度相关** - 很可能是直接原因
307
+ - **1-7天内的提交**: 🟡 **中等相关** - 需要仔细分析
308
+ - **超过1周的提交**: ⚪ **低相关性** - 除非重大重构
381
309
 
382
310
  ## 特殊场景的测试
383
311
 
384
- 针对一些特殊场景的测试,需要阅读相关文件:
312
+ 针对一些特殊场景的测试,需要阅读相关 rules:
385
313
 
386
314
  - [Electron IPC 接口测试策略](mdc:./electron-ipc-test.mdc)
387
315
  - [数据库 Model 测试指南](mdc:./db-model-test.mdc)
388
316
 
389
- ## 🎯 总结
390
-
391
- 修复测试时,记住以下关键点:
317
+ ## 🎯 核心要点
392
318
 
393
- - **使用正确的命令**: `npx vitest run --config [config-file]`
394
- - **理解测试意图**: 先读懂测试再修复
395
- - **查看最近修改**: 检查相关文件的 git 修改记录,判断问题根源
396
- - **选择正确环境**: 客户端测试用 `vitest.config.ts`,服务端用 `vitest.config.server.ts`
397
- - **专注单一问题**: 只修复当前的测试失败
398
- - **验证修复结果**: 确保修复后测试通过且无副作用
399
- - **提供修复总结**: 说明错误原因和修复方法
400
- - **Model 测试安全第一**: 必须包含用户权限检查和对应的安全测试
401
- - **Model 双环境验证**: 必须在 PGLite 和 PostgreSQL 两个环境下都验证通过
319
+ - **命令格式**: 使用 `npx vitest run --config [config-file]` 并指定文件过滤
320
+ - **修复原则**: 失败1-2次后寻求帮助,测试命名关注行为而非实现细节
321
+ - **调试流程**: 复现 分析 → 假设 → 修复 → 验证 → 总结
322
+ - **文件组织**: 优先在现有 `describe` 块中添加测试,避免创建冗余顶级块
323
+ - **安全要求**: Model 测试必须包含权限检查,并在双环境下验证通过
package/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.99.6](https://github.com/lobehub/lobe-chat/compare/v1.99.5...v1.99.6)
6
+
7
+ <sup>Released on **2025-07-16**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Desktop local db can't upload image.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Desktop local db can't upload image, closes [#8459](https://github.com/lobehub/lobe-chat/issues/8459) ([25bfc80](https://github.com/lobehub/lobe-chat/commit/25bfc80))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
30
+ ### [Version 1.99.5](https://github.com/lobehub/lobe-chat/compare/v1.99.4...v1.99.5)
31
+
32
+ <sup>Released on **2025-07-16**</sup>
33
+
34
+ #### 🐛 Bug Fixes
35
+
36
+ - **misc**: Fix page error when url is not defined in web search plugin.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **misc**: Fix page error when url is not defined in web search plugin, closes [#8441](https://github.com/lobehub/lobe-chat/issues/8441) ([a55b65b](https://github.com/lobehub/lobe-chat/commit/a55b65b))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ### [Version 1.99.4](https://github.com/lobehub/lobe-chat/compare/v1.99.3...v1.99.4)
6
56
 
7
57
  <sup>Released on **2025-07-16**</sup>
@@ -20,7 +20,7 @@
20
20
  "electron:run-unpack": "electron .",
21
21
  "format": "prettier --write ",
22
22
  "i18n": "bun run scripts/i18nWorkflow/index.ts && lobe-i18n",
23
- "postinstall": "electron-builder install-app-deps && pnpm rebuild sharp",
23
+ "postinstall": "electron-builder install-app-deps",
24
24
  "install-isolated": "pnpm install",
25
25
  "lint": "eslint --cache ",
26
26
  "pg-server": "bun run scripts/pglite-server.ts",