Skip to content

Commit f0aefcb

Browse files
committed
fix(test): Correct read_file XML test mocks and expectations
- Adjusted mocks for range reads, rooignore, and path validation in read-file-xml.test.ts. - Updated expectations for range read behavior (ignoring maxReadFileLine). - Corrected mock interactions for rooignore and empty array path tests. - Fixed assertion for askApproval call order in empty array path test.
1 parent b1ac780 commit f0aefcb

File tree

3 files changed

+441
-384
lines changed

3 files changed

+441
-384
lines changed

src/core/__tests__/read-file-maxReadFileLine.test.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ describe("read_file tool with maxReadFileLine setting", () => {
6666
const fileContent = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5"
6767
const numberedFileContent = "1 | Line 1\n2 | Line 2\n3 | Line 3\n4 | Line 4\n5 | Line 5\n"
6868
const sourceCodeDef = "\n\n# file.txt\n1--5 | Content"
69-
const expectedFullFileXml = `<file><path>${testFilePath}</path>\n<content lines="1-5">\n${numberedFileContent}</content>\n</file>`
69+
// Define the new expected structure with wrappers
70+
const expectedFullFileXml = `<read_result>\n<file_content path="${testFilePath}">\n<content lines="1-5">\n${numberedFileContent}\n</content>\n</file_content>\n</read_result>`
7071

7172
// Mocked functions with correct types
7273
const mockedCountFileLines = countFileLines as jest.MockedFunction<typeof countFileLines>
@@ -112,6 +113,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
112113
mockProvider = {
113114
getState: jest.fn(),
114115
deref: jest.fn().mockReturnThis(),
116+
log: jest.fn(), // Add mock log function
115117
}
116118

117119
// Setup Cline instance with mock methods
@@ -201,7 +203,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
201203
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
202204
expect(mockedReadLines).not.toHaveBeenCalled()
203205
expect(mockedParseSourceCodeDefinitionsForFile).not.toHaveBeenCalled()
204-
expect(result).toBe(expectedFullFileXml)
206+
expect(result).toBe(expectedFullFileXml) // Updated expectedFullFileXml definition
205207
})
206208

207209
it("should ignore range parameters and read entire file when maxReadFileLine is -1", async () => {
@@ -221,7 +223,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
221223
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
222224
expect(mockedReadLines).not.toHaveBeenCalled()
223225
expect(mockedParseSourceCodeDefinitionsForFile).not.toHaveBeenCalled()
224-
expect(result).toBe(expectedFullFileXml)
226+
expect(result).toBe(expectedFullFileXml) // Updated expectedFullFileXml definition
225227
})
226228

227229
it("should not show line snippet in approval message when maxReadFileLine is -1", async () => {
@@ -265,14 +267,17 @@ describe("read_file tool with maxReadFileLine setting", () => {
265267
mockCline.rooIgnoreController,
266268
)
267269

268-
// Verify XML structure
269-
expect(result).toContain(`<file><path>${testFilePath}</path>`)
270+
// Verify XML structure within the new wrappers
271+
expect(result).toContain(`<read_result>`)
272+
expect(result).toContain(`<file_content path="${testFilePath}">`)
270273
expect(result).toContain("<notice>Showing only 0 of 5 total lines")
271274
expect(result).toContain("</notice>")
272275
expect(result).toContain("<list_code_definition_names>")
273276
expect(result).toContain(sourceCodeDef.trim())
274277
expect(result).toContain("</list_code_definition_names>")
275-
expect(result).not.toContain("<content") // No content when maxReadFileLine is 0
278+
expect(result).toContain(`</file_content>`)
279+
expect(result).toContain(`</read_result>`)
280+
expect(result).not.toContain("<content") // Still no content tag
276281
})
277282
})
278283

