chore: 保存工作副本——客户端授权新契约(双端点/验签/令牌/周检)与桌面会话可靠性改进

This commit is contained in:
Logan.Li committed 2026-09-14 22:10:22 +08:00
1 parent f71eef0eba
commit ae6093c9b3
163 files changed
+4911 -2494

No files matched your search

+7 -9
View File
@@ -20,9 +20,7 @@ describe('patrol / desktop (rdp + vnc)', () => {
it('RDP connect dialog submits host/port/username/password', async () => {
const user = userEvent.setup()
const onConnect = vi.fn()
render(
<DesktopConnectDialog protocol="rdp" isOpen onClose={vi.fn()} onConnect={onConnect} />
)
render(<DesktopConnectDialog protocol="rdp" isOpen onClose={vi.fn()} onConnect={onConnect} />)
expect(screen.getByText('连接 RDP')).toBeVisible()
expect(screen.getByLabelText('端口')).toHaveValue(3389)
@@ -48,9 +46,7 @@ describe('patrol / desktop (rdp + vnc)', () => {
it('VNC connect dialog defaults to port 5900 and allows password-only auth', async () => {
const user = userEvent.setup()
const onConnect = vi.fn()
render(
<DesktopConnectDialog protocol="vnc" isOpen onClose={vi.fn()} onConnect={onConnect} />
)
render(<DesktopConnectDialog protocol="vnc" isOpen onClose={vi.fn()} onConnect={onConnect} />)
expect(screen.getByText('连接 VNC')).toBeVisible()
expect(screen.getByLabelText('端口')).toHaveValue(5900)
@@ -73,9 +69,7 @@ describe('patrol / desktop (rdp + vnc)', () => {
it('requires host before connecting', async () => {
const user = userEvent.setup()
const onConnect = vi.fn()
render(
<DesktopConnectDialog protocol="rdp" isOpen onClose={vi.fn()} onConnect={onConnect} />
)
render(<DesktopConnectDialog protocol="rdp" isOpen onClose={vi.fn()} onConnect={onConnect} />)
await user.click(screen.getByRole('button', { name: '连接' }))
expect(await screen.findByText(/请输入主机/)).toBeVisible()
expect(onConnect).not.toHaveBeenCalled()
@@ -103,6 +97,10 @@ describe('patrol / desktop (rdp + vnc)', () => {
await waitFor(() => {
expect(screen.getByLabelText('端口')).toHaveValue(3389)
})
expect(screen.getAllByLabelText('密码')).toHaveLength(1)
await user.click(screen.getByText('高级选项'))
expect(screen.queryByLabelText('跳板机(可选)')).not.toBeInTheDocument()
expect(screen.queryByLabelText('启动命令(可选)')).not.toBeInTheDocument()
await user.clear(screen.getByLabelText('主机'))
await user.type(screen.getByLabelText('主机'), 'win.lab.local')
await user.click(screen.getByRole('button', { name: '创建并保存' }))
+22 -20
View File
@@ -8,6 +8,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import SFTPView from '../../src/components/sftp/SFTPView'
import { useTabStore } from '../../src/stores/tabStore'
import { useToastStore } from '../../src/stores/toastStore'
import { useSettingsStore } from '../../src/stores/settingsStore'
import { mockDesktopApi } from '../setup'
import { resetPatrolStores, SSH_SESSION } from '../helpers/patrol'
@@ -109,10 +110,7 @@ describe('patrol / sftp', () => {
await user.click(screen.getByRole('button', { name: '确认' }))
await waitFor(() => {
expect(mockDesktopApi.sftpMkdir).toHaveBeenCalledWith(
'sftp-native',
expect.stringMatching(/\/tests$/)
)
expect(mockDesktopApi.sftpMkdir).toHaveBeenCalledWith('sftp-native', expect.stringMatching(/\/tests$/))
})
})
@@ -202,9 +200,7 @@ describe('patrol / sftp', () => {
const remotePanel = screen.getByLabelText('远程文件面板')
await user.click(within(remotePanel).getByRole('button', { name: '刷新当前面板' }))
expect(
within(remotePanel).getAllByText('权限不足,无法访问该文件或目录').length
).toBeGreaterThan(0)
expect(within(remotePanel).getAllByText('权限不足,无法访问该文件或目录').length).toBeGreaterThan(0)
await waitFor(() => {
expect(useToastStore.getState().toasts.some((item) => item.message.includes('权限不足'))).toBe(true)
})
@@ -261,9 +257,7 @@ describe('patrol / sftp', () => {
await user.click(await screen.findByText('编辑'))
await waitFor(() => {
expect(
useToastStore.getState().toasts.some((item) => item.message.includes('2MB'))
).toBe(true)
expect(useToastStore.getState().toasts.some((item) => item.message.includes('2MB'))).toBe(true)
})
})
@@ -298,9 +292,7 @@ describe('patrol / sftp', () => {
await user.click(within(remotePanel).getByRole('button', { name: '刷新当前面板' }))
// Channel failure also tears down the browse session → reconnect strip.
expect(
await screen.findByText('无法打开 SFTP 通道(服务器限制或会话繁忙),请重连后再试')
).toBeVisible()
expect(await screen.findByText('无法打开 SFTP 通道(服务器限制或会话繁忙),请重连后再试')).toBeVisible()
expect(screen.getByRole('button', { name: '重新连接' })).toBeVisible()
})
@@ -373,17 +365,27 @@ describe('patrol / sftp', () => {
expect(await within(remotePanel).findByText('root')).toBeVisible()
expect(onClosed).toBeTypeOf('function')
useSettingsStore.setState((state) => ({
settings: { ...state.settings, reconnectBaseDelayMs: 10 },
}))
let releaseConnect: ((value: { success: true; sftpId: string }) => void) | undefined
vi.mocked(mockDesktopApi.sftpConnect).mockImplementation(
() =>
new Promise((resolve) => {
releaseConnect = resolve
})
)
onClosed?.({}, 'conn-sftp', 'network reset')
expect(await screen.findByText(/连接已关闭|Connection closed/i)).toBeVisible()
expect(screen.getByText(/重连后将回到 \//)).toBeVisible()
vi.mocked(mockDesktopApi.sftpListDirectory).mockClear()
vi.mocked(mockDesktopApi.sftpConnect).mockResolvedValue({ success: true, sftpId: 'sftp-resumed' })
await user.click(screen.getByRole('button', { name: '重新连接' }))
expect(await screen.findByText(/正在重连并恢复 \//)).toBeVisible()
await waitFor(() => {
expect(mockDesktopApi.sftpConnect).toHaveBeenCalled()
expect(releaseConnect).toBeTypeOf('function')
})
vi.mocked(mockDesktopApi.sftpListDirectory).mockClear()
releaseConnect?.({ success: true, sftpId: 'sftp-resumed' })
await waitFor(() => {
const paths = vi.mocked(mockDesktopApi.sftpListDirectory).mock.calls.map((call) => call[1])
expect(paths[0]).toBe('/')