mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Fix bug with auto-approving commands
This commit is contained in:
5
.changeset/fuzzy-horses-run.md
Normal file
5
.changeset/fuzzy-horses-run.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"roo-cline": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix bug with auto-approving commands
|
||||||
@@ -834,7 +834,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
|
|||||||
const autoApprove = async () => {
|
const autoApprove = async () => {
|
||||||
if (isAutoApproved(lastMessage)) {
|
if (isAutoApproved(lastMessage)) {
|
||||||
// Add delay for write operations
|
// Add delay for write operations
|
||||||
if (alwaysAllowWrite && isWriteToolAction(lastMessage)) {
|
if (lastMessage?.ask === "tool" && isWriteToolAction(lastMessage)) {
|
||||||
await new Promise(resolve => setTimeout(resolve, writeDelayMs))
|
await new Promise(resolve => setTimeout(resolve, writeDelayMs))
|
||||||
}
|
}
|
||||||
handlePrimaryButtonClick()
|
handlePrimaryButtonClick()
|
||||||
|
|||||||
@@ -247,54 +247,108 @@ describe('ChatView - Auto Approval Tests', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('auto-approves write tools when alwaysAllowWrite is enabled', async () => {
|
describe('Write Tool Auto-Approval Tests', () => {
|
||||||
render(
|
it('auto-approves write tools when alwaysAllowWrite is enabled and message is a tool request', async () => {
|
||||||
<ExtensionStateContextProvider>
|
render(
|
||||||
<ChatView
|
<ExtensionStateContextProvider>
|
||||||
isHidden={false}
|
<ChatView
|
||||||
showAnnouncement={false}
|
isHidden={false}
|
||||||
hideAnnouncement={() => {}}
|
showAnnouncement={false}
|
||||||
showHistoryView={() => {}}
|
hideAnnouncement={() => {}}
|
||||||
/>
|
showHistoryView={() => {}}
|
||||||
</ExtensionStateContextProvider>
|
/>
|
||||||
)
|
</ExtensionStateContextProvider>
|
||||||
|
)
|
||||||
|
|
||||||
// First hydrate state with initial task
|
// First hydrate state with initial task
|
||||||
mockPostMessage({
|
mockPostMessage({
|
||||||
alwaysAllowWrite: true,
|
alwaysAllowWrite: true,
|
||||||
clineMessages: [
|
clineMessages: [
|
||||||
{
|
{
|
||||||
type: 'say',
|
type: 'say',
|
||||||
say: 'task',
|
say: 'task',
|
||||||
ts: Date.now() - 2000,
|
ts: Date.now() - 2000,
|
||||||
text: 'Initial task'
|
text: 'Initial task'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
// Then send the write tool ask message
|
||||||
|
mockPostMessage({
|
||||||
|
alwaysAllowWrite: true,
|
||||||
|
clineMessages: [
|
||||||
|
{
|
||||||
|
type: 'say',
|
||||||
|
say: 'task',
|
||||||
|
ts: Date.now() - 2000,
|
||||||
|
text: 'Initial task'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'ask',
|
||||||
|
ask: 'tool',
|
||||||
|
ts: Date.now(),
|
||||||
|
text: JSON.stringify({ tool: 'editedExistingFile', path: 'test.txt' }),
|
||||||
|
partial: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
// Wait for the auto-approval message
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(vscode.postMessage).toHaveBeenCalledWith({
|
||||||
|
type: 'askResponse',
|
||||||
|
askResponse: 'yesButtonClicked'
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Then send the write tool ask message
|
it('does not auto-approve write operations when alwaysAllowWrite is enabled but message is not a tool request', () => {
|
||||||
mockPostMessage({
|
render(
|
||||||
alwaysAllowWrite: true,
|
<ExtensionStateContextProvider>
|
||||||
clineMessages: [
|
<ChatView
|
||||||
{
|
isHidden={false}
|
||||||
type: 'say',
|
showAnnouncement={false}
|
||||||
say: 'task',
|
hideAnnouncement={() => {}}
|
||||||
ts: Date.now() - 2000,
|
showHistoryView={() => {}}
|
||||||
text: 'Initial task'
|
/>
|
||||||
},
|
</ExtensionStateContextProvider>
|
||||||
{
|
)
|
||||||
type: 'ask',
|
|
||||||
ask: 'tool',
|
|
||||||
ts: Date.now(),
|
|
||||||
text: JSON.stringify({ tool: 'editedExistingFile', path: 'test.txt' }),
|
|
||||||
partial: false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
// Wait for the auto-approval message
|
// First hydrate state with initial task
|
||||||
await waitFor(() => {
|
mockPostMessage({
|
||||||
expect(vscode.postMessage).toHaveBeenCalledWith({
|
alwaysAllowWrite: true,
|
||||||
|
clineMessages: [
|
||||||
|
{
|
||||||
|
type: 'say',
|
||||||
|
say: 'task',
|
||||||
|
ts: Date.now() - 2000,
|
||||||
|
text: 'Initial task'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
// Then send a non-tool write operation message
|
||||||
|
mockPostMessage({
|
||||||
|
alwaysAllowWrite: true,
|
||||||
|
clineMessages: [
|
||||||
|
{
|
||||||
|
type: 'say',
|
||||||
|
say: 'task',
|
||||||
|
ts: Date.now() - 2000,
|
||||||
|
text: 'Initial task'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'ask',
|
||||||
|
ask: 'write_operation',
|
||||||
|
ts: Date.now(),
|
||||||
|
text: JSON.stringify({ path: 'test.txt', content: 'test content' }),
|
||||||
|
partial: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
// Verify no auto-approval message was sent
|
||||||
|
expect(vscode.postMessage).not.toHaveBeenCalledWith({
|
||||||
type: 'askResponse',
|
type: 'askResponse',
|
||||||
askResponse: 'yesButtonClicked'
|
askResponse: 'yesButtonClicked'
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user