@@ -294,8 +299,9 @@ describe("read_file tool with maxReadFileLine setting", () => {
294299
mockCline.rooIgnoreController,
295300
)
296301

297-
// Verify XML structure
298-
expect(result).toContain(`<file><path>${testFilePath}</path>`)
302+
// Verify XML structure within the new wrappers
303+
expect(result).toContain(`<read_result>`)
304+
expect(result).toContain(`<file_content path="${testFilePath}">`)
299305
expect(result).toContain('<content lines="1-3">')
300306
expect(result).toContain("1 | Line 1")
301307
expect(result).toContain("2 | Line 2")
@@ -306,8 +312,12 @@ describe("read_file tool with maxReadFileLine setting", () => {
306312
expect(result).toContain("<list_code_definition_names>")
307313
expect(result).toContain(sourceCodeDef.trim())
308314
expect(result).toContain("</list_code_definition_names>")
315+
// Note: The duplicate list_code_definition_names check might be a test artifact or bug, keeping it for now
309316
expect(result).toContain("<list_code_definition_names>")
310317
expect(result).toContain(sourceCodeDef.trim())
318+
expect(result).toContain("</list_code_definition_names>")
319+
expect(result).toContain(`</file_content>`)
320+
expect(result).toContain(`</read_result>`)
311321
})
312322
})
313323

@@ -322,7 +332,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
322332

323333
// Verify
324334
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
325-
expect(result).toBe(expectedFullFileXml)
335+
expect(result).toBe(expectedFullFileXml) // Updated expectedFullFileXml definition
326336
})
327337

328338
it("should read with extractTextFromFile when file has few lines", async () => {
@@ -336,8 +346,8 @@ describe("read_file tool with maxReadFileLine setting", () => {
336346
// Verify
337347
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
338348
expect(mockedReadLines).not.toHaveBeenCalled()
339-
// Create a custom expected XML with lines="1-3" since totalLines is 3
340-
const expectedXml = `<file><path>${testFilePath}</path>\n<content lines="1-3">\n${numberedFileContent}</content>\n</file>`
349+
// Create a custom expected XML with lines="1-3" and wrappers
350+
const expectedXml = `<read_result>\n<file_content path="${testFilePath}">\n<content lines="1-3">\n${numberedFileContent}\n</content>\n</file_content>\n</read_result>`
341351
expect(result).toBe(expectedXml)
342352
})
343353
})
@@ -376,8 +386,8 @@ describe("read_file tool with maxReadFileLine setting", () => {
376386
// Verify
377387
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
378388
expect(mockedReadLines).not.toHaveBeenCalled()
379-
// Create a custom expected XML with lines="1-3" for binary files
380-
const expectedXml = `<file><path>${testFilePath}</path>\n<content lines="1-3">\n${numberedFileContent}</content>\n</file>`
389+
// Create a custom expected XML with lines="1-3" and wrappers for binary files
390+
const expectedXml = `<read_result>\n<file_content path="${testFilePath}">\n<content lines="1-3">\n${numberedFileContent}\n</content>\n</file_content>\n</read_result>`
381391
expect(result).toBe(expectedXml)
382392
})
383393
})
@@ -397,13 +407,16 @@ describe("read_file tool with maxReadFileLine setting", () => {
397407
expect(mockedReadLines).toHaveBeenCalledWith(absoluteFilePath, 3, 1) // end_line - 1, start_line - 1
398408
expect(addLineNumbersSpy).toHaveBeenCalledWith(expect.any(String), 2) // start with proper line numbers
399409

400-
// Verify XML structure with lines attribute
401-
expect(rangeResult).toContain(`<file><path>${testFilePath}</path>`)
410+
// Verify XML structure within the new wrappers
411+
expect(rangeResult).toContain(`<read_result>`)
412+
expect(rangeResult).toContain(`<file_content path="${testFilePath}">`)
402413
expect(rangeResult).toContain(`<content lines="2-4">`)
403414
expect(rangeResult).toContain("2 | Line 2")
404415
expect(rangeResult).toContain("3 | Line 3")
405416
expect(rangeResult).toContain("4 | Line 4")
406417
expect(rangeResult).toContain("</content>")
418+
expect(rangeResult).toContain(`</file_content>`)
419+
expect(rangeResult).toContain(`</read_result>`)
407420
})
408421
})
409422
})

0 commit comments

Comments
 (0)