This repository was archived by the owner on May 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open the worktreeinclude file after creating it #10891
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /** | ||
| * Tests for worktree handlers | ||
| */ | ||
|
|
||
| import * as vscode from "vscode" | ||
| import * as path from "path" | ||
| import { handleCreateWorktreeInclude } from "../handlers" | ||
| import { worktreeIncludeService } from "@roo-code/core" | ||
| import type { ClineProvider } from "../../ClineProvider" | ||
|
|
||
| // Mock vscode | ||
| vi.mock("vscode", () => ({ | ||
| workspace: { | ||
| openTextDocument: vi.fn(), | ||
| workspaceFolders: [{ uri: { fsPath: "/test/workspace" }, name: "workspace" }], | ||
| }, | ||
| window: { | ||
| showTextDocument: vi.fn(), | ||
| }, | ||
| Uri: { | ||
| file: vi.fn((path: string) => ({ fsPath: path })), | ||
| }, | ||
| })) | ||
|
|
||
| // Mock worktreeIncludeService | ||
| vi.mock("@roo-code/core", () => ({ | ||
| worktreeIncludeService: { | ||
| createWorktreeInclude: vi.fn(), | ||
| }, | ||
| worktreeService: { | ||
| checkGitRepo: vi.fn(), | ||
| }, | ||
| })) | ||
|
|
||
| describe("handleCreateWorktreeInclude", () => { | ||
| const mockProvider = { | ||
| cwd: "/test/workspace", | ||
| log: vi.fn(), | ||
| } as unknown as ClineProvider | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it("should create the file and open it in the editor", async () => { | ||
| const mockDocument = { uri: { fsPath: "/test/workspace/.worktreeinclude" } } | ||
| vi.mocked(worktreeIncludeService.createWorktreeInclude).mockResolvedValue(undefined) | ||
| vi.mocked(vscode.workspace.openTextDocument).mockResolvedValue(mockDocument as any) | ||
| vi.mocked(vscode.window.showTextDocument).mockResolvedValue({} as any) | ||
|
|
||
| const result = await handleCreateWorktreeInclude(mockProvider, "node_modules/\n.env") | ||
|
|
||
| expect(result.success).toBe(true) | ||
| expect(result.message).toBe(".worktreeinclude file created") | ||
| expect(worktreeIncludeService.createWorktreeInclude).toHaveBeenCalledWith( | ||
| "/test/workspace", | ||
| "node_modules/\n.env", | ||
| ) | ||
|
|
||
| // Verify the file was opened in the editor | ||
| const expectedPath = path.join("/test/workspace", ".worktreeinclude") | ||
| expect(vscode.workspace.openTextDocument).toHaveBeenCalledWith(expectedPath) | ||
| expect(vscode.window.showTextDocument).toHaveBeenCalledWith(mockDocument) | ||
| }) | ||
|
|
||
| it("should return error when creation fails", async () => { | ||
| vi.mocked(worktreeIncludeService.createWorktreeInclude).mockRejectedValue(new Error("Permission denied")) | ||
|
|
||
| const result = await handleCreateWorktreeInclude(mockProvider, "node_modules/") | ||
|
|
||
| expect(result.success).toBe(false) | ||
| expect(result.message).toBe("Failed to create .worktreeinclude: Permission denied") | ||
| expect(vscode.workspace.openTextDocument).not.toHaveBeenCalled() | ||
| expect(vscode.window.showTextDocument).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("should still return success even if opening the file fails", async () => { | ||
| vi.mocked(worktreeIncludeService.createWorktreeInclude).mockResolvedValue(undefined) | ||
| vi.mocked(vscode.workspace.openTextDocument).mockRejectedValue(new Error("Failed to open")) | ||
|
|
||
| const result = await handleCreateWorktreeInclude(mockProvider, "node_modules/") | ||
|
|
||
| // The function throws when opening fails, so it should return error | ||
| expect(result.success).toBe(false) | ||
| expect(result.message).toContain("Failed to create .worktreeinclude") | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.