@@ -61,7 +61,7 @@ vi.mock("../wiki-prompts/subtasks/constants", () => ({
6161
6262vi . mock ( "../wiki-prompts/project_wiki" , ( ) => ( {
6363 projectWikiVersion : "v1.0.1" ,
64- PROJECT_WIKI_TEMPLATE : " ---\ndescription: \ "项目深度分析与知识文档生成\ "\nversion: v1.0.1\n---\n# 测试模板" ,
64+ PROJECT_WIKI_TEMPLATE : ' ---\ndescription: "项目深度分析与知识文档生成"\nversion: v1.0.1\n---\n# 测试模板' ,
6565} ) )
6666
6767vi . mock ( "../wiki-prompts/subtasks/01_Project_Overview_Analysis" , ( ) => ( {
@@ -110,7 +110,7 @@ vi.mock("../wiki-prompts/subtasks/11_Project_Rules_Generation", () => ({
110110
111111// 导入模块
112112import * as fs from "fs"
113- import { ensureProjectWikiCommandExists , setLogger } from "../projectWikiHelpers"
113+ import { ensureProjectWikiSubtasksExists , setLogger } from "../projectWikiHelpers"
114114
115115describe ( "projectWikiHelpers" , ( ) => {
116116 beforeEach ( ( ) => {
@@ -119,55 +119,47 @@ describe("projectWikiHelpers", () => {
119119 setLogger ( mockLogger )
120120 } )
121121
122- describe ( "ensureProjectWikiCommandExists" , ( ) => {
123- it ( "应该在文件不存在时创建项目wiki命令" , async ( ) => {
124- // Mock fs.access 抛出错误表示文件不存在
125- vi . mocked ( fs . promises . access ) . mockRejectedValue ( new Error ( "File not found" ) )
122+ describe ( "ensureProjectWikiSubtasksExists" , ( ) => {
123+ it ( "应该在子任务目录不存在时创建子任务文件" , async ( ) => {
124+ // Mock fs.stat 抛出错误表示目录不存在
126125 vi . mocked ( fs . promises . stat ) . mockRejectedValue ( new Error ( "Directory not found" ) )
127126 vi . mocked ( fs . promises . mkdir ) . mockResolvedValue ( undefined )
128127 vi . mocked ( fs . promises . writeFile ) . mockResolvedValue ( undefined )
129128 vi . mocked ( fs . promises . rm ) . mockResolvedValue ( undefined )
130129
131- await ensureProjectWikiCommandExists ( )
130+ await ensureProjectWikiSubtasksExists ( )
132131
133- expect ( fs . promises . mkdir ) . toHaveBeenCalledWith ( "/home/user/.roo/commands" , { recursive : true } )
132+ expect ( fs . promises . mkdir ) . toHaveBeenCalledWith ( "/home/user/.roo/commands/project-wiki-tasks/" , {
133+ recursive : true ,
134+ } )
134135 expect ( fs . promises . writeFile ) . toHaveBeenCalled ( )
135- expect ( mockLogger . info ) . toHaveBeenCalledWith ( "[projectWikiHelpers] Starting ensureProjectWikiCommandExists..." )
136+ expect ( mockLogger . info ) . toHaveBeenCalledWith (
137+ "[projectWikiHelpers] Starting ensureProjectWikiSubtasksExists..." ,
138+ )
136139 } )
137140
138- it ( "应该在版本不匹配时重新创建文件" , async ( ) => {
139- // Mock 文件存在但版本不匹配
140- vi . mocked ( fs . promises . access ) . mockResolvedValue ( undefined )
141- vi . mocked ( fs . promises . readFile ) . mockResolvedValue ( `---
142- description: "项目深度分析与知识文档生成"
143- version: "v1.0.0"
144- ---
145- # 旧版本模板` )
141+ it ( "应该在子任务文件不完整时重新创建" , async ( ) => {
142+ // Mock 子任务目录存在但文件不完整
146143 vi . mocked ( fs . promises . stat ) . mockResolvedValue ( {
147144 isDirectory : ( ) => true ,
148145 } as any )
149146 vi . mocked ( fs . promises . readdir ) . mockResolvedValue ( [
150147 "01_Project_Overview_Analysis.md" ,
151148 "02_Overall_Architecture_Analysis.md" ,
149+ // 缺少其他文件
152150 ] as any )
153151 vi . mocked ( fs . promises . mkdir ) . mockResolvedValue ( undefined )
154152 vi . mocked ( fs . promises . writeFile ) . mockResolvedValue ( undefined )
155153 vi . mocked ( fs . promises . rm ) . mockResolvedValue ( undefined )
156154
157- await ensureProjectWikiCommandExists ( )
155+ await ensureProjectWikiSubtasksExists ( )
158156
159157 expect ( fs . promises . rm ) . toHaveBeenCalled ( )
160158 expect ( fs . promises . writeFile ) . toHaveBeenCalled ( )
161159 } )
162160
163- it ( "应该正确处理文件存在的情况" , async ( ) => {
164- // Mock 文件存在的情况
165- vi . mocked ( fs . promises . access ) . mockResolvedValue ( undefined )
166- vi . mocked ( fs . promises . readFile ) . mockResolvedValue ( `---
167- description: "项目深度分析与知识文档生成"
168- version: "v1.0.1"
169- ---
170- # 当前版本模板` )
161+ it ( "应该正确处理子任务文件完整的情况" , async ( ) => {
162+ // Mock 子任务文件完整的情况
171163 vi . mocked ( fs . promises . stat ) . mockResolvedValue ( {
172164 isDirectory : ( ) => true ,
173165 } as any )
@@ -188,112 +180,70 @@ version: "v1.0.1"
188180 vi . mocked ( fs . promises . writeFile ) . mockResolvedValue ( undefined )
189181 vi . mocked ( fs . promises . rm ) . mockResolvedValue ( undefined )
190182
191- await ensureProjectWikiCommandExists ( )
183+ await ensureProjectWikiSubtasksExists ( )
192184
193185 // 验证启动日志被调用
194- expect ( mockLogger . info ) . toHaveBeenCalledWith ( "[projectWikiHelpers] Starting ensureProjectWikiCommandExists..." )
195- // 验证设置命令的日志被调用
196- expect ( mockLogger . info ) . toHaveBeenCalledWith ( "[projectWikiHelpers] Setting up project-wiki command..." )
197- // 验证写文件操作被调用
198- expect ( fs . promises . writeFile ) . toHaveBeenCalled ( )
199- } )
200-
201- it ( "应该在子任务目录缺少文件时重新创建" , async ( ) => {
202- // Mock 主文件存在但子任务目录缺少文件
203- vi . mocked ( fs . promises . access ) . mockResolvedValue ( undefined )
204- vi . mocked ( fs . promises . readFile ) . mockResolvedValue ( `---
205- description: "项目深度分析与知识文档生成"
206- version: "v1.0.1"
207- ---
208- # 当前版本模板` )
209- vi . mocked ( fs . promises . stat ) . mockResolvedValue ( {
210- isDirectory : ( ) => true ,
211- } as any )
212- vi . mocked ( fs . promises . readdir ) . mockResolvedValue ( [
213- "01_Project_Overview_Analysis.md" ,
214- // 缺少其他文件
215- ] as any )
216- vi . mocked ( fs . promises . mkdir ) . mockResolvedValue ( undefined )
217- vi . mocked ( fs . promises . writeFile ) . mockResolvedValue ( undefined )
218- vi . mocked ( fs . promises . rm ) . mockResolvedValue ( undefined )
219-
220- await ensureProjectWikiCommandExists ( )
221-
222- expect ( fs . promises . rm ) . toHaveBeenCalled ( )
223- expect ( fs . promises . writeFile ) . toHaveBeenCalled ( )
186+ expect ( mockLogger . info ) . toHaveBeenCalledWith (
187+ "[projectWikiHelpers] Starting ensureProjectWikiSubtasksExists..." ,
188+ )
189+ // 验证子任务已存在的日志被调用
190+ expect ( mockLogger . info ) . toHaveBeenCalledWith ( "[projectWikiHelpers] project-wiki subtasks already exist" )
191+ // 验证不需要重新生成文件
192+ expect ( fs . promises . writeFile ) . not . toHaveBeenCalled ( )
224193 } )
225194
226195 it ( "应该处理错误情况" , async ( ) => {
227196 const consoleSpy = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
228-
197+
229198 // Mock mkdir 抛出错误
230199 vi . mocked ( fs . promises . mkdir ) . mockRejectedValue ( new Error ( "Permission denied" ) )
231200
232- await ensureProjectWikiCommandExists ( )
201+ await ensureProjectWikiSubtasksExists ( )
233202
234203 expect ( consoleSpy ) . toHaveBeenCalledWith (
235- "[commands] Failed to initialize project-wiki command :" ,
236- expect . stringContaining ( "Permission denied" )
204+ "[commands] Failed to initialize project-wiki subtasks :" ,
205+ expect . stringContaining ( "Permission denied" ) ,
237206 )
238207
239208 consoleSpy . mockRestore ( )
240209 } )
241210
242- it ( "应该正确处理前置matter解析错误" , async ( ) => {
243- // Mock 文件存在但前置matter格式错误
244- vi . mocked ( fs . promises . access ) . mockResolvedValue ( undefined )
245- vi . mocked ( fs . promises . readFile ) . mockResolvedValue ( `# 没有前置matter的文件` )
246- vi . mocked ( fs . promises . stat ) . mockResolvedValue ( {
247- isDirectory : ( ) => true ,
248- } as any )
249- vi . mocked ( fs . promises . readdir ) . mockResolvedValue ( [ ] as any )
250- vi . mocked ( fs . promises . mkdir ) . mockResolvedValue ( undefined )
251- vi . mocked ( fs . promises . writeFile ) . mockResolvedValue ( undefined )
252- vi . mocked ( fs . promises . rm ) . mockResolvedValue ( undefined )
253-
254- await ensureProjectWikiCommandExists ( )
255-
256- // 验证启动日志被调用
257- expect ( mockLogger . info ) . toHaveBeenCalledWith ( "[projectWikiHelpers] Starting ensureProjectWikiCommandExists..." )
258- // 验证设置命令的日志被调用
259- expect ( mockLogger . info ) . toHaveBeenCalledWith ( "[projectWikiHelpers] Setting up project-wiki command..." )
260- // 验证写文件操作被调用
261- expect ( fs . promises . writeFile ) . toHaveBeenCalled ( )
262- } )
263-
264211 it ( "应该正确处理部分子任务文件生成失败的情况" , async ( ) => {
265- // Mock 文件不存在,需要创建
266- vi . mocked ( fs . promises . access ) . mockRejectedValue ( new Error ( "File not found" ) )
212+ // Mock 子任务目录不存在,需要创建
267213 vi . mocked ( fs . promises . stat ) . mockRejectedValue ( new Error ( "Directory not found" ) )
268214 vi . mocked ( fs . promises . mkdir ) . mockResolvedValue ( undefined )
269215 vi . mocked ( fs . promises . writeFile )
270- . mockResolvedValueOnce ( undefined ) // 主文件成功
271216 . mockRejectedValueOnce ( new Error ( "Write failed" ) ) // 第一个子任务文件失败
272217 . mockResolvedValue ( undefined ) // 其他文件成功
273218 vi . mocked ( fs . promises . rm ) . mockResolvedValue ( undefined )
274219
275- await ensureProjectWikiCommandExists ( )
220+ await ensureProjectWikiSubtasksExists ( )
276221
277222 // 验证启动和设置日志被调用
278- expect ( mockLogger . info ) . toHaveBeenCalledWith ( "[projectWikiHelpers] Starting ensureProjectWikiCommandExists..." )
279- expect ( mockLogger . info ) . toHaveBeenCalledWith ( "[projectWikiHelpers] Setting up project-wiki command..." )
223+ expect ( mockLogger . info ) . toHaveBeenCalledWith (
224+ "[projectWikiHelpers] Starting ensureProjectWikiSubtasksExists..." ,
225+ )
226+ expect ( mockLogger . info ) . toHaveBeenCalledWith ( "[projectWikiHelpers] Setting up project-wiki subtasks..." )
280227 // 验证警告日志被调用(部分文件生成失败)
281228 expect ( mockLogger . warn ) . toHaveBeenCalledWith ( expect . stringContaining ( "Failed to generate" ) )
282229 } )
283230
284231 it ( "应该正确处理Promise.allSettled的混合结果" , async ( ) => {
285232 // Mock 混合的成功和失败情况
286- vi . mocked ( fs . promises . access ) . mockRejectedValue ( new Error ( "File not found" ) )
287233 vi . mocked ( fs . promises . stat ) . mockRejectedValue ( new Error ( "Directory not found" ) )
288234 vi . mocked ( fs . promises . mkdir ) . mockResolvedValue ( undefined )
289235 vi . mocked ( fs . promises . writeFile ) . mockResolvedValue ( undefined )
290236 vi . mocked ( fs . promises . rm ) . mockResolvedValue ( undefined )
291237
292- await ensureProjectWikiCommandExists ( )
238+ await ensureProjectWikiSubtasksExists ( )
293239
294240 // 验证基本流程被执行
295- expect ( mockLogger . info ) . toHaveBeenCalledWith ( "[projectWikiHelpers] Starting ensureProjectWikiCommandExists..." )
296- expect ( fs . promises . mkdir ) . toHaveBeenCalledWith ( "/home/user/.roo/commands" , { recursive : true } )
241+ expect ( mockLogger . info ) . toHaveBeenCalledWith (
242+ "[projectWikiHelpers] Starting ensureProjectWikiSubtasksExists..." ,
243+ )
244+ expect ( fs . promises . mkdir ) . toHaveBeenCalledWith ( "/home/user/.roo/commands/project-wiki-tasks/" , {
245+ recursive : true ,
246+ } )
297247 } )
298248 } )
299249
@@ -311,4 +261,4 @@ version: "v1.0.1"
311261 expect ( ( ) => setLogger ( testLogger ) ) . not . toThrow ( )
312262 } )
313263 } )
314- } )
264+ } )
0 commit comments