Skip to content

Commit 32dd79f

Browse files
committed
Error message and update to vitest
1 parent 8c84c3f commit 32dd79f

File tree

19 files changed

+78
-2
lines changed

19 files changed

+78
-2
lines changed

src/core/tools/__tests__/searchFilesTool.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ vi.mock("../../../utils/path", () => ({
2222

2323
vi.mock("../../ignore/RooIgnoreController")
2424

25+
vi.mock("../../../i18n", () => ({
26+
t: vi.fn((key: string, params?: any) => {
27+
if (key === "tools:searchFiles.workspaceBoundaryError") {
28+
return `Cannot search outside workspace. Path '${params?.path}' is outside the current workspace.`
29+
}
30+
return key
31+
}),
32+
}))
33+
2534
const mockedIsPathOutsideWorkspace = isPathOutsideWorkspace as MockedFunction<typeof isPathOutsideWorkspace>
2635
const mockedRegexSearchFiles = regexSearchFiles as MockedFunction<typeof regexSearchFiles>
2736

@@ -40,6 +49,7 @@ describe("searchFilesTool", () => {
4049
consecutiveMistakeCount: 0,
4150
recordToolError: vi.fn(),
4251
sayAndCreateMissingParamError: vi.fn().mockResolvedValue("Missing parameter error"),
52+
say: vi.fn().mockResolvedValue(undefined),
4353
rooIgnoreController: new RooIgnoreController("/workspace"),
4454
}
4555

@@ -105,6 +115,10 @@ describe("searchFilesTool", () => {
105115

106116
expect(mockedIsPathOutsideWorkspace).toHaveBeenCalledWith(path.resolve("/workspace", "../external"))
107117
expect(mockedRegexSearchFiles).not.toHaveBeenCalled()
118+
expect(mockTask.say).toHaveBeenCalledWith(
119+
"error",
120+
"Cannot search outside workspace. Path '../external' is outside the current workspace.",
121+
)
108122
expect(mockPushToolResult).toHaveBeenCalledWith(
109123
"Cannot search outside workspace. Path '../external' is outside the current workspace.",
110124
)
@@ -136,6 +150,10 @@ describe("searchFilesTool", () => {
136150

137151
expect(mockedIsPathOutsideWorkspace).toHaveBeenCalledWith(path.resolve("/workspace", "/etc/passwd"))
138152
expect(mockedRegexSearchFiles).not.toHaveBeenCalled()
153+
expect(mockTask.say).toHaveBeenCalledWith(
154+
"error",
155+
"Cannot search outside workspace. Path '/etc/passwd' is outside the current workspace.",
156+
)
139157
expect(mockPushToolResult).toHaveBeenCalledWith(
140158
"Cannot search outside workspace. Path '/etc/passwd' is outside the current workspace.",
141159
)
@@ -165,6 +183,10 @@ describe("searchFilesTool", () => {
165183

166184
expect(mockedIsPathOutsideWorkspace).toHaveBeenCalledWith(path.resolve("/workspace", "../../.."))
167185
expect(mockedRegexSearchFiles).not.toHaveBeenCalled()
186+
expect(mockTask.say).toHaveBeenCalledWith(
187+
"error",
188+
"Cannot search outside workspace. Path '../../..' is outside the current workspace.",
189+
)
168190
expect(mockPushToolResult).toHaveBeenCalledWith(
169191
"Cannot search outside workspace. Path '../../..' is outside the current workspace.",
170192
)

src/core/tools/searchFilesTool.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ClineSayTool } from "../../shared/ExtensionMessage"
66
import { getReadablePath } from "../../utils/path"
77
import { isPathOutsideWorkspace } from "../../utils/pathUtils"
88
import { regexSearchFiles } from "../../services/ripgrep"
9+
import { t } from "../../i18n"
910

1011
export async function searchFilesTool(
1112
cline: Task,
@@ -52,10 +53,12 @@ export async function searchFilesTool(
5253

5354
// Check if path is outside workspace
5455
if (isPathOutsideWorkspace(absolutePath)) {
55-
const errorMessage = `Cannot search outside workspace. Path '${relDirPath}' is outside the current workspace.`
56+
const userErrorMessage = t("tools:searchFiles.workspaceBoundaryError", { path: relDirPath })
57+
const llmErrorMessage = `Cannot search outside workspace. Path '${relDirPath}' is outside the current workspace.`
5658
cline.consecutiveMistakeCount++
5759
cline.recordToolError("search_files")
58-
pushToolResult(errorMessage)
60+
await cline.say("error", userErrorMessage)
61+
pushToolResult(llmErrorMessage)
5962
return
6063
}
6164

src/i18n/locales/ca/tools.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"toolRepetitionLimitReached": "Roo sembla estar atrapat en un bucle, intentant la mateixa acció ({{toolName}}) repetidament. Això podria indicar un problema amb la seva estratègia actual. Considera reformular la tasca, proporcionar instruccions més específiques o guiar-lo cap a un enfocament diferent.",
88
"codebaseSearch": {
99
"approval": "Cercant '{{query}}' a la base de codi..."
10+
},
11+
"searchFiles": {
12+
"workspaceBoundaryError": "No es pot cercar fora de l'espai de treball. El camí '{{path}}' està fora de l'espai de treball actual."
1013
}
1114
}

src/i18n/locales/de/tools.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"toolRepetitionLimitReached": "Roo scheint in einer Schleife festzustecken und versucht wiederholt dieselbe Aktion ({{toolName}}). Dies könnte auf ein Problem mit der aktuellen Strategie hindeuten. Überlege dir, die Aufgabe umzuformulieren, genauere Anweisungen zu geben oder Roo zu einem anderen Ansatz zu führen.",
88
"codebaseSearch": {
99
"approval": "Suche nach '{{query}}' im Codebase..."
10+
},
11+
"searchFiles": {
12+
"workspaceBoundaryError": "Kann nicht außerhalb des Arbeitsbereichs suchen. Pfad '{{path}}' liegt außerhalb des aktuellen Arbeitsbereichs."
1013
}
1114
}

src/i18n/locales/en/tools.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"toolRepetitionLimitReached": "Roo appears to be stuck in a loop, attempting the same action ({{toolName}}) repeatedly. This might indicate a problem with its current strategy. Consider rephrasing the task, providing more specific instructions, or guiding it towards a different approach.",
88
"codebaseSearch": {
99
"approval": "Searching for '{{query}}' in codebase..."
10+
},
11+
"searchFiles": {
12+
"workspaceBoundaryError": "Cannot search outside workspace. Path '{{path}}' is outside the current workspace."
1013
}
1114
}

src/i18n/locales/es/tools.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"toolRepetitionLimitReached": "Roo parece estar atrapado en un bucle, intentando la misma acción ({{toolName}}) repetidamente. Esto podría indicar un problema con su estrategia actual. Considera reformular la tarea, proporcionar instrucciones más específicas o guiarlo hacia un enfoque diferente.",
88
"codebaseSearch": {
99
"approval": "Buscando '{{query}}' en la base de código..."
10+
},
11+
"searchFiles": {
12+
"workspaceBoundaryError": "No se puede buscar fuera del espacio de trabajo. La ruta '{{path}}' está fuera del espacio de trabajo actual."
1013
}
1114
}

src/i18n/locales/fr/tools.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"toolRepetitionLimitReached": "Roo semble être bloqué dans une boucle, tentant la même action ({{toolName}}) de façon répétée. Cela pourrait indiquer un problème avec sa stratégie actuelle. Envisage de reformuler la tâche, de fournir des instructions plus spécifiques ou de le guider vers une approche différente.",
88
"codebaseSearch": {
99
"approval": "Recherche de '{{query}}' dans la base de code..."
10+
},
11+
"searchFiles": {
12+
"workspaceBoundaryError": "Impossible de rechercher en dehors de l'espace de travail. Le chemin '{{path}}' est en dehors de l'espace de travail actuel."
1013
}
1114
}

src/i18n/locales/hi/tools.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"toolRepetitionLimitReached": "Roo एक लूप में फंसा हुआ लगता है, बार-बार एक ही क्रिया ({{toolName}}) को दोहरा रहा है। यह उसकी वर्तमान रणनीति में किसी समस्या का संकेत हो सकता है। कार्य को पुनः परिभाषित करने, अधिक विशिष्ट निर्देश देने, या उसे एक अलग दृष्टिकोण की ओर मार्गदर्शित करने पर विचार करें।",
88
"codebaseSearch": {
99
"approval": "कोडबेस में '{{query}}' खोज रहा है..."
10+
},
11+
"searchFiles": {
12+
"workspaceBoundaryError": "वर्कस्पेस के बाहर खोज नहीं की जा सकती। पथ '{{path}}' वर्तमान वर्कस्पेस के बाहर है।"
1013
}
1114
}

src/i18n/locales/it/tools.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"toolRepetitionLimitReached": "Roo sembra essere bloccato in un ciclo, tentando ripetutamente la stessa azione ({{toolName}}). Questo potrebbe indicare un problema con la sua strategia attuale. Considera di riformulare l'attività, fornire istruzioni più specifiche o guidarlo verso un approccio diverso.",
88
"codebaseSearch": {
99
"approval": "Ricerca di '{{query}}' nella base di codice..."
10+
},
11+
"searchFiles": {
12+
"workspaceBoundaryError": "Impossibile cercare al di fuori dell'area di lavoro. Il percorso '{{path}}' è al di fuori dell'area di lavoro corrente."
1013
}
1114
}

src/i18n/locales/ja/tools.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"toolRepetitionLimitReached": "Rooが同じ操作({{toolName}})を繰り返し試みるループに陥っているようです。これは現在の方法に問題がある可能性を示しています。タスクの言い換え、より具体的な指示の提供、または別のアプローチへの誘導を検討してください。",
88
"codebaseSearch": {
99
"approval": "コードベースで '{{query}}' を検索中..."
10+
},
11+
"searchFiles": {
12+
"workspaceBoundaryError": "ワークスペース外では検索できません。パス '{{path}}' は現在のワークスペース外にあります。"
1013
}
1114
}

0 commit comments

Comments
 (0)