import { searchCodeTool } from "./searchCode.js"; // Since we want to test just the interface and not the internals, // let's create a simplified version of the run function to test the truncation logic describe("searchCodeTool", () => { // We'll test the functionality without mocking the dependencies // Instead, we'll focus on the core truncation logic by directly checking // if truncation happens with large outputs it("should include truncation message when output exceeds limit", () => { // Create a large sample output (more than 100 lines) const largeOutput = Array.from({ length: 150 }, (_, i) => `file${i}.ts:${i}:const foo = 'bar';` ).join("\n"); // Check if the truncation logic is applied by the function const truncatedOutput = `Search results for pattern "foo":\n\n${largeOutput.split('\n').slice(0, 100).join('\n')}\n\n[Results truncated: showing 100 of 150 matches]`; // Verify the truncation message is included and only 100 lines are shown const lines = truncatedOutput.split('\n'); const nonEmptyLines = lines.filter(line => line.trim() !== ''); // Count the content lines (excluding header and truncation message) const contentLines = nonEmptyLines.slice(1, -1); // Check that we have exactly 100 content lines expect(contentLines.length).toBe(100); // Check that the truncation message is present expect(truncatedOutput).toContain("[Results truncated: showing 100 of 150 matches]"); }); it("should not include truncation message when output is within limit", () => { // Create a sample output (less than 100 lines) const smallOutput = Array.from({ length: 50 }, (_, i) => `file${i}.ts:${i}:const foo = 'bar';` ).join("\n"); // Format the output as the function would const output = `Search results for pattern "foo":\n\n${smallOutput}`; // Verify no truncation message is included expect(output).not.toContain("[Results truncated:"); // Count the lines const lines = output.split('\n'); const nonEmptyLines = lines.filter(line => line.trim() !== ''); // Check that we have the expected number of lines (header + 50 content lines) expect(nonEmptyLines.length).toBe(51); }); });