fix(sdk): treat zero search results as success (#11510)

This commit is contained in:
Saoud Rizwan
2026-06-12 16:35:00 -07:00
committed by GitHub
parent a279388451
commit 5260595472
2 changed files with 53 additions and 4 deletions
@@ -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({
@@ -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);