Skip to content

Commit

Permalink
Fix: Exclude node_modules from workspace download (#6640)
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent committed Feb 14, 2025
1 parent 85e3a00 commit 0d3a041
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions frontend/__tests__/utils/download-files.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { downloadFiles } from "../../src/utils/download-files";
import * as OpenHandsAPI from "../../src/api/open-hands";

jest.mock("../../src/api/open-hands");

describe("downloadFiles", () => {
it("should not download node_modules", async () => {
const mockGetFiles = OpenHandsAPI.OpenHands.getFiles as jest.Mock;
mockGetFiles.mockResolvedValueOnce(["file1.txt", "node_modules/", "file2.txt"]);
mockGetFiles.mockResolvedValueOnce(["file_in_node_modules.txt"]); // Should not be called due to exclusion
mockGetFiles.mockResolvedValueOnce([]); // For file2.txt directory (not a directory in this test case)

// Mock showDirectoryPicker and file system API
const mockDirHandle = {
getFileHandle: jest.fn().mockResolvedValue({
createWritable: jest.fn().mockResolvedValue({
write: jest.fn().mockResolvedValue(undefined),
close: jest.fn().mockResolvedValue(undefined),
}),
}),
getDirectoryHandle: jest.fn().mockResolvedValue({}),
};
global.window.showDirectoryPicker = jest.fn().mockResolvedValue(mockDirHandle);

await downloadFiles("test-conversation-id");

expect(mockGetFiles).toHaveBeenCalledTimes(2); // Should only call getFiles for root and file2.txt, not node_modules
expect(mockGetFiles).toHaveBeenCalledWith("test-conversation-id", "");
expect(mockGetFiles).not.toHaveBeenCalledWith("test-conversation-id", "node_modules/"); // Verify node_modules is skipped
});
});
3 changes: 3 additions & 0 deletions frontend/src/utils/download-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ async function getAllFiles(

const fullPath = path + entry;
if (entry.endsWith("/")) {
if (entry === "node_modules/") {
return [];
}
const subEntries = await OpenHands.getFiles(conversationID, fullPath);
const subFilesPromises = subEntries.map((subEntry) =>
processEntry(subEntry),
Expand Down

0 comments on commit 0d3a041

Please sign in to comment.