diff --git a/sdk/packages/core/src/extensions/tools/definitions.test.ts b/sdk/packages/core/src/extensions/tools/definitions.test.ts index 8f69e9ec75..17616983f5 100644 --- a/sdk/packages/core/src/extensions/tools/definitions.test.ts +++ b/sdk/packages/core/src/extensions/tools/definitions.test.ts @@ -8,6 +8,7 @@ import { createBashTool, createDefaultTools, createReadFilesTool, + createSearchTool, createSkillsTool, createWindowsShellTool, } from "./definitions"; @@ -348,6 +349,57 @@ describe("default submit_and_exit tool", () => { }); }); +describe("default search_codebase tool", () => { + it("treats a valid search with zero matches as success", async () => { + const noResults = + "No results found for pattern: missingSymbol\nSearched 3 files."; + const execute = vi.fn(async () => noResults); + const tool = createSearchTool(execute); + + const result = await tool.execute( + { queries: ["missingSymbol"] }, + { + agentId: "agent-1", + conversationId: "conv-1", + iteration: 1, + }, + ); + + expect(result).toEqual([ + { + query: "missingSymbol", + result: noResults, + success: true, + }, + ]); + }); + + it("treats executor errors as failures", async () => { + const execute = vi.fn(async () => { + throw new Error("bad regex"); + }); + const tool = createSearchTool(execute); + + const result = await tool.execute( + { queries: ["("] }, + { + agentId: "agent-1", + conversationId: "conv-1", + iteration: 1, + }, + ); + + expect(result).toEqual([ + { + query: "(", + result: "", + error: "Search failed: bad regex", + success: false, + }, + ]); + }); +}); + describe("default apply_patch tool", () => { it("is included only when enabled with an applyPatch executor", () => { const toolsWithoutExecutor = createDefaultTools({ diff --git a/sdk/packages/core/src/extensions/tools/definitions.ts b/sdk/packages/core/src/extensions/tools/definitions.ts index 5e9f00fed1..30fa578d0a 100644 --- a/sdk/packages/core/src/extensions/tools/definitions.ts +++ b/sdk/packages/core/src/extensions/tools/definitions.ts @@ -247,13 +247,10 @@ export function createSearchTool( timeoutMs, `Search timed out after ${timeoutMs}ms`, ); - // Check if results contain matches - const hasResults = - results.length > 0 && !results.includes("No results found"); return { query, result: results, - success: hasResults, + success: true, }; } catch (error) { const msg = formatError(error);