chore: 保存工作副本——客户端授权新契约(双端点/验签/令牌/周检)与桌面会话可靠性改进
This commit is contained in:
1 parent
f71eef0eba
commit
ae6093c9b3
163 files changed
+4911
-2494
No files matched your search
@@ -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('/')
|
||||
|
||||
Reference in new issue
Block a user