feat(i18n): add multi-language support (ja/ko/vi/ru/zh-TW) with system auto-detection

- Extend AppLanguage to 7 locales: zh-CN, zh-TW, en, ja, ko, vi, ru
- Auto-detect system language via navigator.languages; fallback to English
- Add BCP47 locale mapping for date formatting and sorting
- Create 50 translation JSON files (5 languages × 10 namespaces, 1137 keys each)
- Update language selector with native language names
- Extend locale key parity test to cover all 7 languages (70 assertions)
- Add VNC/RDP desktop, serial terminal, AI agent, port forwarding, and SFTP features
- Add credential encryption, host metrics, session backup crypto, and zmodem bridge
- Update Rust backend: desktop services, host metrics, SSH/SFTP enhancements
This commit is contained in:
Logan.Li committed 2026-08-12 00:07:48 +08:00
1 parent fea6d8db04
commit b0d0e3a5f3
301 files changed
+28002 -2705

No files matched your search

+156 -22
View File
@@ -5,6 +5,8 @@ import { useAiProviderStore } from '../../src/stores/aiProviderStore'
import { useSettingsStore } from '../../src/stores/settingsStore'
import { mockDesktopApi } from '../setup'
const PLACEHOLDER = '任务或追问…(Enter 发送,Shift+Enter 换行)'
describe('terminal Agent CLI panel', () => {
beforeEach(() => {
vi.clearAllMocks()
@@ -29,11 +31,11 @@ describe('terminal Agent CLI panel', () => {
catalogUpdatedAt: null,
})
useSettingsStore.setState((state) => ({
settings: { ...state.settings, agentSafetyMode: 'balanced' },
settings: { ...state.settings, agentSafetyMode: 'relaxed' },
}))
})
it('uses one task entry, Enter to run, Shift+Enter for a newline, and selected context only', async () => {
it('keeps a sticky composer and uses Enter to send with selected context only', async () => {
vi.mocked(mockDesktopApi.aiComplete).mockResolvedValueOnce({
success: true,
text: 'FINAL: 这是远端 Bash TMOUT 策略导致的自动退出。',
@@ -50,10 +52,10 @@ describe('terminal Agent CLI panel', () => {
)
expect(screen.queryByRole('button', { name: '解释' })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: '生成命令' })).not.toBeInTheDocument()
expect(screen.getByText('自然语言驱动 SSH 自主排障与部署')).toBeVisible()
expect(screen.queryByText('自然语言驱动 SSH 自主排障与部署')).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: '发送' })).toBeVisible()
const input = screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)')
const input = screen.getByPlaceholderText(PLACEHOLDER)
fireEvent.change(input, { target: { value: '解释这个超时' } })
fireEvent.keyDown(input, { key: 'Enter', shiftKey: true })
expect(mockDesktopApi.aiComplete).not.toHaveBeenCalled()
@@ -63,9 +65,10 @@ describe('terminal Agent CLI panel', () => {
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()
expect(screen.getByPlaceholderText(PLACEHOLDER)).toHaveValue('')
})
it('runs safe diagnostic commands automatically in the default balanced mode', async () => {
it('runs safe diagnostic commands automatically in the default relaxed mode', 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 })
@@ -84,10 +87,10 @@ describe('terminal Agent CLI panel', () => {
/>
)
fireEvent.change(screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)'), {
fireEvent.change(screen.getByPlaceholderText(PLACEHOLDER), {
target: { value: '检查服务器负载' },
})
fireEvent.click(screen.getByRole('button', { name: '执行' }))
fireEvent.click(screen.getByRole('button', { name: '发送' }))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'uptime'))
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
@@ -97,7 +100,7 @@ describe('terminal Agent CLI panel', () => {
expect(vi.mocked(mockDesktopApi.aiComplete).mock.calls[1][0].context).toContain('[exit_code=0]')
})
it('asks for confirmation for high-risk commands in the default balanced mode', async () => {
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: 'FINAL: nginx 已重启。', model: 'test', redactedCount: 0 })
@@ -111,19 +114,49 @@ describe('terminal Agent CLI panel', () => {
targetLabel="root@opsbase.cn"
/>
)
fireEvent.change(screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)'), {
fireEvent.change(screen.getByPlaceholderText(PLACEHOLDER), {
target: { value: '重启 nginx' },
})
fireEvent.click(screen.getByRole('button', { name: '执行' }))
fireEvent.click(screen.getByRole('button', { name: '发送' }))
const dialog = await screen.findByRole('dialog')
expect(within(dialog).getByText(/均衡/)).toBeVisible()
expect(within(dialog).getByText(/宽松/)).toBeVisible()
expect(within(dialog).getByText(/systemctl restart nginx/)).toBeVisible()
expect(mockDesktopApi.sshExec).not.toHaveBeenCalled()
fireEvent.click(within(dialog).getByRole('button', { name: '确认风险并执行' }))
fireEvent.click(within(dialog).getByRole('button', { name: 'Once' }))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledTimes(1))
})
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: 'FINAL: 清理完成。', model: 'test', redactedCount: 0 })
vi.mocked(mockDesktopApi.sshExec)
.mockResolvedValueOnce({ success: true, result: 'ok', exitCode: 0 })
.mockResolvedValueOnce({ success: true, result: 'ok', exitCode: 0 })
render(
<AiTerminalPanel
capture={() => ({ selection: '', viewport: '' })}
onClose={vi.fn()}
connectionId="ssh-active-1"
targetLabel="root@opsbase.cn"
/>
)
fireEvent.change(screen.getByPlaceholderText(PLACEHOLDER), {
target: { value: '清理临时文件' },
})
fireEvent.click(screen.getByRole('button', { name: '发送' }))
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'))
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
expect(await screen.findByText('清理完成。')).toBeVisible()
})
it('lets strict mode require confirmation from medium risk upward', async () => {
vi.mocked(mockDesktopApi.aiComplete).mockResolvedValueOnce({
success: true,
@@ -140,10 +173,10 @@ describe('terminal Agent CLI panel', () => {
/>
)
fireEvent.click(screen.getByRole('radio', { name: '严格' }))
fireEvent.change(screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)'), {
fireEvent.change(screen.getByPlaceholderText(PLACEHOLDER), {
target: { value: '创建临时文件' },
})
fireEvent.click(screen.getByRole('button', { name: '执行' }))
fireEvent.click(screen.getByRole('button', { name: '发送' }))
const dialog = await screen.findByRole('dialog')
expect(within(dialog).getByText(/touch \/tmp\/opsxshell-agent-test/)).toBeVisible()
@@ -166,10 +199,10 @@ describe('terminal Agent CLI panel', () => {
targetLabel="root@opsbase.cn"
/>
)
fireEvent.change(screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)'), {
fireEvent.change(screen.getByPlaceholderText(PLACEHOLDER), {
target: { value: '删除整台主机' },
})
fireEvent.click(screen.getByRole('button', { name: '执行' }))
fireEvent.click(screen.getByRole('button', { name: '发送' }))
expect(await screen.findByRole('alert')).toHaveTextContent('破坏性操作硬红线')
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
@@ -194,10 +227,10 @@ describe('terminal Agent CLI panel', () => {
targetLabel="root@opsbase.cn"
/>
)
fireEvent.change(screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)'), {
fireEvent.change(screen.getByPlaceholderText(PLACEHOLDER), {
target: { value: '给出结论' },
})
fireEvent.click(screen.getByRole('button', { name: '执行' }))
fireEvent.click(screen.getByRole('button', { name: '发送' }))
expect(await screen.findByText('已根据已有上下文完成分析。')).toBeVisible()
expect(mockDesktopApi.aiComplete).toHaveBeenCalledTimes(2)
@@ -205,7 +238,7 @@ describe('terminal Agent CLI panel', () => {
expect(mockDesktopApi.sshExec).not.toHaveBeenCalled()
})
it('automatically executes multiple read-only commands in the same balanced task', async () => {
it('automatically executes multiple read-only commands in the same relaxed 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 })
@@ -222,13 +255,114 @@ describe('terminal Agent CLI panel', () => {
targetLabel="root@opsbase.cn"
/>
)
fireEvent.change(screen.getByPlaceholderText('输入任务描述,回车发送(Shift+回车换行)'), {
fireEvent.change(screen.getByPlaceholderText(PLACEHOLDER), {
target: { value: '连续检查时间和系统' },
})
fireEvent.click(screen.getByRole('button', { name: '执行' }))
fireEvent.click(screen.getByRole('button', { name: '发送' }))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledTimes(2))
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
expect(await screen.findByText('两项检查已完成。')).toBeVisible()
})
it('keeps follow-up turns in memory and can start a new topic', async () => {
vi.mocked(mockDesktopApi.aiComplete)
.mockResolvedValueOnce({ success: true, text: 'FINAL: 负载正常。', 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(PLACEHOLDER), { target: { value: '看负载' } })
fireEvent.click(screen.getByRole('button', { name: '发送' }))
expect(await screen.findByText('负载正常。')).toBeVisible()
fireEvent.change(screen.getByPlaceholderText(PLACEHOLDER), { 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(vi.mocked(mockDesktopApi.aiComplete).mock.calls[1][0].context).toContain('负载正常')
fireEvent.click(screen.getByRole('button', { name: '新话题' }))
expect(screen.queryByText('负载正常。')).not.toBeInTheDocument()
expect(screen.queryByText('内存也正常。')).not.toBeInTheDocument()
expect(screen.getByText(/可连续追问/)).toBeVisible()
})
it('renders markdown tables in FINAL conclusions', async () => {
vi.mocked(mockDesktopApi.aiComplete).mockResolvedValueOnce({
success: true,
text: [
'FINAL: 当前监听端口如下:',
'',
'| 端口 | 服务 |',
'|------|------|',
'| 22 | sshd |',
'| 80 | nginx |',
].join('\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(PLACEHOLDER), { target: { value: '列出端口' } })
fireEvent.click(screen.getByRole('button', { name: '发送' }))
expect(await screen.findByRole('table')).toBeVisible()
expect(screen.getByText('sshd')).toBeVisible()
expect(screen.getByText('nginx')).toBeVisible()
})
it('stops the agent and cancels the in-flight ssh_exec', async () => {
type ExecResult = { success: boolean; result?: string; exitCode?: number; error?: string }
const deferred: { resolve: (value: ExecResult) => void } = {
resolve: () => undefined,
}
vi.mocked(mockDesktopApi.aiComplete).mockResolvedValueOnce({
success: true,
text: '```bash\ndate\n```',
model: 'test',
redactedCount: 0,
})
vi.mocked(mockDesktopApi.sshExec).mockImplementationOnce(
() =>
new Promise<ExecResult>((resolve) => {
deferred.resolve = resolve
})
)
render(
<AiTerminalPanel
capture={() => ({ selection: '', viewport: '' })}
onClose={vi.fn()}
connectionId="ssh-active-1"
targetLabel="root@opsbase.cn"
/>
)
fireEvent.change(screen.getByPlaceholderText(PLACEHOLDER), { target: { value: '查看时间' } })
fireEvent.click(screen.getByRole('button', { name: '发送' }))
await waitFor(() => expect(mockDesktopApi.sshExec).toHaveBeenCalledWith('ssh-active-1', 'date'))
fireEvent.click(screen.getByRole('button', { name: '停止' }))
expect(mockDesktopApi.sshExecCancel).toHaveBeenCalledWith('ssh-active-1')
expect(await screen.findByText('已终止。正在执行的远端命令已请求中断。')).toBeVisible()
deferred.resolve({ success: false, error: '命令已终止' })
await waitFor(() => expect(screen.getByRole('button', { name: '发送' })).toBeVisible())
expect(mockDesktopApi.aiComplete).toHaveBeenCalledTimes(1)
})
})