-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathprocessUserContentMentions.spec.ts
More file actions
366 lines (327 loc) · 9.06 KB
/
processUserContentMentions.spec.ts
File metadata and controls
366 lines (327 loc) · 9.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
// npx vitest core/mentions/__tests__/processUserContentMentions.spec.ts
import { processUserContentMentions } from "../processUserContentMentions"
import { parseMentions } from "../index"
import { UrlContentFetcher } from "../../../services/browser/UrlContentFetcher"
import { FileContextTracker } from "../../context-tracking/FileContextTracker"
// Mock the parseMentions function
vi.mock("../index", () => ({
parseMentions: vi.fn(),
}))
describe("processUserContentMentions", () => {
let mockUrlContentFetcher: UrlContentFetcher
let mockFileContextTracker: FileContextTracker
let mockRooIgnoreController: any
beforeEach(() => {
vi.clearAllMocks()
mockUrlContentFetcher = {} as UrlContentFetcher
mockFileContextTracker = {} as FileContextTracker
mockRooIgnoreController = {}
// Default mock implementation - returns ParseMentionsResult object
vi.mocked(parseMentions).mockImplementation(async (text) => ({
text: `parsed: ${text}`,
mode: undefined,
}))
})
describe("maxReadFileLine parameter", () => {
it("should pass maxReadFileLine to parseMentions when provided", async () => {
const userContent = [
{
type: "text" as const,
text: "<task>Read file with limit</task>",
},
]
await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
rooIgnoreController: mockRooIgnoreController,
maxReadFileLine: 100,
})
expect(parseMentions).toHaveBeenCalledWith(
"<task>Read file with limit</task>",
"/test",
mockUrlContentFetcher,
mockFileContextTracker,
mockRooIgnoreController,
false,
true, // includeDiagnosticMessages
50, // maxDiagnosticMessages
100,
undefined, // maxFileTokenBudget
)
})
it("should pass undefined maxReadFileLine when not provided", async () => {
const userContent = [
{
type: "text" as const,
text: "<task>Read file without limit</task>",
},
]
await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
rooIgnoreController: mockRooIgnoreController,
})
expect(parseMentions).toHaveBeenCalledWith(
"<task>Read file without limit</task>",
"/test",
mockUrlContentFetcher,
mockFileContextTracker,
mockRooIgnoreController,
false,
true, // includeDiagnosticMessages
50, // maxDiagnosticMessages
undefined,
undefined, // maxFileTokenBudget
)
})
it("should handle UNLIMITED_LINES constant correctly", async () => {
const userContent = [
{
type: "text" as const,
text: "<task>Read unlimited lines</task>",
},
]
await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
rooIgnoreController: mockRooIgnoreController,
maxReadFileLine: -1,
})
expect(parseMentions).toHaveBeenCalledWith(
"<task>Read unlimited lines</task>",
"/test",
mockUrlContentFetcher,
mockFileContextTracker,
mockRooIgnoreController,
false,
true, // includeDiagnosticMessages
50, // maxDiagnosticMessages
-1,
undefined, // maxFileTokenBudget
)
})
})
describe("content processing", () => {
it("should process text blocks with <task> tags", async () => {
const userContent = [
{
type: "text" as const,
text: "<task>Do something</task>",
},
]
const result = await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
})
expect(parseMentions).toHaveBeenCalled()
expect(result.content[0]).toEqual({
type: "text",
text: "parsed: <task>Do something</task>",
})
expect(result.mode).toBeUndefined()
})
it("should process text blocks with <feedback> tags", async () => {
const userContent = [
{
type: "text" as const,
text: "<feedback>Fix this issue</feedback>",
},
]
const result = await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
})
expect(parseMentions).toHaveBeenCalled()
expect(result.content[0]).toEqual({
type: "text",
text: "parsed: <feedback>Fix this issue</feedback>",
})
expect(result.mode).toBeUndefined()
})
it("should not process text blocks without task or feedback tags", async () => {
const userContent = [
{
type: "text" as const,
text: "Regular text without special tags",
},
]
const result = await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
})
expect(parseMentions).not.toHaveBeenCalled()
expect(result.content[0]).toEqual(userContent[0])
expect(result.mode).toBeUndefined()
})
it("should process tool_result blocks with string content", async () => {
const userContent = [
{
type: "tool_result" as const,
tool_use_id: "123",
content: "<feedback>Tool feedback</feedback>",
},
]
const result = await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
})
expect(parseMentions).toHaveBeenCalled()
expect(result.content[0]).toEqual({
type: "tool_result",
tool_use_id: "123",
content: "parsed: <feedback>Tool feedback</feedback>",
})
expect(result.mode).toBeUndefined()
})
it("should process tool_result blocks with array content", async () => {
const userContent = [
{
type: "tool_result" as const,
tool_use_id: "123",
content: [
{
type: "text" as const,
text: "<task>Array task</task>",
},
{
type: "text" as const,
text: "Regular text",
},
],
},
]
const result = await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
})
expect(parseMentions).toHaveBeenCalledTimes(1)
expect(result.content[0]).toEqual({
type: "tool_result",
tool_use_id: "123",
content: [
{
type: "text",
text: "parsed: <task>Array task</task>",
},
{
type: "text",
text: "Regular text",
},
],
})
expect(result.mode).toBeUndefined()
})
it("should handle mixed content types", async () => {
const userContent = [
{
type: "text" as const,
text: "<task>First task</task>",
},
{
type: "image" as const,
source: {
type: "base64" as const,
media_type: "image/png" as const,
data: "base64data",
},
},
{
type: "tool_result" as const,
tool_use_id: "456",
content: "<feedback>Feedback</feedback>",
},
]
const result = await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
maxReadFileLine: 50,
})
expect(parseMentions).toHaveBeenCalledTimes(2)
expect(result.content).toHaveLength(3)
expect(result.content[0]).toEqual({
type: "text",
text: "parsed: <task>First task</task>",
})
expect(result.content[1]).toEqual(userContent[1]) // Image block unchanged
expect(result.content[2]).toEqual({
type: "tool_result",
tool_use_id: "456",
content: "parsed: <feedback>Feedback</feedback>",
})
expect(result.mode).toBeUndefined()
})
})
describe("showRooIgnoredFiles parameter", () => {
it("should default showRooIgnoredFiles to false", async () => {
const userContent = [
{
type: "text" as const,
text: "<task>Test default</task>",
},
]
await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
})
expect(parseMentions).toHaveBeenCalledWith(
"<task>Test default</task>",
"/test",
mockUrlContentFetcher,
mockFileContextTracker,
undefined,
false, // showRooIgnoredFiles should default to false
true, // includeDiagnosticMessages
50, // maxDiagnosticMessages
undefined,
undefined, // maxFileTokenBudget
)
})
it("should respect showRooIgnoredFiles when explicitly set to false", async () => {
const userContent = [
{
type: "text" as const,
text: "<task>Test explicit false</task>",
},
]
await processUserContentMentions({
userContent,
cwd: "/test",
urlContentFetcher: mockUrlContentFetcher,
fileContextTracker: mockFileContextTracker,
showRooIgnoredFiles: false,
})
expect(parseMentions).toHaveBeenCalledWith(
"<task>Test explicit false</task>",
"/test",
mockUrlContentFetcher,
mockFileContextTracker,
undefined,
false,
true, // includeDiagnosticMessages
50, // maxDiagnosticMessages
undefined,
undefined, // maxFileTokenBudget
)
})
})
})