Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Exclude node_modules from workspace download (#6640) #6721

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading