-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Prevent completion with open todos #5716
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2df9a7a
Prevent completion with open todos
mrubens 790428a
Merge remote-tracking branch 'origin/main' into prevent_completion_wi…
roomote 2dc3b1a
feat: add VSCode setting to control todo completion prevention
roomote f778acf
PR fixes
mrubens 22e9e10
Bump types
mrubens 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,228 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest" | ||
| import { TodoItem } from "@roo-code/types" | ||
| import { AttemptCompletionToolUse } from "../../../shared/tools" | ||
|
|
||
| // Mock the formatResponse module before importing the tool | ||
| vi.mock("../../prompts/responses", () => ({ | ||
| formatResponse: { | ||
| toolError: vi.fn((msg: string) => `Error: ${msg}`), | ||
| }, | ||
| })) | ||
|
|
||
| import { attemptCompletionTool } from "../attemptCompletionTool" | ||
| import { Task } from "../../task/Task" | ||
|
|
||
| describe("attemptCompletionTool", () => { | ||
| let mockTask: Partial<Task> | ||
| let mockPushToolResult: ReturnType<typeof vi.fn> | ||
| let mockAskApproval: ReturnType<typeof vi.fn> | ||
| let mockHandleError: ReturnType<typeof vi.fn> | ||
| let mockRemoveClosingTag: ReturnType<typeof vi.fn> | ||
| let mockToolDescription: ReturnType<typeof vi.fn> | ||
| let mockAskFinishSubTaskApproval: ReturnType<typeof vi.fn> | ||
|
|
||
| beforeEach(() => { | ||
| mockPushToolResult = vi.fn() | ||
| mockAskApproval = vi.fn() | ||
| mockHandleError = vi.fn() | ||
| mockRemoveClosingTag = vi.fn() | ||
| mockToolDescription = vi.fn() | ||
| mockAskFinishSubTaskApproval = vi.fn() | ||
|
|
||
| mockTask = { | ||
| consecutiveMistakeCount: 0, | ||
| recordToolError: vi.fn(), | ||
| todoList: undefined, | ||
| } | ||
| }) | ||
|
|
||
| describe("todo list validation", () => { | ||
| it("should allow completion when there is no todo list", async () => { | ||
| const block: AttemptCompletionToolUse = { | ||
| type: "tool_use", | ||
| name: "attempt_completion", | ||
| params: { result: "Task completed successfully" }, | ||
| partial: false, | ||
| } | ||
|
|
||
| mockTask.todoList = undefined | ||
|
|
||
| // Mock the formatResponse to avoid import issues | ||
| vi.doMock("../../prompts/responses", () => ({ | ||
| formatResponse: { | ||
| toolError: vi.fn((msg) => `Error: ${msg}`), | ||
| }, | ||
| })) | ||
|
|
||
| await attemptCompletionTool( | ||
| mockTask as Task, | ||
| block, | ||
| mockAskApproval, | ||
| mockHandleError, | ||
| mockPushToolResult, | ||
| mockRemoveClosingTag, | ||
| mockToolDescription, | ||
| mockAskFinishSubTaskApproval, | ||
| ) | ||
|
|
||
| // Should not call pushToolResult with an error for empty todo list | ||
| expect(mockTask.consecutiveMistakeCount).toBe(0) | ||
| expect(mockTask.recordToolError).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("should allow completion when todo list is empty", async () => { | ||
| const block: AttemptCompletionToolUse = { | ||
| type: "tool_use", | ||
| name: "attempt_completion", | ||
| params: { result: "Task completed successfully" }, | ||
| partial: false, | ||
| } | ||
|
|
||
| mockTask.todoList = [] | ||
|
|
||
| await attemptCompletionTool( | ||
| mockTask as Task, | ||
| block, | ||
| mockAskApproval, | ||
| mockHandleError, | ||
| mockPushToolResult, | ||
| mockRemoveClosingTag, | ||
| mockToolDescription, | ||
| mockAskFinishSubTaskApproval, | ||
| ) | ||
|
|
||
| expect(mockTask.consecutiveMistakeCount).toBe(0) | ||
| expect(mockTask.recordToolError).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("should allow completion when all todos are completed", async () => { | ||
| const block: AttemptCompletionToolUse = { | ||
| type: "tool_use", | ||
| name: "attempt_completion", | ||
| params: { result: "Task completed successfully" }, | ||
| partial: false, | ||
| } | ||
|
|
||
| const completedTodos: TodoItem[] = [ | ||
| { id: "1", content: "First task", status: "completed" }, | ||
| { id: "2", content: "Second task", status: "completed" }, | ||
| ] | ||
|
|
||
| mockTask.todoList = completedTodos | ||
|
|
||
| await attemptCompletionTool( | ||
| mockTask as Task, | ||
| block, | ||
| mockAskApproval, | ||
| mockHandleError, | ||
| mockPushToolResult, | ||
| mockRemoveClosingTag, | ||
| mockToolDescription, | ||
| mockAskFinishSubTaskApproval, | ||
| ) | ||
|
|
||
| expect(mockTask.consecutiveMistakeCount).toBe(0) | ||
| expect(mockTask.recordToolError).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("should prevent completion when there are pending todos", async () => { | ||
| const block: AttemptCompletionToolUse = { | ||
| type: "tool_use", | ||
| name: "attempt_completion", | ||
| params: { result: "Task completed successfully" }, | ||
| partial: false, | ||
| } | ||
|
|
||
| const todosWithPending: TodoItem[] = [ | ||
| { id: "1", content: "First task", status: "completed" }, | ||
| { id: "2", content: "Second task", status: "pending" }, | ||
| ] | ||
|
|
||
| mockTask.todoList = todosWithPending | ||
|
|
||
| await attemptCompletionTool( | ||
| mockTask as Task, | ||
| block, | ||
| mockAskApproval, | ||
| mockHandleError, | ||
| mockPushToolResult, | ||
| mockRemoveClosingTag, | ||
| mockToolDescription, | ||
| mockAskFinishSubTaskApproval, | ||
| ) | ||
|
|
||
| expect(mockTask.consecutiveMistakeCount).toBe(1) | ||
| expect(mockTask.recordToolError).toHaveBeenCalledWith("attempt_completion") | ||
| expect(mockPushToolResult).toHaveBeenCalledWith( | ||
| expect.stringContaining("Cannot complete task while there are incomplete todos"), | ||
| ) | ||
| }) | ||
|
|
||
| it("should prevent completion when there are in-progress todos", async () => { | ||
| const block: AttemptCompletionToolUse = { | ||
| type: "tool_use", | ||
| name: "attempt_completion", | ||
| params: { result: "Task completed successfully" }, | ||
| partial: false, | ||
| } | ||
|
|
||
| const todosWithInProgress: TodoItem[] = [ | ||
| { id: "1", content: "First task", status: "completed" }, | ||
| { id: "2", content: "Second task", status: "in_progress" }, | ||
| ] | ||
|
|
||
| mockTask.todoList = todosWithInProgress | ||
|
|
||
| await attemptCompletionTool( | ||
| mockTask as Task, | ||
| block, | ||
| mockAskApproval, | ||
| mockHandleError, | ||
| mockPushToolResult, | ||
| mockRemoveClosingTag, | ||
| mockToolDescription, | ||
| mockAskFinishSubTaskApproval, | ||
| ) | ||
|
|
||
| expect(mockTask.consecutiveMistakeCount).toBe(1) | ||
| expect(mockTask.recordToolError).toHaveBeenCalledWith("attempt_completion") | ||
| expect(mockPushToolResult).toHaveBeenCalledWith( | ||
| expect.stringContaining("Cannot complete task while there are incomplete todos"), | ||
| ) | ||
| }) | ||
|
|
||
| it("should prevent completion when there are mixed incomplete todos", async () => { | ||
| const block: AttemptCompletionToolUse = { | ||
| type: "tool_use", | ||
| name: "attempt_completion", | ||
| params: { result: "Task completed successfully" }, | ||
| partial: false, | ||
| } | ||
|
|
||
| const mixedTodos: TodoItem[] = [ | ||
| { id: "1", content: "First task", status: "completed" }, | ||
| { id: "2", content: "Second task", status: "pending" }, | ||
| { id: "3", content: "Third task", status: "in_progress" }, | ||
| ] | ||
|
|
||
| mockTask.todoList = mixedTodos | ||
|
|
||
| await attemptCompletionTool( | ||
| mockTask as Task, | ||
| block, | ||
| mockAskApproval, | ||
| mockHandleError, | ||
| mockPushToolResult, | ||
| mockRemoveClosingTag, | ||
| mockToolDescription, | ||
| mockAskFinishSubTaskApproval, | ||
| ) | ||
|
|
||
| expect(mockTask.consecutiveMistakeCount).toBe(1) | ||
| expect(mockTask.recordToolError).toHaveBeenCalledWith("attempt_completion") | ||
| expect(mockPushToolResult).toHaveBeenCalledWith( | ||
| expect.stringContaining("Cannot complete task while there are incomplete todos"), | ||
| ) | ||
| }) | ||
| }) | ||
| }) | ||
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
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.