Skip to content

Commit c7dd8e3

Browse files
committed
Fix tests
1 parent 25e55aa commit c7dd8e3

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

src/core/tools/__tests__/readFileTool.test.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ let mockInputContent = ""
3333

3434
jest.mock("../../../integrations/misc/extract-text", () => {
3535
const actual = jest.requireActual("../../../integrations/misc/extract-text")
36-
// Create a spy on the actual addLineNumbers function
36+
// Create a spy on the actual addLineNumbers function.
3737
const addLineNumbersSpy = jest.spyOn(actual, "addLineNumbers")
3838

3939
return {
4040
...actual,
41-
// Expose the spy so tests can access it
41+
// Expose the spy so tests can access it.
4242
__addLineNumbersSpy: addLineNumbersSpy,
4343
extractTextFromFile: jest.fn().mockImplementation((_filePath) => {
44-
// Use the actual addLineNumbers function
44+
// Use the actual addLineNumbers function.
4545
const content = mockInputContent
4646
return Promise.resolve(actual.addLineNumbers(content))
4747
}),
@@ -87,39 +87,33 @@ describe("read_file tool with maxReadFileLine setting", () => {
8787
const mockedIsBinaryFile = isBinaryFile as jest.MockedFunction<typeof isBinaryFile>
8888
const mockedPathResolve = path.resolve as jest.MockedFunction<typeof path.resolve>
8989

90-
// Mock instances
9190
const mockCline: any = {}
9291
let mockProvider: any
9392
let toolResult: ToolResponse | undefined
9493

9594
beforeEach(() => {
9695
jest.clearAllMocks()
9796

98-
// Setup path resolution
9997
mockedPathResolve.mockReturnValue(absoluteFilePath)
100-
101-
// Setup mocks for file operations
10298
mockedIsBinaryFile.mockResolvedValue(false)
10399

104-
// Set the default content for the mock
105100
mockInputContent = fileContent
106101

107-
// Setup the extractTextFromFile mock implementation with the current mockInputContent
102+
// Setup the extractTextFromFile mock implementation with the current
103+
// mockInputContent.
108104
mockedExtractTextFromFile.mockImplementation((_filePath) => {
109105
const actual = jest.requireActual("../../../integrations/misc/extract-text")
110106
return Promise.resolve(actual.addLineNumbers(mockInputContent))
111107
})
112108

113109
// No need to setup the extractTextFromFile mock implementation here
114-
// as it's already defined at the module level
110+
// as it's already defined at the module level.
115111

116-
// Setup mock provider
117112
mockProvider = {
118113
getState: jest.fn(),
119114
deref: jest.fn().mockReturnThis(),
120115
}
121116

122-
// Setup Cline instance with mock methods
123117
mockCline.cwd = "/"
124118
mockCline.task = "Test"
125119
mockCline.providerRef = mockProvider
@@ -129,12 +123,14 @@ describe("read_file tool with maxReadFileLine setting", () => {
129123
mockCline.say = jest.fn().mockResolvedValue(undefined)
130124
mockCline.ask = jest.fn().mockResolvedValue(true)
131125
mockCline.presentAssistantMessage = jest.fn()
132-
mockCline.fileContextTracker = jest.fn().mockReturnValue({
126+
127+
mockCline.fileContextTracker = {
133128
trackFileContext: jest.fn().mockResolvedValue(undefined),
134-
})
129+
}
130+
135131
mockCline.recordToolUsage = jest.fn().mockReturnValue(undefined)
136132
mockCline.recordToolError = jest.fn().mockReturnValue(undefined)
137-
// Reset tool result
133+
138134
toolResult = undefined
139135
})
140136

@@ -433,22 +429,16 @@ describe("read_file tool XML output structure", () => {
433429
beforeEach(() => {
434430
jest.clearAllMocks()
435431

436-
// Setup path resolution
437432
mockedPathResolve.mockReturnValue(absoluteFilePath)
438-
439-
// Setup mocks for file operations
440433
mockedIsBinaryFile.mockResolvedValue(false)
441434

442-
// Set the default content for the mock
443435
mockInputContent = fileContent
444436

445-
// Setup mock provider
446437
mockProvider = {
447438
getState: jest.fn().mockResolvedValue({ maxReadFileLine: 500 }),
448439
deref: jest.fn().mockReturnThis(),
449440
}
450441

451-
// Setup Cline instance with mock methods
452442
mockCline.cwd = "/"
453443
mockCline.task = "Test"
454444
mockCline.providerRef = mockProvider
@@ -460,14 +450,13 @@ describe("read_file tool XML output structure", () => {
460450
mockCline.presentAssistantMessage = jest.fn()
461451
mockCline.sayAndCreateMissingParamError = jest.fn().mockResolvedValue("Missing required parameter")
462452

463-
mockCline.fileContextTracker = jest.fn().mockReturnValue({
453+
mockCline.fileContextTracker = {
464454
trackFileContext: jest.fn().mockResolvedValue(undefined),
465-
})
455+
}
466456

467457
mockCline.recordToolUsage = jest.fn().mockReturnValue(undefined)
468458
mockCline.recordToolError = jest.fn().mockReturnValue(undefined)
469459

470-
// Reset tool result
471460
toolResult = undefined
472461
})
473462

0 commit comments

Comments
 (0)