chore: 保存 Agent 安全优化前基线

This commit is contained in:
Logan.Li committed 2026-09-02 23:31:38 +08:00
1 parent 08696896f9
commit ff016347cd
116 files changed
+3858 -2485

No files matched your search

+30 -7
View File
@@ -92,7 +92,9 @@ describe('terminal Agent CLI panel', () => {
})
fireEvent.click(screen.getByRole('button', { name: '发送' }))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'uptime'))
await waitFor(() =>
expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'uptime', { fromAgent: true })
)
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
expect(await screen.findByText('load average: 0.01')).toBeVisible()
expect(await screen.findByText('负载正常,任务完成。')).toBeVisible()
@@ -102,7 +104,12 @@ describe('terminal Agent CLI panel', () => {
it('asks for confirmation for high-risk commands in the default relaxed mode', async () => {
vi.mocked(mockDesktopApi.aiComplete)
.mockResolvedValueOnce({ success: true, text: '```bash\nsystemctl restart nginx\n```', model: 'test', redactedCount: 0 })
.mockResolvedValueOnce({
success: true,
text: '```bash\nsystemctl restart nginx\n```',
model: 'test',
redactedCount: 0,
})
.mockResolvedValueOnce({ success: true, text: 'FINAL: nginx 已重启。', model: 'test', redactedCount: 0 })
vi.mocked(mockDesktopApi.sshExec).mockResolvedValueOnce({ success: true, result: 'ok', exitCode: 0 })
@@ -129,8 +136,18 @@ describe('terminal Agent CLI panel', () => {
it('Always skips confirmation for the same command shape in the current panel session', async () => {
vi.mocked(mockDesktopApi.aiComplete)
.mockResolvedValueOnce({ success: true, text: '```bash\nrm /tmp/tmp.AAA111\n```', model: 'test', redactedCount: 0 })
.mockResolvedValueOnce({ success: true, text: '```bash\nrm /tmp/tmp.BBB222\n```', model: 'test', redactedCount: 0 })
.mockResolvedValueOnce({
success: true,
text: '```bash\nrm /tmp/tmp.AAA111\n```',
model: 'test',
redactedCount: 0,
})
.mockResolvedValueOnce({
success: true,
text: '```bash\nrm /tmp/tmp.BBB222\n```',
model: 'test',
redactedCount: 0,
})
.mockResolvedValueOnce({ success: true, text: 'FINAL: 清理完成。', model: 'test', redactedCount: 0 })
vi.mocked(mockDesktopApi.sshExec)
.mockResolvedValueOnce({ success: true, result: 'ok', exitCode: 0 })
@@ -151,8 +168,12 @@ describe('terminal Agent CLI panel', () => {
const dialog = await screen.findByRole('dialog')
fireEvent.click(within(dialog).getByRole('button', { name: 'Always' }))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'rm /tmp/tmp.AAA111'))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'rm /tmp/tmp.BBB222'))
await waitFor(() =>
expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'rm /tmp/tmp.AAA111', { fromAgent: true })
)
await waitFor(() =>
expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'rm /tmp/tmp.BBB222', { fromAgent: true })
)
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
expect(await screen.findByText('清理完成。')).toBeVisible()
})
@@ -356,7 +377,9 @@ describe('terminal Agent CLI panel', () => {
fireEvent.change(screen.getByPlaceholderText(PLACEHOLDER), { target: { value: '查看时间' } })
fireEvent.click(screen.getByRole('button', { name: '发送' }))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'date'))
await waitFor(() =>
expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'date', { fromAgent: true })
)
fireEvent.click(screen.getByRole('button', { name: '停止' }))
expect(mockDesktopApi.sshExecCancel).toHaveBeenCalledWith('ssh-active-1')