feat: release OpsXShell 2.1.1

This commit is contained in:
Logan.Li committed 2026-07-31 01:37:01 +08:00
1 parent a3dba0c6ed
commit 494ef6b9d0
37 files changed
+2039 -370

No files matched your search

+139 -40
View File
@@ -4,7 +4,7 @@ import AiTerminalPanel from '../../src/components/ai/AiTerminalPanel'
import { useAiProviderStore } from '../../src/stores/aiProviderStore'
import { mockDesktopApi } from '../setup'
describe('terminal AI panel', () => {
describe('terminal Agent CLI panel', () => {
beforeEach(() => {
vi.clearAllMocks()
useAiProviderStore.setState({
@@ -27,65 +27,164 @@ describe('terminal AI panel', () => {
catalogProviders: [],
catalogUpdatedAt: null,
})
vi.mocked(mockDesktopApi.aiComplete).mockResolvedValue({
})
it('uses one task entry, Enter to run, Shift+Enter for a newline, and selected context only', async () => {
vi.mocked(mockDesktopApi.aiComplete).mockResolvedValueOnce({
success: true,
text: '建议:\n```bash\ndate\n```',
text: 'FINAL: 这是远端 Bash TMOUT 策略导致的自动退出。',
model: 'test',
redactedCount: 0,
})
})
it('prefers selection and fills one line without pressing enter', async () => {
const insert = vi.fn()
render(
<AiTerminalPanel
capture={() => ({ selection: 'selected error', viewport: 'whole screen' })}
insert={insert}
onClose={vi.fn()}
/>
)
fireEvent.change(screen.getByPlaceholderText('例如:分析这段报错,并给出最少的只读检查命令'), {
target: { value: '怎么排查' },
})
fireEvent.click(screen.getByRole('button', { name: '生成建议' }))
await waitFor(() => expect(mockDesktopApi.aiComplete).toHaveBeenCalled())
expect(vi.mocked(mockDesktopApi.aiComplete).mock.calls[0][0].context).toBe('selected error')
fireEvent.click(await screen.findByRole('button', { name: '填入终端' }))
expect(insert).toHaveBeenCalledWith('date')
})
it('executes one confirmed command through the current SSH connection and analyzes real output', async () => {
vi.mocked(mockDesktopApi.aiComplete)
.mockResolvedValueOnce({ success: true, text: '```bash\nuptime\n```', model: 'test', redactedCount: 0 })
.mockResolvedValueOnce({ success: true, text: '负载正常。', model: 'test', redactedCount: 0 })
vi.mocked(mockDesktopApi.sshExec).mockResolvedValueOnce({ success: true, result: 'load average: 0.01' })
render(
<AiTerminalPanel
capture={() => ({ selection: '', viewport: '' })}
insert={vi.fn()}
capture={() => ({ selection: 'timed out waiting for input: auto-logout', viewport: 'whole screen' })}
onClose={vi.fn()}
connectionId="ssh-active-1"
targetLabel="root@opsbase.cn"
/>
)
fireEvent.click(screen.getByRole('button', { name: '执行任务' }))
fireEvent.change(screen.getByPlaceholderText('例如:分析这段报错,并给出最少的只读检查命令'), {
expect(screen.queryByRole('button', { name: '解释' })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: '生成命令' })).not.toBeInTheDocument()
expect(screen.getByText('自然语言驱动 SSH 自主排障与部署')).toBeVisible()
const input = screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)')
fireEvent.change(input, { target: { value: '解释这个超时' } })
fireEvent.keyDown(input, { key: 'Enter', shiftKey: true })
expect(mockDesktopApi.aiComplete).not.toHaveBeenCalled()
fireEvent.keyDown(input, { key: 'Enter' })
await waitFor(() => expect(mockDesktopApi.aiComplete).toHaveBeenCalledTimes(1))
expect(vi.mocked(mockDesktopApi.aiComplete).mock.calls[0][0].context).toContain('auto-logout')
expect(vi.mocked(mockDesktopApi.aiComplete).mock.calls[0][0].context).not.toContain('whole screen')
expect(await screen.findByText('这是远端 Bash TMOUT 策略导致的自动退出。')).toBeVisible()
})
it('runs a bounded observe loop on the active SSH connection with confirmation before every command', async () => {
vi.mocked(mockDesktopApi.aiComplete)
.mockResolvedValueOnce({ success: true, text: '```bash\nuptime\n```', model: 'test', redactedCount: 0 })
.mockResolvedValueOnce({ success: true, text: 'FINAL: 负载正常,任务完成。', model: 'test', redactedCount: 0 })
vi.mocked(mockDesktopApi.sshExec).mockResolvedValueOnce({
success: true,
result: 'load average: 0.01',
exitCode: 0,
})
render(
<AiTerminalPanel
capture={() => ({ selection: '', viewport: '' })}
onClose={vi.fn()}
connectionId="ssh-active-1"
targetLabel="root@opsbase.cn"
/>
)
fireEvent.change(screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)'), {
target: { value: '检查服务器负载' },
})
fireEvent.click(screen.getByRole('button', { name: '准备执行方案' }))
fireEvent.click(await screen.findByRole('button', { name: '执行一次' }))
fireEvent.click(screen.getByRole('button', { name: '执行' }))
const dialog = await screen.findByRole('dialog')
expect(within(dialog).getByText(/root@opsbase.cn/)).toBeVisible()
expect(within(dialog).getByText(/uptime/)).toBeVisible()
expect(mockDesktopApi.sshExec).not.toHaveBeenCalled()
fireEvent.click(within(dialog).getByRole('button', { name: '执行一次' }))
fireEvent.click(within(dialog).getByRole('button', { name: '执行' }))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'uptime'))
expect(await screen.findByText('load average: 0.01')).toBeVisible()
expect(await screen.findByText('负载正常。')).toBeVisible()
expect(await screen.findByText('负载正常,任务完成。')).toBeVisible()
expect(mockDesktopApi.aiComplete).toHaveBeenCalledTimes(2)
expect(vi.mocked(mockDesktopApi.aiComplete).mock.calls[1][0].context).toContain('[exit_code=0]')
})
it('hard-denies critical destructive commands without offering confirmation', async () => {
vi.mocked(mockDesktopApi.aiComplete).mockResolvedValueOnce({
success: true,
text: '```bash\nrm -rf /\n```',
model: 'test',
redactedCount: 0,
})
render(
<AiTerminalPanel
capture={() => ({ selection: '', viewport: '' })}
onClose={vi.fn()}
connectionId="ssh-active-1"
targetLabel="root@opsbase.cn"
/>
)
fireEvent.change(screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)'), {
target: { value: '删除整台主机' },
})
fireEvent.click(screen.getByRole('button', { name: '执行' }))
expect(await screen.findByRole('alert')).toHaveTextContent('破坏性操作硬红线')
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
expect(mockDesktopApi.sshExec).not.toHaveBeenCalled()
})
it('retries one malformed model response and then requires the explicit FINAL protocol', async () => {
vi.mocked(mockDesktopApi.aiComplete)
.mockResolvedValueOnce({ success: true, text: '我准备先检查一下。', model: 'test', redactedCount: 0 })
.mockResolvedValueOnce({
success: true,
text: 'FINAL: 已根据已有上下文完成分析。',
model: 'test',
redactedCount: 0,
})
render(
<AiTerminalPanel
capture={() => ({ selection: '已有足够证据', viewport: '' })}
onClose={vi.fn()}
connectionId="ssh-active-1"
targetLabel="root@opsbase.cn"
/>
)
fireEvent.change(screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)'), {
target: { value: '给出结论' },
})
fireEvent.click(screen.getByRole('button', { name: '执行' }))
expect(await screen.findByText('已根据已有上下文完成分析。')).toBeVisible()
expect(mockDesktopApi.aiComplete).toHaveBeenCalledTimes(2)
expect(vi.mocked(mockDesktopApi.aiComplete).mock.calls[1][0].prompt).toContain('上一次回答没有遵循工具协议')
expect(mockDesktopApi.sshExec).not.toHaveBeenCalled()
})
it('asks again before a second command in the same task', async () => {
vi.mocked(mockDesktopApi.aiComplete)
.mockResolvedValueOnce({ success: true, text: '```bash\ndate\n```', model: 'test', redactedCount: 0 })
.mockResolvedValueOnce({ success: true, text: '```bash\nuname -a\n```', model: 'test', redactedCount: 0 })
.mockResolvedValueOnce({ success: true, text: 'FINAL: 两项检查已完成。', model: 'test', redactedCount: 0 })
vi.mocked(mockDesktopApi.sshExec)
.mockResolvedValueOnce({ success: true, result: 'Thu Jul 30', exitCode: 0 })
.mockResolvedValueOnce({ success: true, result: 'Linux host', exitCode: 0 })
render(
<AiTerminalPanel
capture={() => ({ selection: '', viewport: '' })}
onClose={vi.fn()}
connectionId="ssh-active-1"
targetLabel="root@opsbase.cn"
/>
)
fireEvent.change(screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)'), {
target: { value: '连续检查时间和系统' },
})
fireEvent.click(screen.getByRole('button', { name: '执行' }))
let dialog = await screen.findByRole('dialog')
fireEvent.click(within(dialog).getByRole('button', { name: '执行' }))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledTimes(1))
dialog = await screen.findByRole('dialog')
expect(within(dialog).getByText(/uname -a/)).toBeVisible()
expect(mockDesktopApi.sshExec).toHaveBeenCalledTimes(1)
fireEvent.click(within(dialog).getByRole('button', { name: '执行' }))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledTimes(2))
expect(await screen.findByText('两项检查已完成。')).toBeVisible()
})
})